From: Bert Vermeulen Date: Tue, 23 Apr 2013 13:14:42 +0000 (+0200) Subject: Enforce open device before config_set()/dev_acquisition_start() X-Git-Tag: dsupstream~70 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e73ffd4238c6d1be58d3fcdcf7f100200f033856;p=libsigrok.git Enforce open device before config_set()/dev_acquisition_start() --- diff --git a/hardware/agilent-dmm/api.c b/hardware/agilent-dmm/api.c index cce8f478..2bbd1e64 100644 --- a/hardware/agilent-dmm/api.c +++ b/hardware/agilent-dmm/api.c @@ -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; diff --git a/hardware/alsa/api.c b/hardware/alsa/api.c index 2e674fff..43d9b51b 100644 --- a/hardware/alsa/api.c +++ b/hardware/alsa/api.c @@ -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; diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index 64ea17d0..cfd95a11 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -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) { diff --git a/hardware/brymen-dmm/api.c b/hardware/brymen-dmm/api.c index 59f5040e..678f67b8 100644 --- a/hardware/brymen-dmm/api.c +++ b/hardware/brymen-dmm/api.c @@ -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; diff --git a/hardware/chronovu-la8/api.c b/hardware/chronovu-la8/api.c index d7841f3f..6e5fd5b6 100644 --- a/hardware/chronovu-la8/api.c +++ b/hardware/chronovu-la8/api.c @@ -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; diff --git a/hardware/colead-slm/api.c b/hardware/colead-slm/api.c index b4755ee7..7464f473 100644 --- a/hardware/colead-slm/api.c +++ b/hardware/colead-slm/api.c @@ -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; diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index 1619be24..1328c4cf 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -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; diff --git a/hardware/fluke-dmm/api.c b/hardware/fluke-dmm/api.c index 09847dd0..ef0e08cd 100644 --- a/hardware/fluke-dmm/api.c +++ b/hardware/fluke-dmm/api.c @@ -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; diff --git a/hardware/fx2lafw/fx2lafw.c b/hardware/fx2lafw/fx2lafw.c index f74c5a51..dbec30b7 100644 --- a/hardware/fx2lafw/fx2lafw.c +++ b/hardware/fx2lafw/fx2lafw.c @@ -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; diff --git a/hardware/hantek-dso/api.c b/hardware/hantek-dso/api.c index abf9db63..e7d9f60b 100644 --- a/hardware/hantek-dso/api.c +++ b/hardware/hantek-dso/api.c @@ -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; diff --git a/hardware/lascar-el-usb/api.c b/hardware/lascar-el-usb/api.c index db890d90..c841a132 100644 --- a/hardware/lascar-el-usb/api.c +++ b/hardware/lascar-el-usb/api.c @@ -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; diff --git a/hardware/link-mso19/api.c b/hardware/link-mso19/api.c index 63fafa86..cbf70986 100644 --- a/hardware/link-mso19/api.c +++ b/hardware/link-mso19/api.c @@ -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."); diff --git a/hardware/mic-985xx/api.c b/hardware/mic-985xx/api.c index 866acb41..4c093148 100644 --- a/hardware/mic-985xx/api.c +++ b/hardware/mic-985xx/api.c @@ -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(); diff --git a/hardware/nexus-osciprime/api.c b/hardware/nexus-osciprime/api.c index 48b361a0..b81b9e88 100644 --- a/hardware/nexus-osciprime/api.c +++ b/hardware/nexus-osciprime/api.c @@ -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; } diff --git a/hardware/openbench-logic-sniffer/api.c b/hardware/openbench-logic-sniffer/api.c index ba804ef9..1a449a6b 100644 --- a/hardware/openbench-logic-sniffer/api.c +++ b/hardware/openbench-logic-sniffer/api.c @@ -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; diff --git a/hardware/rigol-ds1xx2/api.c b/hardware/rigol-ds1xx2/api.c index 708c6015..5107d83d 100644 --- a/hardware/rigol-ds1xx2/api.c +++ b/hardware/rigol-ds1xx2/api.c @@ -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; diff --git a/hardware/serial-dmm/api.c b/hardware/serial-dmm/api.c index 8136f297..f59702cc 100644 --- a/hardware/serial-dmm/api.c +++ b/hardware/serial-dmm/api.c @@ -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; diff --git a/hardware/tondaj-sl-814/api.c b/hardware/tondaj-sl-814/api.c index 2e8f139d..bfe4c401 100644 --- a/hardware/tondaj-sl-814/api.c +++ b/hardware/tondaj-sl-814/api.c @@ -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; diff --git a/hardware/uni-t-dmm/api.c b/hardware/uni-t-dmm/api.c index a93dec4a..d210304b 100644 --- a/hardware/uni-t-dmm/api.c +++ b/hardware/uni-t-dmm/api.c @@ -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; } diff --git a/hardware/victor-dmm/api.c b/hardware/victor-dmm/api.c index 2222797d..c15239ed 100644 --- a/hardware/victor-dmm/api.c +++ b/hardware/victor-dmm/api.c @@ -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; diff --git a/hardware/zeroplus-logic-cube/api.c b/hardware/zeroplus-logic-cube/api.c index e9b5d6c7..f9578a8b 100644 --- a/hardware/zeroplus-logic-cube/api.c +++ b/hardware/zeroplus-logic-cube/api.c @@ -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; diff --git a/libsigrok.h b/libsigrok.h index aa3f4c71..8b9239ad 100644 --- a/libsigrok.h +++ b/libsigrok.h @@ -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. */