]> sigrok.org Git - libsigrok.git/blobdiff - hardware/openbench-logic-sniffer/ols.c
sr: rename more functions to sr_thing_action format
[libsigrok.git] / hardware / openbench-logic-sniffer / ols.c
index 930d008557f9101203446104fe35648e9f5d8861..c322f789fd64f3e831fda864be0c05752782e984 100644 (file)
@@ -231,7 +231,7 @@ static struct sr_device_instance *get_metadata(int fd)
        GString *tmp_str, *devicename, *version;
        gchar tmp_c;
 
-       sdi = sr_device_instance_new(0, SR_ST_INACTIVE, NULL, NULL, NULL);
+       sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, NULL, NULL, NULL);
        ols = ols_device_new();
        sdi->priv = ols;
 
@@ -446,13 +446,13 @@ static int hw_init(const char *deviceinfo)
                        sdi->index = final_devcnt;
                } else {
                        /* not an OLS -- some other board that uses the sump protocol */
-                       sdi = sr_device_instance_new(final_devcnt, SR_ST_INACTIVE,
+                       sdi = sr_dev_inst_new(final_devcnt, SR_ST_INACTIVE,
                                        "Sump", "Logic Analyzer", "v1.0");
                        ols = ols_device_new();
                        ols->num_probes = 32;
                        sdi->priv = ols;
                }
-               ols->serial = sr_serial_device_instance_new(device_names[i], -1);
+               ols->serial = sr_serial_dev_inst_new(device_names[i], -1);
                device_instances = g_slist_append(device_instances, sdi);
                final_devcnt++;
                serial_close(fds[i].fd);
@@ -485,7 +485,7 @@ static int hw_opendev(int device_index)
        struct sr_device_instance *sdi;
        struct ols_device *ols;
 
-       if (!(sdi = sr_get_device_instance(device_instances, device_index)))
+       if (!(sdi = sr_dev_inst_get(device_instances, device_index)))
                return SR_ERR;
 
        ols = sdi->priv;
@@ -504,7 +504,7 @@ static int hw_closedev(int device_index)
        struct sr_device_instance *sdi;
        struct ols_device *ols;
 
-       if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+       if (!(sdi = sr_dev_inst_get(device_instances, device_index))) {
                sr_err("ols: %s: sdi was NULL", __func__);
                return SR_ERR; /* TODO: SR_ERR_ARG? */
        }
@@ -521,23 +521,38 @@ static int hw_closedev(int device_index)
        return SR_OK;
 }
 
-static void hw_cleanup(void)
+static int hw_cleanup(void)
 {
        GSList *l;
        struct sr_device_instance *sdi;
        struct ols_device *ols;
+       int ret = SR_OK;
 
        /* Properly close and free all devices. */
        for (l = device_instances; l; l = l->next) {
-               sdi = l->data;
-               ols = sdi->priv;
+               if (!(sdi = l->data)) {
+                       /* Log error, but continue cleaning up the rest. */
+                       sr_err("ols: %s: sdi was NULL, continuing", __func__);
+                       ret = SR_ERR_BUG;
+                       continue;
+               }
+               if (!(ols = sdi->priv)) {
+                       /* Log error, but continue cleaning up the rest. */
+                       sr_err("ols: %s: sdi->priv was NULL, continuing",
+                              __func__);
+                       ret = SR_ERR_BUG;
+                       continue;
+               }
+               /* TODO: Check for serial != NULL. */
                if (ols->serial->fd != -1)
                        serial_close(ols->serial->fd);
-               sr_serial_device_instance_free(ols->serial);
-               sr_device_instance_free(sdi);
+               sr_serial_dev_inst_free(ols->serial);
+               sr_dev_inst_free(sdi);
        }
        g_slist_free(device_instances);
        device_instances = NULL;
+
+       return ret;
 }
 
 static void *hw_get_device_info(int device_index, int device_info_id)
@@ -546,7 +561,7 @@ static void *hw_get_device_info(int device_index, int device_info_id)
        struct ols_device *ols;
        void *info;
 
-       if (!(sdi = sr_get_device_instance(device_instances, device_index)))
+       if (!(sdi = sr_dev_inst_get(device_instances, device_index)))
                return NULL;
        ols = sdi->priv;
 
@@ -579,7 +594,7 @@ static int hw_get_status(int device_index)
 {
        struct sr_device_instance *sdi;
 
-       if (!(sdi = sr_get_device_instance(device_instances, device_index)))
+       if (!(sdi = sr_dev_inst_get(device_instances, device_index)))
                return SR_ST_NOT_FOUND;
 
        return sdi->status;
@@ -630,7 +645,7 @@ static int hw_set_configuration(int device_index, int capability, void *value)
        int ret;
        uint64_t *tmp_u64;
 
-       if (!(sdi = sr_get_device_instance(device_instances, device_index)))
+       if (!(sdi = sr_dev_inst_get(device_instances, device_index)))
                return SR_ERR;
        ols = sdi->priv;
 
@@ -870,7 +885,7 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
        int num_channels;
        int i;
 
-       if (!(sdi = sr_get_device_instance(device_instances, device_index)))
+       if (!(sdi = sr_dev_inst_get(device_instances, device_index)))
                return SR_ERR;
 
        ols = sdi->priv;