]> sigrok.org Git - libsigrok.git/commitdiff
Enforce open device before config_set()/dev_acquisition_start()
authorBert Vermeulen <redacted>
Tue, 23 Apr 2013 13:14:42 +0000 (15:14 +0200)
committerBert Vermeulen <redacted>
Wed, 24 Apr 2013 20:03:50 +0000 (22:03 +0200)
22 files changed:
hardware/agilent-dmm/api.c
hardware/alsa/api.c
hardware/asix-sigma/asix-sigma.c
hardware/brymen-dmm/api.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/hantek-dso/api.c
hardware/lascar-el-usb/api.c
hardware/link-mso19/api.c
hardware/mic-985xx/api.c
hardware/nexus-osciprime/api.c
hardware/openbench-logic-sniffer/api.c
hardware/rigol-ds1xx2/api.c
hardware/serial-dmm/api.c
hardware/tondaj-sl-814/api.c
hardware/uni-t-dmm/api.c
hardware/victor-dmm/api.c
hardware/zeroplus-logic-cube/api.c
libsigrok.h

index cce8f478832800872aacf245bca57c412c5cd605..2bbd1e6478505272727a806595f514f36a27983e 100644 (file)
@@ -231,7 +231,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        struct dev_context *devc;
 
        if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR;
+               return SR_ERR_DEV_CLOSED;
 
        if (!(devc = sdi->priv)) {
                sr_err("sdi->priv was NULL.");
@@ -287,6 +287,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        if (!(devc = sdi->priv)) {
                sr_err("sdi->priv was NULL.");
                return SR_ERR_BUG;
index 2e674fff6e3fe151aa2233108212aeab11ccfe3b..43d9b51b5543484605f11826682f076ad8e4f27e 100644 (file)
@@ -92,6 +92,8 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
                return SR_ERR;
        }
 
+       sdi->status = SR_ST_ACTIVE;
+
        return SR_OK;
 }
 
@@ -108,6 +110,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
                        sr_err("Failed to close device: %s.",
                               snd_strerror(ret));
                        devc->capture_handle = NULL;
+            sdi->status = SR_ST_INACTIVE;
                }
        } else {
                sr_dbg("No capture handle, no need to close audio device.");
@@ -143,6 +146,9 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        devc = sdi->priv;
 
        switch (id) {
@@ -203,6 +209,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        int count, ret;
        char *endianness;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        devc = sdi->priv;
        devc->cb_data = cb_data;
        devc->num_samples = 0;
index 64ea17d028abcb93b5deaccebc17779ab054d3a5..cfd95a1115e924ba431d61f275e24ec6118ba0e2 100644 (file)
@@ -789,6 +789,9 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        struct dev_context *devc;
        int ret;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        devc = sdi->priv;
 
        if (id == SR_CONF_SAMPLERATE) {
@@ -1271,6 +1274,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        struct triggerinout triggerinout_conf;
        struct triggerlut lut;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        devc = sdi->priv;
 
        if (configure_probes(sdi) != SR_OK) {
index 59f5040e40995d96ffefe085131317b6523d8547..678f67b8a92cce2f8814cdc0e6cc7b1277b49372 100644 (file)
@@ -216,10 +216,8 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        struct dev_context *devc;
        int ret;
 
-       if (sdi->status != SR_ST_ACTIVE) {
-               sr_err("Device inactive, can't set config options.");
-               return SR_ERR;
-       }
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
 
        if (!(devc = sdi->priv)) {
                sr_err("sdi->priv was NULL.");
@@ -266,6 +264,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
 {
        struct dev_context *devc;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        if (!(devc = sdi->priv)) {
                sr_err("sdi->priv was NULL.");
                return SR_ERR_BUG;
index d7841f3f59cc4f56eaaa3c8c986f9ca251249423..6e5fd5b695638dfc3699516d9e1a43baa87717dc 100644 (file)
@@ -308,6 +308,9 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        if (!(devc = sdi->priv)) {
                sr_err("%s: sdi->priv was NULL.", __func__);
                return SR_ERR_BUG;
@@ -433,6 +436,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        uint8_t buf[4];
        int bytes_written;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        if (!(devc = sdi->priv)) {
                sr_err("%s: sdi->priv was NULL.", __func__);
                return SR_ERR_BUG;
index b4755ee7a14f4129e69e790fd12fbfe0a4b96b01..7464f473f6acf12c2b560e1e81d2ed621b2eb9bb 100644 (file)
@@ -176,7 +176,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        struct dev_context *devc;
 
        if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR;
+               return SR_ERR_DEV_CLOSED;
 
        if (!(devc = sdi->priv)) {
                sr_err("sdi->priv was NULL.");
@@ -233,6 +233,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        if (!(devc = sdi->priv)) {
                sr_err("sdi->priv was NULL.");
                return SR_ERR_BUG;
index 1619be24c9e2d927910379c9ccf9948c5b21f6af..1328c4cfc586869d18b5d9db46bfcd76afbfbdfc 100644 (file)
@@ -212,7 +212,7 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
 {
        (void)sdi;
 
-       /* Nothing needed so far. */
+       sdi->status = SR_ST_ACTIVE;
 
        return SR_OK;
 }
@@ -221,7 +221,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
 {
        (void)sdi;
 
-       /* Nothing needed so far. */
+    sdi->status = SR_ST_INACTIVE;
 
        return SR_OK;
 }
@@ -299,6 +299,9 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
 
        struct dev_context *const devc = sdi->priv;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        if (id == SR_CONF_SAMPLERATE) {
                devc->cur_samplerate = g_variant_get_uint64(data);
                sr_dbg("%s: setting samplerate to %" PRIu64, __func__,
@@ -460,6 +463,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
 {
        struct dev_context *const devc = sdi->priv;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        devc->cb_data = cb_data;
        devc->samples_counter = 0;
 
index 09847dd05ef4bc56bbe0b16ee2d0f529e9c28281..ef0e08cd6473eac846034407562cdbc4134c2e2e 100644 (file)
@@ -264,7 +264,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        struct dev_context *devc;
 
        if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR;
+               return SR_ERR_DEV_CLOSED;
 
        if (!(devc = sdi->priv)) {
                sr_err("sdi->priv was NULL.");
@@ -321,6 +321,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        if (!(devc = sdi->priv)) {
                sr_err("sdi->priv was NULL.");
                return SR_ERR_BUG;
index f74c5a510b0f1fe4d6035ba37e3708c746820cd7..dbec30b754904e84244135a3bfb1a73e276501cd 100644 (file)
@@ -617,6 +617,9 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        struct dev_context *devc;
        int ret;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR;
+
        devc = sdi->priv;
 
        if (id == SR_CONF_SAMPLERATE) {
@@ -948,6 +951,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        unsigned char *buf;
        size_t size;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        drvc = di->priv;
        devc = sdi->priv;
        usb = sdi->conn;
index abf9db63489a0a0fc9887112cb509ec52ee5471c..e7d9f60b618910febce8225181785f1d3e0507f0 100644 (file)
@@ -473,7 +473,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        char **targets;
 
        if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR;
+               return SR_ERR_DEV_CLOSED;
 
        ret = SR_OK;
        devc = sdi->priv;
@@ -926,7 +926,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        int i;
 
        if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR;
+               return SR_ERR_DEV_CLOSED;
 
        devc = sdi->priv;
        devc->cb_data = cb_data;
index db890d908f9dbcad1aa0bc150b0916fc719bd332..c841a132389652a1b64d47ab8871ce05e0ef9673 100644 (file)
@@ -229,14 +229,13 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        struct dev_context *devc;
        int ret;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        if (!di->priv) {
                sr_err("Driver was not initialized.");
                return SR_ERR;
        }
-       if (sdi->status != SR_ST_ACTIVE) {
-               sr_err("Device inactive, can't set config options.");
-               return SR_ERR;
-       }
 
        devc = sdi->priv;
        ret = SR_OK;
@@ -369,6 +368,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        int ret, i;
        unsigned char cmd[3], resp[4], *buf;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        if (!di->priv) {
                sr_err("Driver was not initialized.");
                return SR_ERR;
index 63fafa8627fa68edacd27fe554a0d5343fc9ec9d..cbf70986a198c71f41e4f97a224de90a18bc5871 100644 (file)
@@ -315,7 +315,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        devc = sdi->priv;
 
        if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR;
+               return SR_ERR_DEV_CLOSED;
 
        switch (id) {
        case SR_CONF_SAMPLERATE:
@@ -405,10 +405,10 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        struct dev_context *devc;
        int ret = SR_ERR;
 
-       devc = sdi->priv;
-
        if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR;
+               return SR_ERR_DEV_CLOSED;
+
+       devc = sdi->priv;
 
        if (mso_configure_probes(sdi) != SR_OK) {
                sr_err("Failed to configure probes.");
index 866acb41be000bc0f0f8a797745be199d55c1004..4c093148750de14b6598e61466c1de2d21ce33d8 100644 (file)
@@ -220,7 +220,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        struct dev_context *devc;
 
        if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR;
+               return SR_ERR_DEV_CLOSED;
 
        devc = sdi->priv;
 
@@ -268,10 +268,11 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
 
-       devc = sdi->priv;
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
 
+       devc = sdi->priv;
        devc->cb_data = cb_data;
-
        devc->num_samples = 0;
        devc->starttime = g_get_monotonic_time();
 
index 48b361a003ae677db979aafbdfa687bcdb29aeb7..b81b9e88c5f440d79246c35fc1ba6473069c8e69 100644 (file)
@@ -223,7 +223,7 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
 {
 
        /* TODO */
-       (void)sdi;
+       sdi->status = SR_ST_ACTIVE;
 
        return SR_OK;
 }
@@ -232,7 +232,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
 {
 
        /* TODO */
-       (void)sdi;
+    sdi->status = SR_ST_INACTIVE;
 
        return SR_OK;
 }
@@ -253,10 +253,8 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        /* TODO */
        (void)data;
 
-       if (sdi->status != SR_ST_ACTIVE) {
-               sr_err("Device inactive, can't set config options.");
-               return SR_ERR;
-       }
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
 
        ret = SR_OK;
        switch (id) {
@@ -285,9 +283,11 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
                                    void *cb_data)
 {
        /* TODO */
-       (void)sdi;
        (void)cb_data;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        return SR_OK;
 }
 
index ba804ef98ed916dc8fa6e9182c5283e4f1a813ef..1a449a6b6ad63a7e52dd2e0289076c2599e9479c 100644 (file)
@@ -280,6 +280,9 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        int ret;
        uint64_t tmp_u64;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        devc = sdi->priv;
 
        switch (id) {
@@ -366,12 +369,12 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        int num_channels;
        int i;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        devc = sdi->priv;
        serial = sdi->conn;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR;
-
        if (ols_configure_probes(sdi) != SR_OK) {
                sr_err("Failed to configure probes.");
                return SR_ERR;
index 708c6015d48dd1d8e2608c1b0e30b21edb1315de..5107d83ddee62bce3d8057615c6991d52160dc13 100644 (file)
@@ -414,10 +414,8 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
 
        devc = sdi->priv;
 
-       if (sdi->status != SR_ST_ACTIVE) {
-               sr_err("Device inactive, can't set config options.");
-               return SR_ERR;
-       }
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
 
        ret = SR_OK;
        switch (id) {
@@ -575,7 +573,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        GSList *l;
        char cmd[256];
 
-       (void)cb_data;
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
 
        serial = sdi->conn;
        devc = sdi->priv;
index 8136f2979c8e44345414396590eedd7e670fdf7d..f59702cc3648ba4b108c01651775dada164a9e70 100644 (file)
@@ -365,7 +365,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        struct dev_context *devc;
 
        if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR;
+               return SR_ERR_DEV_CLOSED;
 
        if (!(devc = sdi->priv)) {
                sr_err("sdi->priv was NULL.");
@@ -417,6 +417,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        if (!(devc = sdi->priv)) {
                sr_err("sdi->priv was NULL.");
                return SR_ERR_BUG;
index 2e8f139dea9fb3cf1a824e0ecba53e0c5b5f3016..bfe4c401ceac42f4fabc0f5679afa2328c39916a 100644 (file)
@@ -184,10 +184,8 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
 
-       if (sdi->status != SR_ST_ACTIVE) {
-               sr_err("Device inactive, can't set config options.");
-               return SR_ERR;
-       }
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
 
        devc = sdi->priv;
 
@@ -230,6 +228,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
 {
        struct dev_context *devc;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        devc = sdi->priv;
        devc->cb_data = cb_data;
 
index a93dec4af32dbbc002ae59e4546f5d793eddddb2..d210304bb6e87c5301eb69321bcd163e5b9e82e4 100644 (file)
@@ -147,11 +147,15 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
 {
        struct drv_context *drvc;
        struct dev_context *devc;
+    int ret;
 
        drvc = di->priv;
        devc = sdi->priv;
 
-       return sr_usb_open(drvc->sr_ctx->libusb_ctx, devc->usb);
+    if ((ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, devc->usb)) == SR_OK)
+        sdi->status = SR_ST_ACTIVE;
+
+    return ret;
 }
 
 static int hw_dev_close(struct sr_dev_inst *sdi)
@@ -160,6 +164,8 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
 
        /* TODO */
 
+    sdi->status = SR_ST_INACTIVE;
+
        return SR_OK;
 }
 
index 2222797d5d15d11403d5a4438d4bb0c043899974..c15239eddef18e4eb95ae8780edd14a54978d4f6 100644 (file)
@@ -257,6 +257,9 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        gint64 now;
        int ret;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        if (!di->priv) {
                sr_err("Driver was not initialized.");
                return SR_ERR;
@@ -396,6 +399,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        int ret, i;
        unsigned char *buf;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        if (!di->priv) {
                sr_err("Driver was not initialized.");
                return SR_ERR;
index e9b5d6c7265e43e84e6dae07cc3ba1aa914bf88b..f9578a8baceae2417f85e695215c75f312ee16aa 100644 (file)
@@ -524,10 +524,8 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
 
-       if (!sdi) {
-               sr_err("%s: sdi was NULL", __func__);
-               return SR_ERR_ARG;
-       }
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
 
        if (!(devc = sdi->priv)) {
                sr_err("%s: sdi->priv was NULL", __func__);
@@ -600,6 +598,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        unsigned int packet_num, n;
        unsigned char *buf;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        if (!(devc = sdi->priv)) {
                sr_err("%s: sdi->priv was NULL", __func__);
                return SR_ERR_ARG;
index aa3f4c71d72080b5fdc6286712aca5382de30606..8b9239ad77e366bc4691854ddcca8fa4a9ac016d 100644 (file)
@@ -71,6 +71,7 @@ enum {
        SR_ERR_BUG        = -4, /**< Errors hinting at internal bugs. */
        SR_ERR_SAMPLERATE = -5, /**< Incorrect samplerate. */
        SR_ERR_NA         = -6, /**< Not applicable. */
+       SR_ERR_DEV_CLOSED = -7, /**< Device is closed, but needs to be open. */
 };
 
 #define SR_MAX_NUM_PROBES    64 /* Limited by uint64_t. */