sr_dev_open(): Factor out SR_ST_ACTIVE check.
This ensures consistent checks and log messages across all drivers and reduces the per-driver boilerplate.
This commit is contained in:
parent
093e1cba6b
commit
6402c37916
|
@ -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;
|
||||
|
|
|
@ -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.",
|
||||
|
|
|
@ -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.",
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.",
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue