]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/rigol-ds/api.c
clear_helper(): Use a cast to shorten all implementations.
[libsigrok.git] / src / hardware / rigol-ds / api.c
index 296d86776fc9295d991d9c2493fa34cae98f9911..37a1984d631280a6e820f2b8ca4bd849c45f4700 100644 (file)
@@ -275,12 +275,10 @@ static const struct rigol_ds_model supported_models[] = {
 
 static struct sr_dev_driver rigol_ds_driver_info;
 
-static void clear_helper(void *priv)
+static void clear_helper(struct dev_context *devc)
 {
-       struct dev_context *devc;
        unsigned int i;
 
-       devc = priv;
        g_free(devc->data);
        g_free(devc->buffer);
        for (i = 0; i < ARRAY_SIZE(devc->coupling); i++)
@@ -288,12 +286,11 @@ static void clear_helper(void *priv)
        g_free(devc->trigger_source);
        g_free(devc->trigger_slope);
        g_free(devc->analog_groups);
-       g_free(devc);
 }
 
 static int dev_clear(const struct sr_dev_driver *di)
 {
-       return std_dev_clear(di, clear_helper);
+       return std_dev_clear_with_callback(di, (std_dev_clear_callback)clear_helper);
 }
 
 static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
@@ -445,8 +442,6 @@ static int dev_open(struct sr_dev_inst *sdi)
                return SR_ERR;
        }
 
-       sdi->status = SR_ST_ACTIVE;
-
        return SR_OK;
 }
 
@@ -455,22 +450,16 @@ static int dev_close(struct sr_dev_inst *sdi)
        struct sr_scpi_dev_inst *scpi;
        struct dev_context *devc;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        scpi = sdi->conn;
        devc = sdi->priv;
 
+       if (!scpi)
+               return SR_ERR_BUG;
+
        if (devc->model->series->protocol == PROTOCOL_V2)
                rigol_ds_config_set(sdi, ":KEY:LOCK DISABLE");
 
-       if (scpi) {
-               if (sr_scpi_close(scpi) < 0)
-                       return SR_ERR;
-               sdi->status = SR_ST_INACTIVE;
-       }
-
-       return SR_OK;
+       return sr_scpi_close(scpi);
 }
 
 static int analog_frame_size(const struct sr_dev_inst *sdi)
@@ -670,9 +659,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 
        devc = sdi->priv;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        /* If a channel group is specified, it must be a valid one. */
        if (cg && !g_slist_find(sdi->channel_groups, cg)) {
                sr_err("Invalid channel group specified.");
@@ -997,9 +983,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        gboolean some_digital;
        GSList *l;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        scpi = sdi->conn;
        devc = sdi->priv;