]> sigrok.org Git - libsigrok.git/commitdiff
libsigrok: closedev() now has a return code.
authorUwe Hermann <redacted>
Wed, 4 May 2011 17:34:12 +0000 (19:34 +0200)
committerUwe Hermann <redacted>
Thu, 5 May 2011 11:06:14 +0000 (13:06 +0200)
This is useful to allow frontends to react upon close failures in a
way they see fit (e.g. a popup in the GUI, or error message in the CLI).
They can also still ignore the error if they want, of course.

device.c
hardware/alsa/alsa.c
hardware/asix-sigma/asix-sigma.c
hardware/chronovu-la8/chronovu-la8.c
hardware/demo/demo.c
hardware/link-mso19/link-mso19.c
hardware/openbench-logic-sniffer/ols.c
hardware/saleae-logic/saleae-logic.c
hardware/zeroplus-logic-cube/zeroplus.c
sigrok.h

index a1556aa4e37244cb57bdf97f7ec644771cc70b7a..fea3d60bedfc235f87e59f5d5f6ba958a897892c 100644 (file)
--- a/device.c
+++ b/device.c
@@ -61,12 +61,18 @@ int sr_device_plugin_init(struct sr_device_plugin *plugin)
 
 void sr_device_close_all(void)
 {
+       int ret;
        struct sr_device *device;
 
        while (devices) {
                device = devices->data;
-               if (device->plugin && device->plugin->closedev)
-                       device->plugin->closedev(device->plugin_index);
+               if (device->plugin && device->plugin->closedev) {
+                       ret = device->plugin->closedev(device->plugin_index);
+                       if (ret != SR_OK) {
+                               sr_err("dev: %s: could not close device %d",
+                                      __func__, device->plugin_index);
+                       }
+               }
                sr_device_destroy(device);
        }
 }
index 95161b7ab8c3bd1df625c7f3a58a0d8c93d6054e..d61246e4388721bc95b535cef0759752dd90c59d 100644 (file)
@@ -108,21 +108,28 @@ static int hw_opendev(int device_index)
        return SR_OK;
 }
 
-static void hw_closedev(int device_index)
+static int hw_closedev(int device_index)
 {
        struct sr_device_instance *sdi;
        struct alsa *alsa;
 
-       if (!(sdi = sr_get_device_instance(device_instances, device_index)))
-               return;
-       alsa = sdi->priv;
-       if (!alsa)
-               return;
+       if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+               sr_err("alsa: %s: sdi was NULL", __func__);
+               return SR_ERR; /* TODO: SR_ERR_ARG? */
+       }
 
+       if (!(alsa = sdi->priv)) {
+               sr_err("alsa: %s: sdi->priv was NULL", __func__);
+               return SR_ERR; /* TODO: SR_ERR_ARG? */
+       }
+
+       // TODO: Return values of snd_*?
        if (alsa->hw_params)
                snd_pcm_hw_params_free(alsa->hw_params);
        if (alsa->capture_handle)
                snd_pcm_close(alsa->capture_handle);
+
+       return SR_OK;
 }
 
 static void hw_cleanup(void)
index 50bb932db26030405a611ebd684c916a8ff02521..b85db6095e87eecaa641b77ec4b0901a5e9c2cdc 100644 (file)
@@ -675,19 +675,28 @@ static int configure_probes(struct sr_device_instance *sdi, GSList *probes)
        return SR_OK;
 }
 
-static void hw_closedev(int device_index)
+static int hw_closedev(int device_index)
 {
        struct sr_device_instance *sdi;
        struct sigma *sigma;
 
-       if ((sdi = sr_get_device_instance(device_instances, device_index)))
-       {
-               sigma = sdi->priv;
-               if (sdi->status == SR_ST_ACTIVE)
-                       ftdi_usb_close(&sigma->ftdic);
+       if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+               sr_err("asix: %s: sdi was NULL", __func__);
+               return SR_ERR; /* TODO: SR_ERR_ARG? */
+       }
 
-               sdi->status = SR_ST_INACTIVE;
+       if (!(sigma = sdi->priv)) {
+               sr_err("asix: %s: sdi->priv was NULL", __func__);
+               return SR_ERR; /* TODO: SR_ERR_ARG? */
        }
+
+       /* TODO */
+       if (sdi->status == SR_ST_ACTIVE)
+               ftdi_usb_close(&sigma->ftdic);
+
+       sdi->status = SR_ST_INACTIVE;
+
+       return SR_OK;
 }
 
 static void hw_cleanup(void)
index d2f07b10eb43b5c8429228951f42f644284619d7..0dea49be4903b1ffa916672682f4fe13877e998c 100644 (file)
@@ -632,25 +632,26 @@ static int set_samplerate(struct sr_device_instance *sdi, uint64_t samplerate)
        return SR_OK;
 }
 
-static void hw_closedev(int device_index)
+static int hw_closedev(int device_index)
 {
        struct sr_device_instance *sdi;
        struct la8 *la8;
 
        if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
                sr_err("la8: %s: sdi was NULL", __func__);
-               return;
+               return SR_ERR; /* TODO: SR_ERR_ARG? */
        }
 
        if (!(la8 = sdi->priv)) {
                sr_err("la8: %s: sdi->priv was NULL", __func__);
-               return;
+               return SR_ERR; /* TODO: SR_ERR_ARG? */
        }
 
        sr_dbg("la8: closing device");
 
        if (sdi->status == SR_ST_ACTIVE) {
                sr_dbg("la8: %s: status ACTIVE, closing device", __func__);
+               /* TODO: Really ignore errors here, or return SR_ERR? */
                (void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */
        } else {
                sr_dbg("la8: %s: status not ACTIVE, nothing to do", __func__);
@@ -660,6 +661,8 @@ static void hw_closedev(int device_index)
 
        sr_dbg("la8: %s: freeing sample buffers", __func__);
        free(la8->final_buf);
+
+       return SR_OK;
 }
 
 static void hw_cleanup(void)
index f28fa525110e7164c664a608a6b085f1f28ddee4..c1e1a90721aaf811d62220ec3a9fb2ed1e1976b4 100644 (file)
@@ -121,15 +121,18 @@ static int hw_opendev(int device_index)
        device_index = device_index;
 
        /* Nothing needed so far. */
+
        return SR_OK;
 }
 
-static void hw_closedev(int device_index)
+static int hw_closedev(int device_index)
 {
        /* Avoid compiler warnings. */
        device_index = device_index;
 
        /* Nothing needed so far. */
+
+       return SR_OK;
 }
 
 static void hw_cleanup(void)
index d37ba02077a06cced83879fef655a61a667a9dc3..63b910318615002dfc653225232898ce5e50e464 100644 (file)
@@ -539,18 +539,23 @@ static int hw_opendev(int device_index)
        return SR_OK;
 }
 
-static void hw_closedev(int device_index)
+static int hw_closedev(int device_index)
 {
        struct sr_device_instance *sdi;
 
-       if (!(sdi = sr_get_device_instance(device_instances, device_index)))
-               return;
+       if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+               sr_err("mso19: %s: sdi was NULL", __func__);
+               return SR_ERR; /* TODO: SR_ERR_ARG? */
+       }
 
+       /* TODO */
        if (sdi->serial->fd != -1) {
                serial_close(sdi->serial->fd);
                sdi->serial->fd = -1;
                sdi->status = SR_ST_INACTIVE;
        }
+
+       return SR_OK;
 }
 
 static void *hw_get_device_info(int device_index, int device_info_id)
index d2d49768eb0e93397862a68c1d290d10082918e1..e3620485315cb99e6bdfe21e5b611920f88185da 100644 (file)
@@ -458,18 +458,23 @@ static int hw_opendev(int device_index)
        return SR_OK;
 }
 
-static void hw_closedev(int device_index)
+static int hw_closedev(int device_index)
 {
        struct sr_device_instance *sdi;
 
-       if (!(sdi = sr_get_device_instance(device_instances, device_index)))
-               return;
+       if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+               sr_err("ols: %s: sdi was NULL", __func__);
+               return SR_ERR; /* TODO: SR_ERR_ARG? */
+       }
 
+       /* TODO */
        if (sdi->serial->fd != -1) {
                serial_close(sdi->serial->fd);
                sdi->serial->fd = -1;
                sdi->status = SR_ST_INACTIVE;
        }
+
+       return SR_OK;
 }
 
 static void hw_cleanup(void)
index 173e8adaa8456cd7ef226ec91f166da0f3f95c8e..0cc4245bb33447ab235a22b6ca4d0d50177df163 100644 (file)
@@ -394,12 +394,19 @@ static int hw_opendev(int device_index)
        return SR_OK;
 }
 
-static void hw_closedev(int device_index)
+static int hw_closedev(int device_index)
 {
        struct sr_device_instance *sdi;
 
-       if ((sdi = sr_get_device_instance(device_instances, device_index)))
-               close_device(sdi);
+       if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+               sr_err("logic: %s: sdi was NULL", __func__);
+               return SR_ERR; /* TODO: SR_ERR_ARG? */
+       }
+
+       /* TODO */
+       close_device(sdi);
+
+       return SR_OK;
 }
 
 static void hw_cleanup(void)
index 9b867dca43e134da40f30a3d989caad7ddaef0d9..f5b2d9e4443268956df325ccec771397dd993957 100644 (file)
@@ -370,12 +370,19 @@ static int hw_opendev(int device_index)
        return SR_OK;
 }
 
-static void hw_closedev(int device_index)
+static int hw_closedev(int device_index)
 {
        struct sr_device_instance *sdi;
 
-       if ((sdi = sr_get_device_instance(device_instances, device_index)))
-               close_device(sdi);
+       if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+               sr_err("lap-c: %s: sdi was NULL", __func__);
+               return SR_ERR; /* TODO: SR_ERR_ARG? */
+       }
+
+       /* TODO */
+       close_device(sdi);
+
+       return SR_OK;
 }
 
 static void hw_cleanup(void)
index 13641bfdf13252ca988ad9fd45b49045ae666d43..c0c28a3a44aa5ffa3829b2095309fbcebc7b746d 100644 (file)
--- a/sigrok.h
+++ b/sigrok.h
@@ -335,7 +335,7 @@ struct sr_device_plugin {
 
        /* Device-specific */
        int (*opendev) (int device_index);
-       void (*closedev) (int device_index);
+       int (*closedev) (int device_index);
        void *(*get_device_info) (int device_index, int device_info_id);
        int (*get_status) (int device_index);
        int *(*get_capabilities) (void);