]> sigrok.org Git - libsigrok.git/blobdiff - hardware/zeroplus-logic-cube/api.c
zeroplus: Use std_dev_clear().
[libsigrok.git] / hardware / zeroplus-logic-cube / api.c
index b46d7dd5b640373499f21635c6d41f82bbfa7b95..13c649df652730fb823fe241367889977118c1dd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file is part of the sigrok project.
+ * This file is part of the libsigrok project.
  *
  * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
  *
@@ -240,31 +240,7 @@ SR_PRIV int zp_set_samplerate(struct dev_context *devc, uint64_t samplerate)
 
 static int clear_instances(void)
 {
-       GSList *l;
-       struct sr_dev_inst *sdi;
-       struct drv_context *drvc;
-       struct dev_context *devc;
-       struct sr_usb_dev_inst *usb;
-
-       drvc = di->priv;
-       for (l = drvc->instances; l; l = l->next) {
-               sdi = l->data;
-               if (!(devc = sdi->priv)) {
-                       /* Log error, but continue cleaning up the rest. */
-                       sr_err("%s: sdi->priv was NULL, continuing", __func__);
-                       continue;
-               }
-               usb = sdi->conn;
-               sr_usb_dev_inst_free(usb);
-               /* Properly close all devices... */
-               hw_dev_close(sdi);
-               /* ...and free all their memory. */
-               sr_dev_inst_free(sdi);
-       }
-       g_slist_free(drvc->instances);
-       drvc->instances = NULL;
-
-       return SR_OK;
+       return std_dev_clear(di, NULL);
 }
 
 static int hw_init(struct sr_context *sr_ctx)
@@ -290,8 +266,6 @@ static GSList *hw_scan(GSList *options)
 
        devices = NULL;
 
-       clear_instances();
-
        /* Find all ZEROPLUS analyzers and add them to device list. */
        devcnt = 0;
        libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); /* TODO: Errors. */
@@ -489,14 +463,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
 
 static int hw_cleanup(void)
 {
-       struct drv_context *drvc;
-
-       if (!(drvc = di->priv))
-               return SR_OK;
-
-       clear_instances();
-
-       return SR_OK;
+       return clear_instances();
 }
 
 static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
@@ -524,10 +491,8 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
 
-       if (!sdi) {
-               sr_err("%s: sdi was NULL", __func__);
-               return SR_ERR_ARG;
-       }
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
 
        if (!(devc = sdi->priv)) {
                sr_err("%s: sdi->priv was NULL", __func__);
@@ -600,6 +565,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        unsigned int packet_num, n;
        unsigned char *buf;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        if (!(devc = sdi->priv)) {
                sr_err("%s: sdi->priv was NULL", __func__);
                return SR_ERR_ARG;
@@ -629,7 +597,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
                analyzer_get_trigger_address(usb->devhdl));
 
        /* Send header packet to the session bus. */
-       std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
+       std_session_send_df_header(cb_data, LOG_PREFIX);
 
        if (!(buf = g_try_malloc(PACKET_SIZE))) {
                sr_err("Packet buffer malloc failed.");