From: Bert Vermeulen Date: Tue, 6 Nov 2012 14:02:37 +0000 (+0100) Subject: allow for intermediate stage in stopping acquisition X-Git-Tag: dsupstream~585 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=69b07d14db24055d23bbb4c4cc718ec073ece0b7;p=libsigrok.git allow for intermediate stage in stopping acquisition In the case of USB drivers, a driver's dev_acquisition_stop() cannot simply remove its fd sources from the session and close its devices: a USB transfer might still be underway, and it needs to be finished (and its memory freed) properly. An sr_dev_inst->status value is added: SR_ST_STOPPING, which should be set when the driver's dev_acquisition_stop() is called, and acts as a marker for the USB event handler to wind up its operations. In order for dev_acquisition_stop() to be able to set the sdi status, however, it needs to be unconstified. --- diff --git a/hardware/agilent-dmm/api.c b/hardware/agilent-dmm/api.c index 60f271b2..848e2dcf 100644 --- a/hardware/agilent-dmm/api.c +++ b/hardware/agilent-dmm/api.c @@ -397,8 +397,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { struct sr_datafeed_packet packet; struct dev_context *devc; diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index 7bf50104..c44e9618 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -42,6 +42,7 @@ SR_PRIV struct sr_dev_driver asix_sigma_driver_info; static struct sr_dev_driver *adi = &asix_sigma_driver_info; +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); static const uint64_t supported_samplerates[] = { SR_KHZ(200), @@ -122,9 +123,6 @@ static const char *firmware_files[] = { "asix-sigma-phasor.fw", /* Frequency counter */ }; -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data); - static int sigma_read(void *buf, size_t size, struct dev_context *devc) { int ret; @@ -1419,8 +1417,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc; uint8_t modestatus; diff --git a/hardware/chronovu-la8/api.c b/hardware/chronovu-la8/api.c index 048c950f..75f085c6 100644 --- a/hardware/chronovu-la8/api.c +++ b/hardware/chronovu-la8/api.c @@ -38,8 +38,7 @@ static const uint16_t usb_pids[] = { }; /* Function prototypes. */ -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data); +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); static int clear_instances(void) { @@ -506,8 +505,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { struct sr_datafeed_packet packet; diff --git a/hardware/colead-slm/api.c b/hardware/colead-slm/api.c index a22ccff5..eb3fa187 100644 --- a/hardware/colead-slm/api.c +++ b/hardware/colead-slm/api.c @@ -305,8 +305,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { struct sr_datafeed_packet packet; struct dev_context *devc; diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index b8a4c242..fdbd89e7 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -137,8 +137,7 @@ static int default_pattern = PATTERN_SIGROK; static GThread *my_thread; static int thread_running; -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data); +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); static int hw_init(void) { @@ -512,8 +511,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc; diff --git a/hardware/fluke-dmm/api.c b/hardware/fluke-dmm/api.c index 2c82d92d..78b63a86 100644 --- a/hardware/fluke-dmm/api.c +++ b/hardware/fluke-dmm/api.c @@ -380,8 +380,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { struct sr_datafeed_packet packet; struct dev_context *devc; diff --git a/hardware/fx2lafw/fx2lafw.c b/hardware/fx2lafw/fx2lafw.c index e74312fb..89eb01ee 100644 --- a/hardware/fx2lafw/fx2lafw.c +++ b/hardware/fx2lafw/fx2lafw.c @@ -143,8 +143,7 @@ static struct sr_dev_driver *fdi = &fx2lafw_driver_info; static int hw_dev_close(struct sr_dev_inst *sdi); static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap, const void *value); -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data); +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); /** * Check the USB configuration to determine if this is an fx2lafw device. @@ -1027,8 +1026,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, } /* TODO: This stops acquisition on ALL devices, ignoring dev_index. */ -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { /* Avoid compiler warnings. */ diff --git a/hardware/genericdmm/api.c b/hardware/genericdmm/api.c index 3057b6c1..67b23620 100644 --- a/hardware/genericdmm/api.c +++ b/hardware/genericdmm/api.c @@ -63,8 +63,7 @@ SR_PRIV struct sr_dev_driver genericdmm_driver_info; static struct sr_dev_driver *gdi = &genericdmm_driver_info; /* TODO need a way to keep this local to the static library */ static libusb_context *genericdmm_usb_context = NULL; -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data); +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); static GSList *connect_serial(const char *conn, const char *serialcomm) { @@ -556,8 +555,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { struct sr_datafeed_packet packet; diff --git a/hardware/hantek-dso/api.c b/hardware/hantek-dso/api.c index 8c7a9dce..0847da55 100644 --- a/hardware/hantek-dso/api.c +++ b/hardware/hantek-dso/api.c @@ -145,8 +145,7 @@ static const char *coupling[] = { SR_PRIV struct sr_dev_driver hantek_dso_driver_info; static struct sr_dev_driver *hdi = &hantek_dso_driver_info; -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data); +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); static struct sr_dev_inst *dso_dev_new(int index, const struct dso_profile *prof) { @@ -886,8 +885,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc; diff --git a/hardware/openbench-logic-sniffer/ols.c b/hardware/openbench-logic-sniffer/ols.c index ef3081c3..6f914a8c 100644 --- a/hardware/openbench-logic-sniffer/ols.c +++ b/hardware/openbench-logic-sniffer/ols.c @@ -1073,8 +1073,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, } /* TODO: This stops acquisition on ALL devices, ignoring dev_index. */ -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { /* Avoid compiler warnings. */ (void)cb_data; diff --git a/hardware/radioshack-dmm/api.c b/hardware/radioshack-dmm/api.c index 4eb5cbfa..75209240 100644 --- a/hardware/radioshack-dmm/api.c +++ b/hardware/radioshack-dmm/api.c @@ -376,8 +376,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { struct sr_datafeed_packet packet; struct dev_context *devc; diff --git a/hardware/tekpower-dmm/api.c b/hardware/tekpower-dmm/api.c index 79476145..f6a649c1 100644 --- a/hardware/tekpower-dmm/api.c +++ b/hardware/tekpower-dmm/api.c @@ -373,8 +373,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { struct sr_datafeed_packet packet; struct dev_context *devc; diff --git a/hardware/uni-t-dmm/api.c b/hardware/uni-t-dmm/api.c index 1afc67ad..cf4c3435 100644 --- a/hardware/uni-t-dmm/api.c +++ b/hardware/uni-t-dmm/api.c @@ -291,8 +291,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { struct sr_datafeed_packet packet; diff --git a/hardware/zeroplus-logic-cube/zeroplus.c b/hardware/zeroplus-logic-cube/zeroplus.c index f292ba56..3145d767 100644 --- a/hardware/zeroplus-logic-cube/zeroplus.c +++ b/hardware/zeroplus-logic-cube/zeroplus.c @@ -799,8 +799,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, } /* TODO: This stops acquisition on ALL devices, ignoring dev_index. */ -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { struct sr_datafeed_packet packet; struct dev_context *devc; diff --git a/libsigrok.h b/libsigrok.h index 73a3afc6..4810f8c1 100644 --- a/libsigrok.h +++ b/libsigrok.h @@ -547,6 +547,8 @@ enum { SR_ST_INACTIVE, /** The device instance is actively in use in a session. */ SR_ST_ACTIVE, + /** The device is winding down its session. */ + SR_ST_STOPPING, }; /* @@ -618,7 +620,7 @@ struct sr_dev_driver { const void *value); int (*dev_acquisition_start) (const struct sr_dev_inst *sdi, void *cb_data); - int (*dev_acquisition_stop) (const struct sr_dev_inst *sdi, + int (*dev_acquisition_stop) (struct sr_dev_inst *sdi, void *cb_data); /* Dynamic */