From: Uwe Hermann Date: Wed, 4 May 2011 17:34:12 +0000 (+0200) Subject: libsigrok: closedev() now has a return code. X-Git-Tag: libsigrok-0.1.0~264 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=697785d1aedc0bf385ea21074d83d61b11d8ce29 libsigrok: closedev() now has a return code. 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. --- diff --git a/device.c b/device.c index a1556aa4..fea3d60b 100644 --- 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); } } diff --git a/hardware/alsa/alsa.c b/hardware/alsa/alsa.c index 95161b7a..d61246e4 100644 --- a/hardware/alsa/alsa.c +++ b/hardware/alsa/alsa.c @@ -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) diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index 50bb932d..b85db609 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -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) diff --git a/hardware/chronovu-la8/chronovu-la8.c b/hardware/chronovu-la8/chronovu-la8.c index d2f07b10..0dea49be 100644 --- a/hardware/chronovu-la8/chronovu-la8.c +++ b/hardware/chronovu-la8/chronovu-la8.c @@ -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) diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index f28fa525..c1e1a907 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -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) diff --git a/hardware/link-mso19/link-mso19.c b/hardware/link-mso19/link-mso19.c index d37ba020..63b91031 100644 --- a/hardware/link-mso19/link-mso19.c +++ b/hardware/link-mso19/link-mso19.c @@ -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) diff --git a/hardware/openbench-logic-sniffer/ols.c b/hardware/openbench-logic-sniffer/ols.c index d2d49768..e3620485 100644 --- a/hardware/openbench-logic-sniffer/ols.c +++ b/hardware/openbench-logic-sniffer/ols.c @@ -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) diff --git a/hardware/saleae-logic/saleae-logic.c b/hardware/saleae-logic/saleae-logic.c index 173e8ada..0cc4245b 100644 --- a/hardware/saleae-logic/saleae-logic.c +++ b/hardware/saleae-logic/saleae-logic.c @@ -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) diff --git a/hardware/zeroplus-logic-cube/zeroplus.c b/hardware/zeroplus-logic-cube/zeroplus.c index 9b867dca..f5b2d9e4 100644 --- a/hardware/zeroplus-logic-cube/zeroplus.c +++ b/hardware/zeroplus-logic-cube/zeroplus.c @@ -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) diff --git a/sigrok.h b/sigrok.h index 13641bfd..c0c28a3a 100644 --- 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);