]> sigrok.org Git - libsigrok.git/commitdiff
sr_dev_open(): Factor out SR_ST_ACTIVE check.
authorUwe Hermann <redacted>
Fri, 7 Jul 2017 19:11:56 +0000 (21:11 +0200)
committerUwe Hermann <redacted>
Sat, 8 Jul 2017 12:25:23 +0000 (14:25 +0200)
This ensures consistent checks and log messages across all drivers
and reduces the per-driver boilerplate.

16 files changed:
src/device.c
src/hardware/dreamsourcelab-dslogic/protocol.c
src/hardware/fx2lafw/protocol.c
src/hardware/hameg-hmo/api.c
src/hardware/hantek-6xxx/protocol.c
src/hardware/hantek-dso/protocol.c
src/hardware/hung-chang-dso-2100/api.c
src/hardware/lecroy-logicstudio/api.c
src/hardware/lecroy-xstream/api.c
src/hardware/pipistrello-ols/api.c
src/hardware/rohde-schwarz-sme-0x/api.c
src/hardware/saleae-logic16/api.c
src/hardware/scpi-pps/api.c
src/hardware/sysclk-lwla/api.c
src/hardware/testo/protocol.c
src/hardware/yokogawa-dlm/api.c

index 6eff16d16573e45c78f0e836a168ff72ff15d31f..e5cbf4ef2868473e1c689e0752361d5f9e35c998 100644 (file)
@@ -560,6 +560,14 @@ SR_API int sr_dev_open(struct sr_dev_inst *sdi)
        if (!sdi || !sdi->driver || !sdi->driver->dev_open)
                return SR_ERR;
 
+       if (sdi->status == SR_ST_ACTIVE) {
+               sr_err("%s: Device instance already active, can't re-open.",
+                       sdi->driver->name);
+               return SR_ERR;
+       }
+
+       sr_dbg("%s: Opening device.", sdi->driver->name)
+
        ret = sdi->driver->dev_open(sdi);
 
        return ret;
index 0818e23f2fb7703bbab483b39a9c45042fe88c5e..43280cc56333e44586ebaee608e8cf07cca6783b 100644 (file)
@@ -568,10 +568,6 @@ SR_PRIV int dslogic_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di)
        devc = sdi->priv;
        usb = sdi->conn;
 
-       if (sdi->status == SR_ST_ACTIVE)
-               /* Device is already in use. */
-               return SR_ERR;
-
        device_count = libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
        if (device_count < 0) {
                sr_err("Failed to get device list: %s.",
index a31231fd41a22813ae3e4f23a69e1c5aa2c71a7d..422c84ea3f693abf4445d7f6f9f836389edd63e2 100644 (file)
@@ -155,10 +155,6 @@ SR_PRIV int fx2lafw_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di)
        devc = sdi->priv;
        usb = sdi->conn;
 
-       if (sdi->status == SR_ST_ACTIVE)
-               /* Device is already in use. */
-               return SR_ERR;
-
        device_count = libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
        if (device_count < 0) {
                sr_err("Failed to get device list: %s.",
index d4e184811763d20785302f514f70eeb770a07746..20b5779c1968badbbfb29e4cca0902aabdb8946a 100644 (file)
@@ -131,7 +131,7 @@ static int dev_clear(const struct sr_dev_driver *di)
 
 static int dev_open(struct sr_dev_inst *sdi)
 {
-       if (sdi->status != SR_ST_ACTIVE && sr_scpi_open(sdi->conn) != SR_OK)
+       if (sr_scpi_open(sdi->conn) != SR_OK)
                return SR_ERR;
 
        if (hmo_scope_state_get(sdi) != SR_OK)
index a43f72bbb546247abcd8ce68cfce68c19478d501..a08e126c5e32a9fc7f672b23d379ac6eeabfe57c 100644 (file)
@@ -33,10 +33,6 @@ SR_PRIV int hantek_6xxx_open(struct sr_dev_inst *sdi)
        devc = sdi->priv;
        usb = sdi->conn;
 
-       if (sdi->status == SR_ST_ACTIVE)
-               /* Already in use. */
-               return SR_ERR;
-
        libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
        for (i = 0; devlist[i]; i++) {
                libusb_get_device_descriptor(devlist[i], &des);
index bf91de451483f19fce735d942d532bdab4b03f2c..b1a56ebdeb482f46091c5d68f1a44978b6206277 100644 (file)
@@ -119,10 +119,6 @@ SR_PRIV int dso_open(struct sr_dev_inst *sdi)
        devc = sdi->priv;
        usb = sdi->conn;
 
-       if (sdi->status == SR_ST_ACTIVE)
-               /* already in use */
-               return SR_ERR;
-
        libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
        for (i = 0; devlist[i]; i++) {
                libusb_get_device_descriptor(devlist[i], &des);
index df2cddbba8000654e34890f7be218df35d003324..9f7526172d7c0ed95c650bd17766ebb962ffc5a2 100644 (file)
@@ -246,9 +246,6 @@ static int dev_open(struct sr_dev_inst *sdi)
        struct dev_context *devc = sdi->priv;
        int i;
 
-       if (sdi->status != SR_ST_INACTIVE)
-               goto fail1;
-
        if (ieee1284_open(sdi->conn, 0, &i) != E1284_OK)
                goto fail1;
 
index dfa13284273c8fcf6205b10327d797a11eace342..f177cabd129cd9eb947ebce69989d58308d6ad4b 100644 (file)
@@ -191,9 +191,6 @@ static int open_device(struct sr_dev_inst *sdi)
        size_t i;
        int r;
 
-       if (sdi->status == SR_ST_ACTIVE)
-               return SR_ERR;
-
        drvc = sdi->driver->context;
        usb = sdi->conn;
 
index 480866474b747791957df86f201b4912dc17c205..075fff76fb9816d11e5a2ceab2ba83f33167a606 100644 (file)
@@ -135,7 +135,7 @@ static int dev_clear(const struct sr_dev_driver *di)
 
 static int dev_open(struct sr_dev_inst *sdi)
 {
-       if (sdi->status != SR_ST_ACTIVE && sr_scpi_open(sdi->conn) != SR_OK)
+       if (sr_scpi_open(sdi->conn) != SR_OK)
                return SR_ERR;
 
        if (lecroy_xstream_state_get(sdi) != SR_OK)
index 9e274f3b5aecf8207951e8edce6afcb2458ed27e..5995cdf87f69cb21ccd1f81a56883f64f15bf2f0 100644 (file)
@@ -411,12 +411,12 @@ static int dev_open(struct sr_dev_inst *sdi)
 
        devc = sdi->priv;
 
-       if (p_ols_open(devc) != SR_OK) {
+       if (p_ols_open(devc) != SR_OK)
                return SR_ERR;
-       } else {
-               sdi->status = SR_ST_ACTIVE;
-               return SR_OK;
-       }
+
+       sdi->status = SR_ST_ACTIVE;
+
+       return SR_OK;
 }
 
 static int dev_close(struct sr_dev_inst *sdi)
index ff04242cab252dd58f9105d428d45d70669a5304..7d39cbdfe54f23b3443efac66b34ca8c9e3c4a99 100644 (file)
@@ -162,7 +162,7 @@ static int dev_clear(const struct sr_dev_driver *di)
 
 static int dev_open(struct sr_dev_inst *sdi)
 {
-       if ((sdi->status != SR_ST_ACTIVE) && (sr_scpi_open(sdi->conn) != SR_OK))
+       if (sr_scpi_open(sdi->conn) != SR_OK)
                return SR_ERR;
 
        sdi->status = SR_ST_ACTIVE;
index a8d32cf896086403a9661e90a0076cb952c90301..986b02571d6617998d2a9e3ad92d7b9295c975c5 100644 (file)
@@ -242,10 +242,6 @@ static int logic16_dev_open(struct sr_dev_inst *sdi)
        drvc = di->context;
        usb = sdi->conn;
 
-       if (sdi->status == SR_ST_ACTIVE)
-               /* Device is already in use. */
-               return SR_ERR;
-
        device_count = libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
        if (device_count < 0) {
                sr_err("Failed to get device list: %s.",
index 2746dc4019dc01b5c1f9a56446b536a882a724b8..50eabc9f4f7b3ccb254e5409a5802b0b34578373 100644 (file)
@@ -251,9 +251,6 @@ static int dev_open(struct sr_dev_inst *sdi)
        struct sr_scpi_dev_inst *scpi;
        GVariant *beeper;
 
-       if (sdi->status != SR_ST_INACTIVE)
-               return SR_ERR;
-
        scpi = sdi->conn;
        if (sr_scpi_open(scpi) < 0)
                return SR_ERR;
index da2019fba31eb51fbc44b82d1a37cae4309168c5..59b368196ff749acd2a18f91ca842f7c7e461ad6 100644 (file)
@@ -273,11 +273,6 @@ static int dev_open(struct sr_dev_inst *sdi)
        devc = sdi->priv;
        usb = sdi->conn;
 
-       if (sdi->status != SR_ST_INACTIVE) {
-               sr_err("Device already open.");
-               return SR_ERR;
-       }
-
        /* Try the whole shebang three times, fingers crossed. */
        for (i = 0; i < 3; i++) {
                ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, usb);
index 8ea254eb17aaf8320390a5e037e25b84619a3d1e..def73d42b5d1e6376002e57658b17802518a9e4c 100644 (file)
@@ -67,7 +67,7 @@ SR_PRIV int testo_probe_channels(struct sr_dev_inst *sdi)
        usb = sdi->conn;
 
        sr_dbg("Probing for channels.");
-       if (sdi->driver->dev_open(sdi) != SR_OK)
+       if (sr_dev_open(sdi) != SR_OK)
                return SR_ERR;
        if (testo_set_serial_params(usb) != SR_OK)
                return SR_ERR;
index 728fce03f5502ec3fe25e5ac0e633083444094e9..2faf7917cd05d89a85ab0c32fb9bbda1cc4c8f15 100644 (file)
@@ -141,7 +141,7 @@ static int dev_clear(const struct sr_dev_driver *di)
 
 static int dev_open(struct sr_dev_inst *sdi)
 {
-       if (sdi->status != SR_ST_ACTIVE && sr_scpi_open(sdi->conn) != SR_OK)
+       if (sr_scpi_open(sdi->conn) != SR_OK)
                return SR_ERR;
 
        if (dlm_scope_state_query(sdi) != SR_OK)