]> sigrok.org Git - libsigrok.git/blobdiff - hardware/rigol-ds1xx2/api.c
s/clear_instances/dev_clear/.
[libsigrok.git] / hardware / rigol-ds1xx2 / api.c
index bffc6ab951d0958b05f8edd9936e2ba8ef49379c..e6e923ccfb7f41f2c78f448e9af1994c8f2a173d 100644 (file)
@@ -140,37 +140,21 @@ static const char *supported_models[] = {
 SR_PRIV struct sr_dev_driver rigol_ds1xx2_driver_info;
 static struct sr_dev_driver *di = &rigol_ds1xx2_driver_info;
 
-/* Properly close and free all devices. */
-static int clear_instances(void)
+static void clear_helper(void *priv)
 {
-       struct sr_dev_inst *sdi;
-       struct drv_context *drvc;
        struct dev_context *devc;
-       GSList *l;
-
-       if (!(drvc = di->priv))
-               return SR_OK;
-
-       for (l = drvc->instances; l; l = l->next) {
-               if (!(sdi = l->data))
-                       continue;
 
-               if (sdi->conn)
-                       sr_serial_dev_inst_free(sdi->conn);
+       devc = priv;
 
-               if ((devc = sdi->priv)) {
-                       g_free(devc->coupling[0]);
-                       g_free(devc->coupling[1]);
-                       g_free(devc->trigger_source);
-                       g_free(devc->trigger_slope);
-               }
-               sr_dev_inst_free(sdi);
-       }
-
-       g_slist_free(drvc->instances);
-       drvc->instances = NULL;
+       g_free(devc->coupling[0]);
+       g_free(devc->coupling[1]);
+       g_free(devc->trigger_source);
+       g_free(devc->trigger_slope);
+}
 
-       return SR_OK;
+static int dev_clear(void)
+{
+       return std_dev_clear(di, clear_helper);
 }
 
 static int set_cfg(const struct sr_dev_inst *sdi, const char *format, ...)
@@ -192,9 +176,9 @@ static int set_cfg(const struct sr_dev_inst *sdi, const char *format, ...)
        return SR_OK;
 }
 
-static int hw_init(struct sr_context *sr_ctx)
+static int init(struct sr_context *sr_ctx)
 {
-       return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN);
+       return std_init(sr_ctx, di, LOG_PREFIX);
 }
 
 static int probe_port(const char *port, GSList **devices)
@@ -210,7 +194,7 @@ static int probe_port(const char *port, GSList **devices)
        char buf[256];
        gchar **tokens, *channel_name;
 
-    *devices = NULL;
+       *devices = NULL;
        if (!(serial = sr_serial_dev_inst_new(port, NULL)))
                return SR_ERR_MALLOC;
 
@@ -246,7 +230,7 @@ static int probe_port(const char *port, GSList **devices)
                return SR_ERR_NA;
        }
 
-    matched = has_digital = FALSE;
+       matched = has_digital = FALSE;
        for (i = 0; i < ARRAY_SIZE(supported_models); i++) {
                if (!strcmp(model, supported_models[i])) {
                        matched = TRUE;
@@ -266,6 +250,7 @@ static int probe_port(const char *port, GSList **devices)
        if (!(sdi->conn = sr_serial_dev_inst_new(port, NULL)))
                return SR_ERR_MALLOC;
        sdi->driver = di;
+       sdi->inst_type = SR_INST_SERIAL;
 
        if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
                return SR_ERR_MALLOC;
@@ -297,7 +282,7 @@ static int probe_port(const char *port, GSList **devices)
        return SR_OK;
 }
 
-static GSList *hw_scan(GSList *options)
+static GSList *scan(GSList *options)
 {
        struct drv_context *drvc;
        struct sr_config *src;
@@ -317,7 +302,7 @@ static GSList *hw_scan(GSList *options)
                }
        }
 
-    devices = NULL;
+       devices = NULL;
        if (port) {
                if (probe_port(port, &devices) == SR_ERR_MALLOC)
                        return NULL;
@@ -338,19 +323,19 @@ static GSList *hw_scan(GSList *options)
                g_dir_close(dir);
        }
 
-    /* Tack a copy of the newly found devices onto the driver list. */
-    l = g_slist_copy(devices);
-    drvc->instances = g_slist_concat(drvc->instances, l);
+       /* Tack a copy of the newly found devices onto the driver list. */
+       l = g_slist_copy(devices);
+       drvc->instances = g_slist_concat(drvc->instances, l);
 
        return devices;
 }
 
-static GSList *hw_dev_list(void)
+static GSList *dev_list(void)
 {
        return ((struct drv_context *)(di->priv))->instances;
 }
 
-static int hw_dev_open(struct sr_dev_inst *sdi)
+static int dev_open(struct sr_dev_inst *sdi)
 {
 
        if (serial_open(sdi->conn, SERIAL_RDWR) != SR_OK)
@@ -359,12 +344,12 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
        if (rigol_ds1xx2_get_dev_cfg(sdi) != SR_OK)
                return SR_ERR;
 
-    sdi->status = SR_ST_ACTIVE;
+       sdi->status = SR_ST_ACTIVE;
 
        return SR_OK;
 }
 
-static int hw_dev_close(struct sr_dev_inst *sdi)
+static int dev_close(struct sr_dev_inst *sdi)
 {
        struct sr_serial_dev_inst *serial;
 
@@ -377,11 +362,9 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int hw_cleanup(void)
+static int cleanup(void)
 {
-       clear_instances();
-
-       return SR_OK;
+       return dev_clear();
 }
 
 static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
@@ -414,10 +397,8 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
 
        devc = sdi->priv;
 
-       if (sdi->status != SR_ST_ACTIVE) {
-               sr_err("Device inactive, can't set config options.");
-               return SR_ERR;
-       }
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
 
        ret = SR_OK;
        switch (id) {
@@ -575,7 +556,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        GSList *l;
        char cmd[256];
 
-       (void)cb_data;
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
 
        serial = sdi->conn;
        devc = sdi->priv;
@@ -613,7 +595,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        sr_source_add(serial->fd, G_IO_IN, 50, rigol_ds1xx2_receive, (void *)sdi);
 
        /* 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);
 
        /* Fetch the first frame. */
        if (devc->enabled_analog_probes) {
@@ -660,16 +642,16 @@ SR_PRIV struct sr_dev_driver rigol_ds1xx2_driver_info = {
        .name = "rigol-ds1xx2",
        .longname = "Rigol DS1xx2",
        .api_version = 1,
-       .init = hw_init,
-       .cleanup = hw_cleanup,
-       .scan = hw_scan,
-       .dev_list = hw_dev_list,
-       .dev_clear = clear_instances,
+       .init = init,
+       .cleanup = cleanup,
+       .scan = scan,
+       .dev_list = dev_list,
+       .dev_clear = dev_clear,
        .config_get = config_get,
        .config_set = config_set,
        .config_list = config_list,
-       .dev_open = hw_dev_open,
-       .dev_close = hw_dev_close,
+       .dev_open = dev_open,
+       .dev_close = dev_close,
        .dev_acquisition_start = dev_acquisition_start,
        .dev_acquisition_stop = dev_acquisition_stop,
        .priv = NULL,