]> sigrok.org Git - libsigrok.git/commitdiff
allow for intermediate stage in stopping acquisition
authorBert Vermeulen <redacted>
Tue, 6 Nov 2012 14:02:37 +0000 (15:02 +0100)
committerBert Vermeulen <redacted>
Tue, 6 Nov 2012 14:16:22 +0000 (15:16 +0100)
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.

15 files changed:
hardware/agilent-dmm/api.c
hardware/asix-sigma/asix-sigma.c
hardware/chronovu-la8/api.c
hardware/colead-slm/api.c
hardware/demo/demo.c
hardware/fluke-dmm/api.c
hardware/fx2lafw/fx2lafw.c
hardware/genericdmm/api.c
hardware/hantek-dso/api.c
hardware/openbench-logic-sniffer/ols.c
hardware/radioshack-dmm/api.c
hardware/tekpower-dmm/api.c
hardware/uni-t-dmm/api.c
hardware/zeroplus-logic-cube/zeroplus.c
libsigrok.h

index 60f271b24721f464fe4281688ac27fd72887bf0b..848e2dcf6b574db62eeb0d8a6dcc9d8f8c16133e 100644 (file)
@@ -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;
index 7bf50104d094bcbc52d04f64c6798723b0b5ccf8..c44e961803c22568fac41dd8beb3ee2c6556a204 100644 (file)
@@ -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;
index 048c950fb2bdb2430872148c0725a1f502edf911..75f085c6bf646115fa30c7dab27c1c83284ccc66 100644 (file)
@@ -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;
 
index a22ccff5e874defaa1eafca0436fbc34d83d0c8c..eb3fa187c20851facff21e019439f709a145512f 100644 (file)
@@ -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;
index b8a4c242b048b5a8dd0c1c4226136be3d0cff9a1..fdbd89e7e833728ccc54c7ac45bc65d257eee3b3 100644 (file)
@@ -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;
 
index 2c82d92d0568434294074b55739d8f3517c2f982..78b63a8658fd280ab3c1f3063ee432fd5118aca6 100644 (file)
@@ -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;
index e74312fb77b8a745d770bd007f7fafed4c7e03d6..89eb01ee85dc10443b5d5a8020ccddace0993c12 100644 (file)
@@ -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. */
index 3057b6c15f5d8fdaa2163abf1ea2b61d7ca31b46..67b23620b11b721e6162a8bb819e46e214625208 100644 (file)
@@ -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;
 
index 8c7a9dce7e4e6738f713ced9ec849d0b791dfdd2..0847da558aabbacb361a4b6db3538514a199aecf 100644 (file)
@@ -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;
 
index ef3081c398d41530d4974cd925de60b19335efc7..6f914a8c8991851dac884897d025fb3de3b773fe 100644 (file)
@@ -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;
index 4eb5cbfa0ee995df59957768df6aa58009aadcd2..7520924012a18c64d06cedd9774af82800e91b02 100644 (file)
@@ -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;
index 79476145870e55f91e8d6088a82d3421103e111d..f6a649c1032341fcc6e8103f4a2945b2c1331703 100644 (file)
@@ -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;
index 1afc67ad08bd02f8086cf1781d60819c49cc870a..cf4c3435199c1bf1f2effeac0118d2e1d26b25eb 100644 (file)
@@ -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;
 
index f292ba568eeade006da86d62c920f501251a3f62..3145d767063c035dbd59d78cdafa5a1e4e26463c 100644 (file)
@@ -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;
index 73a3afc6e0987962338bc00f0bea9768056cd925..4810f8c15ac7e109d068dfae039ffab9b6a44deb 100644 (file)
@@ -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 */