]> sigrok.org Git - libsigrok.git/blobdiff - hardware/mic-985xx/api.c
serial-dmm: Use std_dev_clear().
[libsigrok.git] / hardware / mic-985xx / api.c
index 866acb41be000bc0f0f8a797745be199d55c1004..e2cc91714e4d493dda68087d0f53815a4bcd1bdc 100644 (file)
@@ -51,39 +51,14 @@ SR_PRIV const struct mic_dev_info mic_devs[] = {
 
 static int clear_instances(int idx)
 {
-       struct sr_dev_inst *sdi;
-       struct drv_context *drvc;
-       struct dev_context *devc;
-       struct sr_serial_dev_inst *serial;
-       GSList *l;
-       struct sr_dev_driver *di;
-
-       di = mic_devs[idx].di;
-
-       if (!(drvc = di->priv))
-               return SR_OK;
-
-       for (l = drvc->instances; l; l = l->next) {
-               if (!(sdi = l->data))
-                       continue;
-               if (!(devc = sdi->priv))
-                       continue;
-               serial = sdi->conn;
-               sr_serial_dev_inst_free(serial);
-               sr_dev_inst_free(sdi);
-       }
-
-       g_slist_free(drvc->instances);
-       drvc->instances = NULL;
-
-       return SR_OK;
+       return std_dev_clear(mic_devs[idx].di, NULL);
 }
 
 static int hw_init(struct sr_context *sr_ctx, int idx)
 {
        sr_dbg("Selected '%s' subdriver.", mic_devs[idx].di->name);
 
-       return std_hw_init(sr_ctx, mic_devs[idx].di, DRIVER_LOG_DOMAIN);
+       return std_hw_init(sr_ctx, mic_devs[idx].di, LOG_PREFIX);
 }
 
 static GSList *scan(const char *conn, const char *serialcomm, int idx)
@@ -159,7 +134,7 @@ static GSList *hw_scan(GSList *options, int idx)
                        conn = g_variant_get_string(src->data, NULL);
                        break;
                case SR_CONF_SERIALCOMM:
-                       serialcomm  = g_variant_get_string(src->data, NULL);
+                       serialcomm = g_variant_get_string(src->data, NULL);
                        break;
                }
        }
@@ -210,9 +185,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
 
 static int hw_cleanup(int idx)
 {
-       clear_instances(idx);
-
-       return SR_OK;
+       return clear_instances(idx);
 }
 
 static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
@@ -220,7 +193,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        struct dev_context *devc;
 
        if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR;
+               return SR_ERR_DEV_CLOSED;
 
        devc = sdi->priv;
 
@@ -268,15 +241,16 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
 
-       devc = sdi->priv;
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
 
+       devc = sdi->priv;
        devc->cb_data = cb_data;
-
        devc->num_samples = 0;
        devc->starttime = g_get_monotonic_time();
 
        /* 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);
 
        /* Poll every 100ms, or whenever some data comes in. */
        serial = sdi->conn;
@@ -289,7 +263,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
 static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
        return std_hw_dev_acquisition_stop_serial(sdi, cb_data, hw_dev_close,
-                                                 sdi->conn, DRIVER_LOG_DOMAIN);
+                                                 sdi->conn, LOG_PREFIX);
 }
 
 /* Driver-specific API function wrappers */