aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2016-05-15 18:33:31 +0200
committerUwe Hermann <uwe@hermann-uwe.de>2016-05-27 14:44:24 +0200
commit15a5bfe4815f9991a9bb532c05d6244a1818a0e4 (patch)
tree18d243d4d2d1d186eb79d7c841e9d6387f5682ca
parent566007e15e8ec0a23b064ba8ea44baae305508b5 (diff)
Add helper function for scan completion
A common task during device scan is to add the newly discovered devices to the instance list of the driver. Currently this is done by each driver on its own. This patch introduces a new helper function std_scan_complete() which takes care of this. The function should be called at the end of a driver's scan() callback before returning the device list. Doing this with a helper function provides guaranteed consistent behaviour among drivers and hopefully paves the way to moving more standard functionality directly into the sigrok core. Another common task that every driver has to do for each device instance is to initialize the device's driver field. So this is done in the new helper function as well. All drivers that can make use of the new helper are updated. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
-rw-r--r--src/hardware/agilent-dmm/api.c7
-rw-r--r--src/hardware/appa-55ii/api.c4
-rw-r--r--src/hardware/arachnid-labs-re-load-pro/api.c4
-rw-r--r--src/hardware/asix-sigma/api.c7
-rw-r--r--src/hardware/atten-pps3xxx/api.c4
-rw-r--r--src/hardware/baylibre-acme/api.c6
-rw-r--r--src/hardware/beaglelogic/api.c6
-rw-r--r--src/hardware/brymen-bm86x/api.c4
-rw-r--r--src/hardware/brymen-dmm/api.c6
-rw-r--r--src/hardware/cem-dt-885x/api.c4
-rw-r--r--src/hardware/center-3xx/api.c6
-rw-r--r--src/hardware/chronovu-la/api.c15
-rw-r--r--src/hardware/colead-slm/api.c7
-rw-r--r--src/hardware/conrad-digi-35-cpu/api.c4
-rw-r--r--src/hardware/demo/demo.c4
-rw-r--r--src/hardware/deree-de5000/api.c14
-rw-r--r--src/hardware/fluke-dmm/api.c4
-rw-r--r--src/hardware/ftdi-la/api.c17
-rw-r--r--src/hardware/fx2lafw/api.c4
-rw-r--r--src/hardware/gmc-mh-1x-2x/api.c8
-rw-r--r--src/hardware/hantek-6xxx/api.c13
-rw-r--r--src/hardware/hantek-dso/api.c13
-rw-r--r--src/hardware/hung-chang-dso-2100/api.c11
-rw-r--r--src/hardware/ikalogic-scanalogic2/api.c4
-rw-r--r--src/hardware/ikalogic-scanaplus/api.c4
-rw-r--r--src/hardware/kecheng-kc-330b/api.c4
-rw-r--r--src/hardware/kern-scale/api.c6
-rw-r--r--src/hardware/korad-kaxxxxp/api.c6
-rw-r--r--src/hardware/lascar-el-usb/api.c3
-rw-r--r--src/hardware/lascar-el-usb/protocol.c1
-rw-r--r--src/hardware/lecroy-logicstudio/api.c13
-rw-r--r--src/hardware/link-mso19/api.c8
-rw-r--r--src/hardware/manson-hcs-3xxx/api.c6
-rw-r--r--src/hardware/mic-985xx/api.c6
-rw-r--r--src/hardware/motech-lps-30x/api.c7
-rw-r--r--src/hardware/norma-dmm/api.c6
-rw-r--r--src/hardware/openbench-logic-sniffer/api.c9
-rw-r--r--src/hardware/openbench-logic-sniffer/protocol.c3
-rw-r--r--src/hardware/pce-322a/api.c6
-rw-r--r--src/hardware/pipistrello-ols/api.c6
-rw-r--r--src/hardware/pipistrello-ols/protocol.c3
-rw-r--r--src/hardware/saleae-logic16/api.c4
-rw-r--r--src/hardware/serial-dmm/api.c6
-rw-r--r--src/hardware/sysclk-lwla/api.c4
-rw-r--r--src/hardware/teleinfo/api.c6
-rw-r--r--src/hardware/testo/api.c3
-rw-r--r--src/hardware/tondaj-sl-814/api.c4
-rw-r--r--src/hardware/uni-t-dmm/api.c4
-rw-r--r--src/hardware/uni-t-ut32x/api.c4
-rw-r--r--src/hardware/victor-dmm/api.c4
-rw-r--r--src/hardware/zeroplus-logic-cube/api.c4
-rw-r--r--src/libsigrok-internal.h1
-rw-r--r--src/std.c48
53 files changed, 120 insertions, 245 deletions
diff --git a/src/hardware/agilent-dmm/api.c b/src/hardware/agilent-dmm/api.c
index 78e7efe..1165dc5 100644
--- a/src/hardware/agilent-dmm/api.c
+++ b/src/hardware/agilent-dmm/api.c
@@ -73,7 +73,6 @@ static const struct agdmm_profile supported_agdmm[] = {
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_config *src;
struct sr_serial_dev_inst *serial;
@@ -82,8 +81,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
const char *conn, *serialcomm;
char *buf, **tokens;
- drvc = di->context;
-
devices = NULL;
conn = serialcomm = NULL;
for (l = options; l; l = l->next) {
@@ -136,9 +133,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
break;
}
@@ -150,7 +145,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
if (!devices)
sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
diff --git a/src/hardware/appa-55ii/api.c b/src/hardware/appa-55ii/api.c
index c570001..d93644d 100644
--- a/src/hardware/appa-55ii/api.c
+++ b/src/hardware/appa-55ii/api.c
@@ -99,18 +99,16 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "T1");
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "T2");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
scan_cleanup:
serial_close(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
diff --git a/src/hardware/arachnid-labs-re-load-pro/api.c b/src/hardware/arachnid-labs-re-load-pro/api.c
index 6deb681..923f6b0 100644
--- a/src/hardware/arachnid-labs-re-load-pro/api.c
+++ b/src/hardware/arachnid-labs-re-load-pro/api.c
@@ -130,7 +130,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->vendor = g_strdup("Arachnid Labs");
sdi->model = g_strdup("Re:load Pro");
sdi->version = g_strdup(buf + 8);
- sdi->driver = di;
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
@@ -146,14 +145,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
devc = g_malloc0(sizeof(struct dev_context));
sdi->priv = devc;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
serial_close(serial);
if (!devices)
sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_list(uint32_t key, GVariant **data,
diff --git a/src/hardware/asix-sigma/api.c b/src/hardware/asix-sigma/api.c
index 255d3d5..8f04809 100644
--- a/src/hardware/asix-sigma/api.c
+++ b/src/hardware/asix-sigma/api.c
@@ -64,7 +64,6 @@ static int dev_clear(const struct sr_dev_driver *di)
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
GSList *devices;
struct ftdi_device_list *devlist;
@@ -75,8 +74,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
(void)options;
- drvc = di->context;
-
devices = NULL;
devc = g_malloc0(sizeof(struct dev_context));
@@ -119,19 +116,17 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup(USB_VENDOR_NAME);
sdi->model = g_strdup(USB_MODEL_NAME);
- sdi->driver = di;
for (i = 0; i < ARRAY_SIZE(channel_names); i++)
sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_names[i]);
devices = g_slist_append(devices, sdi);
- drvc->instances = g_slist_append(drvc->instances, sdi);
sdi->priv = devc;
/* We will open the device again when we need it. */
ftdi_list_free(&devlist);
- return devices;
+ return std_scan_complete(di, devices);
free:
ftdi_deinit(&devc->ftdic);
diff --git a/src/hardware/atten-pps3xxx/api.c b/src/hardware/atten-pps3xxx/api.c
index 7fd3b67..3b9f113 100644
--- a/src/hardware/atten-pps3xxx/api.c
+++ b/src/hardware/atten-pps3xxx/api.c
@@ -158,7 +158,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options, int modelid)
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Atten");
sdi->model = g_strdup(model->name);
- sdi->driver = di;
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
for (i = 0; i < MAX_CHANNELS; i++) {
@@ -176,14 +175,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options, int modelid)
devc->config = g_malloc0(sizeof(struct per_channel_config) * model->num_channels);
devc->delay_ms = delay_ms;
sdi->priv = devc;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
serial_close(serial);
if (!devices)
sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static GSList *scan_3203(struct sr_dev_driver *di, GSList *options)
diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c
index 1d83228..2072ccb 100644
--- a/src/hardware/baylibre-acme/api.c
+++ b/src/hardware/baylibre-acme/api.c
@@ -53,7 +53,6 @@ static const uint64_t samplerates[] = {
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_dev_inst *sdi;
GSList *devices;
@@ -62,7 +61,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
(void)options;
- drvc = di->context;
devices = NULL;
devc = g_malloc0(sizeof(struct dev_context));
@@ -72,7 +70,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("BayLibre");
sdi->model = g_strdup("ACME");
- sdi->driver = di;
sdi->priv = devc;
status = bl_acme_is_sane();
@@ -124,9 +121,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
goto err_out;
devices = g_slist_append(devices, sdi);
- drvc->instances = g_slist_append(drvc->instances, sdi);
- return devices;
+ return std_scan_complete(di, devices);
err_out:
g_free(devc);
diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c
index 10f9a0f..a94a917 100644
--- a/src/hardware/beaglelogic/api.c
+++ b/src/hardware/beaglelogic/api.c
@@ -73,7 +73,6 @@ static struct dev_context *beaglelogic_devc_alloc(void)
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
- struct drv_context *drvc;
GSList *devices, *l;
struct sr_config *src;
struct sr_dev_inst *sdi;
@@ -81,7 +80,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
int i, maxch;
devices = NULL;
- drvc = di->context;
/* Probe for /dev/beaglelogic */
if (!g_file_test(BEAGLELOGIC_DEV_NODE, G_FILE_TEST_EXISTS))
@@ -91,7 +89,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->status = SR_ST_INACTIVE;
sdi->model = g_strdup("BeagleLogic");
sdi->version = g_strdup("1.0");
- sdi->driver = di;
/* Unless explicitly specified, keep max channels to 8 only */
maxch = 8;
@@ -131,10 +128,9 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
channel_names[i]);
sdi->priv = devc;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
diff --git a/src/hardware/brymen-bm86x/api.c b/src/hardware/brymen-bm86x/api.c
index 64acf32..a9ac15b 100644
--- a/src/hardware/brymen-bm86x/api.c
+++ b/src/hardware/brymen-bm86x/api.c
@@ -70,7 +70,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->model = g_strdup("BM869");
devc = g_malloc0(sizeof(struct dev_context));
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P2");
@@ -79,11 +78,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sr_sw_limits_init(&devc->sw_limits);
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
diff --git a/src/hardware/brymen-dmm/api.c b/src/hardware/brymen-dmm/api.c
index 0e9034d..54f15c5 100644
--- a/src/hardware/brymen-dmm/api.c
+++ b/src/hardware/brymen-dmm/api.c
@@ -37,7 +37,6 @@ static GSList *brymen_scan(struct sr_dev_driver *di, const char *conn,
{
struct sr_dev_inst *sdi;
struct dev_context *devc;
- struct drv_context *drvc;
struct sr_serial_dev_inst *serial;
GSList *devices;
int ret;
@@ -75,17 +74,14 @@ static GSList *brymen_scan(struct sr_dev_driver *di, const char *conn,
sr_sw_limits_init(&devc->sw_limits);
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
- drvc = di->context;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
scan_cleanup:
serial_close(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static GSList *scan(struct sr_dev_driver *di, GSList *options)
diff --git a/src/hardware/cem-dt-885x/api.c b/src/hardware/cem-dt-885x/api.c
index af3626b..9ee036b 100644
--- a/src/hardware/cem-dt-885x/api.c
+++ b/src/hardware/cem-dt-885x/api.c
@@ -114,9 +114,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->conn = sr_serial_dev_inst_new(conn, SERIALCOMM);
sdi->inst_type = SR_INST_SERIAL;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "SPL");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
break;
}
@@ -126,7 +124,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
serial_close(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
diff --git a/src/hardware/center-3xx/api.c b/src/hardware/center-3xx/api.c
index 27c8d7e..6b9c0e3 100644
--- a/src/hardware/center-3xx/api.c
+++ b/src/hardware/center-3xx/api.c
@@ -60,7 +60,6 @@ static GSList *center_scan(const char *conn, const char *serialcomm, int idx)
{
int i;
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
GSList *devices;
@@ -70,7 +69,6 @@ static GSList *center_scan(const char *conn, const char *serialcomm, int idx)
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;
- drvc = center_devs[idx].di->context;
devices = NULL;
serial_flush(serial);
@@ -84,12 +82,10 @@ static GSList *center_scan(const char *conn, const char *serialcomm, int idx)
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = center_devs[idx].di;
for (i = 0; i < center_devs[idx].num_channels; i++)
sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]);
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
serial_close(serial);
@@ -126,7 +122,7 @@ static GSList *scan(GSList *options, int idx)
devices = center_scan(conn, center_devs[idx].conn, idx);
}
- return devices;
+ return std_scan_complete(center_devs[idx].di, devices);
}
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c
index d1a7ec7..ea247d4 100644
--- a/src/hardware/chronovu-la/api.c
+++ b/src/hardware/chronovu-la/api.c
@@ -61,20 +61,17 @@ static int dev_clear(const struct sr_dev_driver *di)
return std_dev_clear(di, clear_helper);
}
-static int add_device(struct sr_dev_driver *di, int model,
- struct libusb_device_descriptor *des, const char *serial_num,
- const char *connection_id, libusb_device *usbdev, GSList **devices)
+static int add_device(int model, struct libusb_device_descriptor *des,
+ const char *serial_num, const char *connection_id, libusb_device *usbdev,
+ GSList **devices)
{
int ret;
unsigned int i;
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
ret = SR_OK;
- drvc = di->context;
-
/* Allocate memory for our private device context. */
devc = g_malloc0(sizeof(struct dev_context));
@@ -116,7 +113,6 @@ static int add_device(struct sr_dev_driver *di, int model,
sdi->connection_id = g_strdup(connection_id);
sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(usbdev),
libusb_get_device_address(usbdev), NULL);
- sdi->driver = di;
sdi->priv = devc;
for (i = 0; i < devc->prof->num_channels; i++)
@@ -124,7 +120,6 @@ static int add_device(struct sr_dev_driver *di, int model,
cv_channel_names[i]);
*devices = g_slist_append(*devices, sdi);
- drvc->instances = g_slist_append(drvc->instances, sdi);
if (ret == SR_OK)
return SR_OK;
@@ -224,7 +219,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), connection_id);
- if ((ret = add_device(di, model, &des, serial_num, connection_id,
+ if ((ret = add_device(model, &des, serial_num, connection_id,
devlist[i], &devices)) < 0) {
sr_dbg("Failed to add device: %d.", ret);
}
@@ -233,7 +228,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
libusb_free_device_list(devlist, 1);
g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
diff --git a/src/hardware/colead-slm/api.c b/src/hardware/colead-slm/api.c
index bc59fd6..ded82dd 100644
--- a/src/hardware/colead-slm/api.c
+++ b/src/hardware/colead-slm/api.c
@@ -44,15 +44,12 @@ static const uint32_t devopts[] = {
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_dev_inst *sdi;
struct sr_config *src;
GSList *devices, *l;
const char *conn, *serialcomm;
- drvc = di->context;
-
devices = NULL;
conn = serialcomm = NULL;
@@ -81,12 +78,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->conn = sr_serial_dev_inst_new(conn, serialcomm);
sdi->inst_type = SR_INST_SERIAL;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
diff --git a/src/hardware/conrad-digi-35-cpu/api.c b/src/hardware/conrad-digi-35-cpu/api.c
index 44f9f26..442f6c7 100644
--- a/src/hardware/conrad-digi-35-cpu/api.c
+++ b/src/hardware/conrad-digi-35-cpu/api.c
@@ -90,12 +90,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->model = g_strdup("DIGI 35 CPU");
sdi->conn = serial;
sdi->priv = NULL;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
diff --git a/src/hardware/demo/demo.c b/src/hardware/demo/demo.c
index 9fa744b..083527c 100644
--- a/src/hardware/demo/demo.c
+++ b/src/hardware/demo/demo.c
@@ -284,7 +284,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->model = g_strdup("Demo device");
- sdi->driver = di;
devc = g_malloc0(sizeof(struct dev_context));
devc->cur_samplerate = SR_KHZ(200);
@@ -346,9 +345,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->priv = devc;
devices = g_slist_append(devices, sdi);
- drvc->instances = g_slist_append(drvc->instances, sdi);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
diff --git a/src/hardware/deree-de5000/api.c b/src/hardware/deree-de5000/api.c
index 675b332..2544b5e 100644
--- a/src/hardware/deree-de5000/api.c
+++ b/src/hardware/deree-de5000/api.c
@@ -25,16 +25,6 @@
#include <libsigrok/libsigrok.h>
#include "libsigrok-internal.h"
-static void std_dev_attach(struct sr_dev_driver *di, struct sr_dev_inst *sdi)
-{
- struct drv_context *drvc;
-
- drvc = di->context;
-
- sdi->driver = di;
- drvc->instances = g_slist_append(drvc->instances, sdi);
-}
-
#define LOG_PREFIX "deree-de5000"
static int dev_clear(const struct sr_dev_driver *di)
@@ -49,9 +39,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
if (!(sdi = es51919_serial_scan(options, "DER EE", "DE-5000")))
return NULL;
- std_dev_attach(di, sdi);
-
- return g_slist_append(NULL, sdi);
+ return std_scan_complete(di, g_slist_append(NULL, sdi));
}
static struct sr_dev_driver deree_de5000_driver_info = {
diff --git a/src/hardware/fluke-dmm/api.c b/src/hardware/fluke-dmm/api.c
index de4efcd..71bd79a 100644
--- a/src/hardware/fluke-dmm/api.c
+++ b/src/hardware/fluke-dmm/api.c
@@ -124,9 +124,7 @@ static GSList *fluke_scan(struct sr_dev_driver *di, const char *conn,
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
break;
}
@@ -140,7 +138,7 @@ static GSList *fluke_scan(struct sr_dev_driver *di, const char *conn,
if (!devices)
sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static GSList *scan(struct sr_dev_driver *di, GSList *options)
diff --git a/src/hardware/ftdi-la/api.c b/src/hardware/ftdi-la/api.c
index 5f5639f..78dc23f 100644
--- a/src/hardware/ftdi-la/api.c
+++ b/src/hardware/ftdi-la/api.c
@@ -82,7 +82,7 @@ static const struct ftdi_chip_desc *chip_descs[] = {
&ft232r_desc,
};
-static void scan_device(struct sr_dev_driver *di, struct ftdi_context *ftdic,
+static void scan_device(struct ftdi_context *ftdic,
struct libusb_device *dev, GSList **devices)
{
struct libusb_device_descriptor usb_desc;
@@ -90,10 +90,8 @@ static void scan_device(struct sr_dev_driver *di, struct ftdi_context *ftdic,
struct dev_context *devc;
char *vendor, *model, *serial_num;
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
int rv;
- drvc = di->context;
libusb_get_device_descriptor(dev, &usb_desc);
desc = NULL;
@@ -143,7 +141,6 @@ static void scan_device(struct sr_dev_driver *di, struct ftdi_context *ftdic,
sdi->vendor = vendor;
sdi->model = model;
sdi->serial_num = serial_num;
- sdi->driver = di;
sdi->priv = devc;
sdi->connection_id = g_strdup_printf("d:%u/%u",
libusb_get_bus_number(dev), libusb_get_device_address(dev));
@@ -153,7 +150,6 @@ static void scan_device(struct sr_dev_driver *di, struct ftdi_context *ftdic,
SR_CHANNEL_LOGIC, TRUE, *chan);
*devices = g_slist_append(*devices, sdi);
- drvc->instances = g_slist_append(drvc->instances, sdi);
return;
err_free_strings:
@@ -164,8 +160,7 @@ err_free_strings:
g_free(devc);
}
-static GSList *scan_all(struct ftdi_context *ftdic, struct sr_dev_driver *di,
- GSList *options)
+static GSList *scan_all(struct ftdi_context *ftdic, GSList *options)
{
GSList *devices;
struct ftdi_device_list *devlist = 0;
@@ -187,7 +182,7 @@ static GSList *scan_all(struct ftdi_context *ftdic, struct sr_dev_driver *di,
curdev = devlist;
while (curdev) {
- scan_device(di, ftdic, curdev->dev, &devices);
+ scan_device(ftdic, curdev->dev, &devices);
curdev = curdev->next;
}
@@ -234,17 +229,17 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
usb = l->data;
if (usb->bus == libusb_get_bus_number(devlist[i])
&& usb->address == libusb_get_device_address(devlist[i])) {
- scan_device(di, ftdic, devlist[i], &devices);
+ scan_device(ftdic, devlist[i], &devices);
}
}
}
libusb_free_device_list(devlist, 1);
} else
- devices = scan_all(ftdic, di, options);
+ devices = scan_all(ftdic, options);
ftdi_free(ftdic);
- return devices;
+ return std_scan_complete(di, devices);
}
static void clear_helper(void *priv)
diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c
index 262f3cd..46b9ee3 100644
--- a/src/hardware/fx2lafw/api.c
+++ b/src/hardware/fx2lafw/api.c
@@ -323,7 +323,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->vendor = g_strdup(prof->vendor);
sdi->model = g_strdup(prof->model);
sdi->version = g_strdup(prof->model_version);
- sdi->driver = di;
sdi->serial_num = g_strdup(serial_num);
sdi->connection_id = g_strdup(connection_id);
@@ -359,7 +358,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
if ((prof->dev_caps & DEV_CAPS_16BIT) || (prof->dev_caps & DEV_CAPS_AX_ANALOG))
devc->sample_wide = TRUE;
sdi->priv = devc;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
if (!strcmp(prof->model, "DSLogic")
@@ -403,7 +401,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
libusb_free_device_list(devlist, 1);
g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free);
- return devices;
+ return std_scan_complete(di, devices);
}
static void clear_dev_context(void *priv)
diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c
index 7ba93e4..3d18ebd 100644
--- a/src/hardware/gmc-mh-1x-2x/api.c
+++ b/src/hardware/gmc-mh-1x-2x/api.c
@@ -217,13 +217,11 @@ static GSList *scan_1x_2x_rs232(struct sr_dev_driver *di, GSList *options)
devc->settings_ok = FALSE;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
- return devices;
+ return std_scan_complete(di, devices);
}
/**
@@ -310,9 +308,7 @@ static GSList *scan_2x_bd232(struct sr_dev_driver *di, GSList *options)
sdi->version = g_strdup_printf("Firmware %d.%d", devc->fw_ver_maj, devc->fw_ver_min);
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
devc = g_malloc0(sizeof(struct dev_context));
sdi = g_malloc0(sizeof(struct sr_dev_inst));
@@ -327,7 +323,7 @@ static GSList *scan_2x_bd232(struct sr_dev_driver *di, GSList *options)
sr_dev_inst_free(sdi);
}
- return devices;
+ return std_scan_complete(di, devices);
exit_err:
sr_info("scan_2x_bd232(): Error!");
diff --git a/src/hardware/hantek-6xxx/api.c b/src/hardware/hantek-6xxx/api.c
index 65b5f04..5c2a478 100644
--- a/src/hardware/hantek-6xxx/api.c
+++ b/src/hardware/hantek-6xxx/api.c
@@ -78,13 +78,11 @@ static int read_channel(const struct sr_dev_inst *sdi, uint32_t amount);
static int dev_acquisition_stop(struct sr_dev_inst *sdi);
-static struct sr_dev_inst *hantek_6xxx_dev_new(struct sr_dev_driver *di,
- const struct hantek_6xxx_profile *prof)
+static struct sr_dev_inst *hantek_6xxx_dev_new(const struct hantek_6xxx_profile *prof)
{
struct sr_dev_inst *sdi;
struct sr_channel *ch;
struct sr_channel_group *cg;
- struct drv_context *drvc;
struct dev_context *devc;
unsigned int i;
@@ -92,7 +90,6 @@ static struct sr_dev_inst *hantek_6xxx_dev_new(struct sr_dev_driver *di,
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup(prof->vendor);
sdi->model = g_strdup(prof->model);
- sdi->driver = di;
for (i = 0; i < ARRAY_SIZE(channel_names); i++) {
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]);
@@ -119,8 +116,6 @@ static struct sr_dev_inst *hantek_6xxx_dev_new(struct sr_dev_driver *di,
devc->samplerate = DEFAULT_SAMPLERATE;
sdi->priv = devc;
- drvc = sdi->driver->context;
- drvc->instances = g_slist_append(drvc->instances, sdi);
return sdi;
}
@@ -222,7 +217,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
/* Device matches the pre-firmware profile. */
prof = &dev_profiles[j];
sr_dbg("Found a %s %s.", prof->vendor, prof->model);
- sdi = hantek_6xxx_dev_new(di, prof);
+ sdi = hantek_6xxx_dev_new(prof);
sdi->connection_id = g_strdup(connection_id);
devices = g_slist_append(devices, sdi);
devc = sdi->priv;
@@ -241,7 +236,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
/* Device matches the post-firmware profile. */
prof = &dev_profiles[j];
sr_dbg("Found a %s %s.", prof->vendor, prof->model);
- sdi = hantek_6xxx_dev_new(di, prof);
+ sdi = hantek_6xxx_dev_new(prof);
sdi->connection_id = g_strdup(connection_id);
sdi->status = SR_ST_INACTIVE;
devices = g_slist_append(devices, sdi);
@@ -258,7 +253,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
}
libusb_free_device_list(devlist, 1);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c
index 275bbf9..eb6c8b6 100644
--- a/src/hardware/hantek-dso/api.c
+++ b/src/hardware/hantek-dso/api.c
@@ -162,13 +162,11 @@ static const char *coupling[] = {
static int dev_acquisition_stop(struct sr_dev_inst *sdi);
-static struct sr_dev_inst *dso_dev_new(struct sr_dev_driver *di,
- const struct dso_profile *prof)
+static struct sr_dev_inst *dso_dev_new(const struct dso_profile *prof)
{
struct sr_dev_inst *sdi;
struct sr_channel *ch;
struct sr_channel_group *cg;
- struct drv_context *drvc;
struct dev_context *devc;
unsigned int i;
@@ -176,7 +174,6 @@ static struct sr_dev_inst *dso_dev_new(struct sr_dev_driver *di,
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup(prof->vendor);
sdi->model = g_strdup(prof->model);
- sdi->driver = di;
/*
* Add only the real channels -- EXT isn't a source of data, only
@@ -208,8 +205,6 @@ static struct sr_dev_inst *dso_dev_new(struct sr_dev_driver *di,
devc->triggersource = g_strdup(DEFAULT_TRIGGER_SOURCE);
devc->triggerposition = DEFAULT_HORIZ_TRIGGERPOS;
sdi->priv = devc;
- drvc = di->context;
- drvc->instances = g_slist_append(drvc->instances, sdi);
return sdi;
}
@@ -313,7 +308,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
/* Device matches the pre-firmware profile. */
prof = &dev_profiles[j];
sr_dbg("Found a %s %s.", prof->vendor, prof->model);
- sdi = dso_dev_new(di, prof);
+ sdi = dso_dev_new(prof);
sdi->connection_id = g_strdup(connection_id);
devices = g_slist_append(devices, sdi);
devc = sdi->priv;
@@ -332,7 +327,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
/* Device matches the post-firmware profile. */
prof = &dev_profiles[j];
sr_dbg("Found a %s %s.", prof->vendor, prof->model);
- sdi = dso_dev_new(di, prof);
+ sdi = dso_dev_new(prof);
sdi->connection_id = g_strdup(connection_id);
sdi->status = SR_ST_INACTIVE;
devices = g_slist_append(devices, sdi);
@@ -349,7 +344,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
}
libusb_free_device_list(devlist, 1);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
diff --git a/src/hardware/hung-chang-dso-2100/api.c b/src/hardware/hung-chang-dso-2100/api.c
index 039ba38..842bdc2 100644
--- a/src/hardware/hung-chang-dso-2100/api.c
+++ b/src/hardware/hung-chang-dso-2100/api.c
@@ -102,14 +102,12 @@ static const uint8_t coupling_map[] = {
0x00, 0x08, 0x04
};
-static GSList *scan_port(GSList *devices, struct sr_dev_driver *di,
- struct parport *port)
+static GSList *scan_port(GSList *devices, struct parport *port)
{
struct sr_dev_inst *sdi;
struct sr_channel *ch;
struct sr_channel_group *cg;
struct dev_context *devc;
- struct drv_context *drvc;
int i;
if (ieee1284_open(port, 0, &i) != E1284_OK) {
@@ -135,8 +133,6 @@ static GSList *scan_port(GSList *devices, struct sr_dev_driver *di,
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Hung-Chang");
sdi->model = g_strdup("DSO-2100");
- sdi->driver = di;
- drvc = di->context;
sdi->inst_type = 0; /* FIXME */
sdi->conn = port;
ieee1284_ref(port);
@@ -169,7 +165,6 @@ static GSList *scan_port(GSList *devices, struct sr_dev_driver *di,
devc->last_step = 0; /* buffersize = 1000 */
sdi->priv = devc;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
fail3:
@@ -209,7 +204,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
for (i = 0; i < ports.portc; i++)
if (!strcmp(ports.portv[i]->name, conn)) {
port_found = TRUE;
- devices = scan_port(devices, di, ports.portv[i]);
+ devices = scan_port(devices, ports.portv[i]);
}
if (!port_found) {
@@ -220,7 +215,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
ieee1284_free_ports(&ports);
- return devices;
+ return std_scan_complete(di, devices);
}
static void clear_private(void *priv)
diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c
index 0c6b898..2d194ab 100644
--- a/src/hardware/ikalogic-scanalogic2/api.c
+++ b/src/hardware/ikalogic-scanalogic2/api.c
@@ -106,7 +106,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->version = g_strdup_printf("%u.%u", dev_info.fw_ver_major, dev_info.fw_ver_minor);
sdi->serial_num = g_strdup_printf("%d", dev_info.serial);
sdi->priv = devc;
- sdi->driver = di;
sdi->inst_type = SR_INST_USB;
sdi->conn = usb;
@@ -145,13 +144,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
devc->xfer_data_out = devc->xfer_buf_out +
LIBUSB_CONTROL_SETUP_SIZE;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
g_slist_free(usb_devices);
- return devices;
+ return std_scan_complete(di, devices);
}
static void clear_dev_context(void *priv)
diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c
index 9b4af07..30b62e3 100644
--- a/src/hardware/ikalogic-scanaplus/api.c
+++ b/src/hardware/ikalogic-scanaplus/api.c
@@ -115,19 +115,17 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(USB_VENDOR_NAME);
sdi->model = g_strdup(USB_MODEL_NAME);
- sdi->driver = di;
sdi->priv = devc;
for (i = 0; i < ARRAY_SIZE(channel_names); i++)
sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_names[i]);
devices = g_slist_append(devices, sdi);
- drvc->instances = g_slist_append(drvc->instances, sdi);
/* Close device. We'll reopen it again when we need it. */
scanaplus_close(devc);
- return devices;
+ return std_scan_complete(di, devices);
scanaplus_close(devc);
err_free_ftdic:
diff --git a/src/hardware/kecheng-kc-330b/api.c b/src/hardware/kecheng-kc-330b/api.c
index fcd08ec..4dacfdc 100644
--- a/src/hardware/kecheng-kc-330b/api.c
+++ b/src/hardware/kecheng-kc-330b/api.c
@@ -124,7 +124,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR);
sdi->model = model; /* Already g_strndup()'d. */
- sdi->driver = di;
sdi->inst_type = SR_INST_USB;
sdi->conn = l->data;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "SPL");
@@ -142,14 +141,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
/* TODO: Set date/time? */
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
g_slist_free(usb_devices);
} else
g_slist_free_full(usb_devices, g_free);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
diff --git a/src/hardware/kern-scale/api.c b/src/hardware/kern-scale/api.c
index 4d1d6bb..7fa66bb 100644
--- a/src/hardware/kern-scale/api.c
+++ b/src/hardware/kern-scale/api.c
@@ -43,7 +43,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
GSList *l, *devices;
const char *conn, *serialcomm;
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
int ret;
@@ -77,7 +76,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sr_info("Probing serial port %s.", conn);
- drvc = di->context;
devices = NULL;
serial_flush(serial);
@@ -104,15 +102,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "Mass");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
scan_cleanup:
serial_close(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
diff --git a/src/hardware/korad-kaxxxxp/api.c b/src/hardware/korad-kaxxxxp/api.c
index bd80b6e..be47256 100644
--- a/src/hardware/korad-kaxxxxp/api.c
+++ b/src/hardware/korad-kaxxxxp/api.c
@@ -64,7 +64,6 @@ static const struct korad_kaxxxxp_model models[] = {
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
- struct drv_context *drvc;
struct dev_context *devc;
GSList *devices, *l;
struct sr_dev_inst *sdi;
@@ -78,7 +77,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
devices = NULL;
conn = NULL;
serialcomm = NULL;
- drvc = di->context;
for (l = options; l; l = l->next) {
src = l->data;
@@ -140,7 +138,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->model = g_strdup(models[model_id].name);
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
@@ -154,14 +151,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
/* Get current status of device. */
if (korad_kaxxxxp_get_all_values(serial, devc) < 0)
goto exit_err;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
serial_close(serial);
if (!devices)
sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(di, devices);
exit_err:
sr_dev_inst_free(sdi);
diff --git a/src/hardware/lascar-el-usb/api.c b/src/hardware/lascar-el-usb/api.c
index 1fd86b7..32bb958 100644
--- a/src/hardware/lascar-el-usb/api.c
+++ b/src/hardware/lascar-el-usb/api.c
@@ -72,14 +72,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
}
sdi->inst_type = SR_INST_USB;
sdi->conn = usb;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
g_slist_free(usb_devices);
} else
g_slist_free_full(usb_devices, g_free);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
diff --git a/src/hardware/lascar-el-usb/protocol.c b/src/hardware/lascar-el-usb/protocol.c
index ba9b84f..ceaf9d7 100644
--- a/src/hardware/lascar-el-usb/protocol.c
+++ b/src/hardware/lascar-el-usb/protocol.c
@@ -327,7 +327,6 @@ static struct sr_dev_inst *lascar_identify(unsigned char *config)
sdi->vendor = g_strdup(LASCAR_VENDOR);
sdi->model = g_strdup(profile->modelname);
sdi->version = g_strdup(firmware);
- sdi->driver = di;
if (profile->logformat == LOG_TEMP_RH) {
/* Model this as two channels: temperature and humidity. */
diff --git a/src/hardware/lecroy-logicstudio/api.c b/src/hardware/lecroy-logicstudio/api.c
index 69852b2..60325fe 100644
--- a/src/hardware/lecroy-logicstudio/api.c
+++ b/src/hardware/lecroy-logicstudio/api.c
@@ -71,9 +71,8 @@ static const uint64_t samplerates[] = {
SR_MHZ(500),
};
-static struct sr_dev_inst *create_device(struct sr_dev_driver *di,
- struct sr_usb_dev_inst *usb, enum sr_dev_inst_status status,
- int64_t fw_updated)
+static struct sr_dev_inst *create_device(struct sr_usb_dev_inst *usb,
+ enum sr_dev_inst_status status, int64_t fw_updated)
{
struct sr_dev_inst *sdi;
struct dev_context *devc;
@@ -84,7 +83,6 @@ static struct sr_dev_inst *create_device(struct sr_dev_driver *di,
sdi->status = status;
sdi->vendor = g_strdup("LeCroy");
sdi->model = g_strdup("LogicStudio16");
- sdi->driver = di;
sdi->inst_type = SR_INST_USB;
sdi->conn = usb;
@@ -140,7 +138,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
usb = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), NULL);
- sdi = create_device(di, usb, SR_ST_INACTIVE, 0);
+ sdi = create_device(usb, SR_ST_INACTIVE, 0);
break;
case LOGICSTUDIO16_PID_LACK_FIRMWARE:
r = ezusb_upload_firmware(drvc->sr_ctx, devlist[i],
@@ -161,7 +159,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
usb = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
UNKNOWN_ADDRESS, NULL);
- sdi = create_device(di, usb, SR_ST_INITIALIZING,
+ sdi = create_device(usb, SR_ST_INITIALIZING,
g_get_monotonic_time());
break;
default:
@@ -174,13 +172,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->connection_id = g_strdup(connection_id);
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
libusb_free_device_list(devlist, 1);
- return devices;
+ return std_scan_complete(di, devices);
}
static int open_device(struct sr_dev_inst *sdi)
diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c
index 99af8dc..a3b0086 100644
--- a/src/hardware/link-mso19/api.c
+++ b/src/hardware/link-mso19/api.c
@@ -159,21 +159,15 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->vendor = g_strdup(manufacturer);
sdi->model = g_strdup(product);
sdi->version = g_strdup(hwrev);
- sdi->driver = di;
sdi->priv = devc;
for (i = 0; i < ARRAY_SIZE(channel_names); i++) {
chtype = (i == 0) ? SR_CHANNEL_ANALOG : SR_CHANNEL_LOGIC;
sr_channel_new(sdi, i, chtype, TRUE, channel_names[i]);
}
-
- //Add the driver
- struct drv_context *drvc = di->context;
- drvc->instances = g_slist_append(drvc->instances, sdi);
- devices = g_slist_append(devices, sdi);
}
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
diff --git a/src/hardware/manson-hcs-3xxx/api.c b/src/hardware/manson-hcs-3xxx/api.c
index 0b0a053..b6449cf 100644
--- a/src/hardware/manson-hcs-3xxx/api.c
+++ b/src/hardware/manson-hcs-3xxx/api.c
@@ -76,7 +76,6 @@ static const struct hcs_model models[] = {
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
int i, model_id;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_dev_inst *sdi;
struct sr_config *src;
@@ -85,7 +84,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
struct sr_serial_dev_inst *serial;
char reply[50], **tokens, *dummy;
- drvc = di->context;
devices = NULL;
conn = NULL;
serialcomm = NULL;
@@ -146,7 +144,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->model = g_strdup(models[model_id].name);
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
@@ -177,14 +174,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
devc->voltage_max_device = g_strtod(tokens[0], &dummy) * devc->model->voltage[2];
g_strfreev(tokens);
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
serial_close(serial);
if (!devices)
sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(di, devices);
exit_err:
sr_dev_inst_free(sdi);
diff --git a/src/hardware/mic-985xx/api.c b/src/hardware/mic-985xx/api.c
index 329a14b..d29cc7e 100644
--- a/src/hardware/mic-985xx/api.c
+++ b/src/hardware/mic-985xx/api.c
@@ -60,7 +60,6 @@ SR_PRIV const struct mic_dev_info mic_devs[] = {
static GSList *mic_scan(const char *conn, const char *serialcomm, int idx)
{
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
GSList *devices;
@@ -70,7 +69,6 @@ static GSList *mic_scan(const char *conn, const char *serialcomm, int idx)
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;
- drvc = mic_devs[idx].di->context;
devices = NULL;
serial_flush(serial);
@@ -89,19 +87,17 @@ static GSList *mic_scan(const char *conn, const char *serialcomm, int idx)
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = mic_devs[idx].di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "Temperature");
if (mic_devs[idx].has_humidity)
sr_channel_new(sdi, 1, SR_CHANNEL_ANALOG, TRUE, "Humidity");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
serial_close(serial);
- return devices;
+ return std_scan_complete(mic_devs[idx].di, devices);
}
static GSList *scan(GSList *options, int idx)
diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c
index ce3294e..ee1f4f7 100644
--- a/src/hardware/motech-lps-30x/api.c
+++ b/src/hardware/motech-lps-30x/api.c
@@ -366,7 +366,6 @@ SR_PRIV int lps_read_reply(struct sr_serial_dev_inst *serial, char **buf, int *b
static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *options)
{
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
struct sr_channel *ch;
@@ -383,8 +382,6 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
conn = serialcomm = NULL;
devices = NULL;
- drvc = drv->context;
-
sr_spew("scan() called!");
/* Process and check options. */
@@ -446,7 +443,6 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
sdi->vendor = g_strdup(VENDOR_MOTECH);
sdi->model = g_strdup(models[modelid].modelstr);
sdi->version = g_strdup(verstr);
- sdi->driver = drv;
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
@@ -472,7 +468,6 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
/* Query status */
@@ -483,7 +478,7 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
if (!devices)
sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(drv, devices);
exit_err:
sr_info("%s: Error!", __func__);
diff --git a/src/hardware/norma-dmm/api.c b/src/hardware/norma-dmm/api.c
index 024bcae..2d154a4 100644
--- a/src/hardware/norma-dmm/api.c
+++ b/src/hardware/norma-dmm/api.c
@@ -68,7 +68,6 @@ static const char *get_typestr(int type, struct sr_dev_driver *drv)
static GSList *scan(struct sr_dev_driver *drv, GSList *options)
{
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_config *src;
struct sr_serial_dev_inst *serial;
@@ -79,7 +78,6 @@ static GSList *scan(struct sr_dev_driver *drv, GSList *options)
char req[10];
devices = NULL;
- drvc = drv->context;
conn = serialcomm = NULL;
for (l = options; l; l = l->next) {
@@ -138,9 +136,7 @@ static GSList *scan(struct sr_dev_driver *drv, GSList *options)
devc->version = g_strdup(&buf[9]);
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = drv;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
break;
}
@@ -163,7 +159,7 @@ static GSList *scan(struct sr_dev_driver *drv, GSList *options)
if (!devices)
sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(drv, devices);
}
static int dev_close(struct sr_dev_inst *sdi)
diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c
index 56161c5..ecd8a08 100644
--- a/src/hardware/openbench-logic-sniffer/api.c
+++ b/src/hardware/openbench-logic-sniffer/api.c
@@ -89,7 +89,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
struct sr_config *src;
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct sr_serial_dev_inst *serial;
GSList *l, *devices;
int ret;
@@ -97,8 +96,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
const char *conn, *serialcomm;
char buf[8];
- drvc = di->context;
-
devices = NULL;
conn = serialcomm = NULL;
@@ -182,7 +179,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->vendor = g_strdup("Sump");
sdi->model = g_strdup("Logic Analyzer");
sdi->version = g_strdup("v1.0");
- sdi->driver = di;
for (i = 0; i < ARRAY_SIZE(ols_channel_names); i++)
sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
ols_channel_names[i]);
@@ -195,12 +191,11 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
serial_close(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
@@ -570,7 +565,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
return SR_OK;
}
-SR_PRIV struct sr_dev_driver ols_driver_info = {
+static struct sr_dev_driver ols_driver_info = {
.name = "ols",
.longname = "Openbench Logic Sniffer",
.api_version = 1,
diff --git a/src/hardware/openbench-logic-sniffer/protocol.c b/src/hardware/openbench-logic-sniffer/protocol.c
index 15f1b3c..f88729d 100644
--- a/src/hardware/openbench-logic-sniffer/protocol.c
+++ b/src/hardware/openbench-logic-sniffer/protocol.c
@@ -20,8 +20,6 @@
#include <config.h>
#include "protocol.h"
-extern SR_PRIV struct sr_dev_driver ols_driver_info;
-
SR_PRIV int send_shortcommand(struct sr_serial_dev_inst *serial,
uint8_t command)
{
@@ -149,7 +147,6 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial)
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
- sdi->driver = &ols_driver_info;
devc = ols_dev_new();
sdi->priv = devc;
diff --git a/src/hardware/pce-322a/api.c b/src/hardware/pce-322a/api.c
index 8e408c1..2509447 100644
--- a/src/hardware/pce-322a/api.c
+++ b/src/hardware/pce-322a/api.c
@@ -59,7 +59,6 @@ static const uint64_t meas_ranges[][2] = {
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_config *src;
struct sr_serial_dev_inst *serial;
@@ -82,7 +81,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
return NULL;
devices = NULL;
- drvc = di->context;
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
@@ -93,14 +91,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->conn = sr_serial_dev_inst_new(conn, SERIALCOMM);
sdi->inst_type = SR_INST_SERIAL;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "SPL");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
serial_close(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_clear(const struct sr_dev_driver *di)
diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c
index eb81c78..91c7dc2 100644
--- a/src/hardware/pipistrello-ols/api.c
+++ b/src/hardware/pipistrello-ols/api.c
@@ -78,7 +78,6 @@ static const uint64_t samplerates[] = {
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
GSList *devices;
int ret, i;
@@ -87,8 +86,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
(void)options;
- drvc = di->context;
-
devices = NULL;
/* Allocate memory for our private device context. */
@@ -177,10 +174,9 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sr_dbg("Failed to set default samplerate (%"PRIu64").",
DEFAULT_SAMPLERATE);
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
- return devices;
+ return std_scan_complete(di, devices);
err_close_ftdic:
p_ols_close(devc);
diff --git a/src/hardware/pipistrello-ols/protocol.c b/src/hardware/pipistrello-ols/protocol.c
index d49d0e6..421934b 100644
--- a/src/hardware/pipistrello-ols/protocol.c
+++ b/src/hardware/pipistrello-ols/protocol.c
@@ -20,8 +20,6 @@
#include <config.h>
#include "protocol.h"
-extern SR_PRIV struct sr_dev_driver p_ols_driver_info;
-
SR_PRIV int write_shortcommand(struct dev_context *devc, uint8_t command)
{
uint8_t buf[1];
@@ -227,7 +225,6 @@ SR_PRIV struct sr_dev_inst *p_ols_get_metadata(uint8_t *buf, int bytes_read, str
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
- sdi->driver = &p_ols_driver_info;
sdi->priv = devc;
devname = g_string_new("");
diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c
index 906313d..3eb9f40 100644
--- a/src/hardware/saleae-logic16/api.c
+++ b/src/hardware/saleae-logic16/api.c
@@ -191,7 +191,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup("Saleae");
sdi->model = g_strdup("Logic16");
- sdi->driver = di;
sdi->connection_id = g_strdup(connection_id);
for (j = 0; j < ARRAY_SIZE(channel_names); j++)
@@ -201,7 +200,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
devc = g_malloc0(sizeof(struct dev_context));
devc->selected_voltage_range = VOLTAGE_RANGE_18_33_V;
sdi->priv = devc;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
if (check_conf_profile(devlist[i])) {
@@ -227,7 +225,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
libusb_free_device_list(devlist, 1);
g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free);
- return devices;
+ return std_scan_complete(di, devices);
}
static int logic16_dev_open(struct sr_dev_inst *sdi)
diff --git a/src/hardware/serial-dmm/api.c b/src/hardware/serial-dmm/api.c
index 3ccce70..af70fc3 100644
--- a/src/hardware/serial-dmm/api.c
+++ b/src/hardware/serial-dmm/api.c
@@ -48,7 +48,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
GSList *l, *devices;
const char *conn, *serialcomm;
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
int dropped, ret;
@@ -82,7 +81,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sr_info("Probing serial port %s.", conn);
- drvc = di->context;
devices = NULL;
serial_flush(serial);
@@ -130,15 +128,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
scan_cleanup:
serial_close(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c
index c66cbeb..2b20db8 100644
--- a/src/hardware/sysclk-lwla/api.c
+++ b/src/hardware/sysclk-lwla/api.c
@@ -194,15 +194,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
continue; /* no match */
/* Register device instance with driver. */
- sdi->driver = di;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
libusb_free_device_list(devlist, 1);
g_slist_free_full(conn_devices, (GDestroyNotify)&sr_usb_dev_inst_free);
- return devices;
+ return std_scan_complete(di, devices);
}
/* Destroy the private device context.
diff --git a/src/hardware/teleinfo/api.c b/src/hardware/teleinfo/api.c
index f5920c5..8934433 100644
--- a/src/hardware/teleinfo/api.c
+++ b/src/hardware/teleinfo/api.c
@@ -38,7 +38,6 @@ static const uint32_t devopts[] = {
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
struct sr_dev_inst *sdi;
@@ -73,7 +72,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sr_info("Probing serial port %s.", conn);
- drvc = di->context;
serial_flush(serial);
/* Let's get a bit of data and see if we can find a packet. */
@@ -92,7 +90,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P");
@@ -116,13 +113,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "IINST");
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "PAPP");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
scan_cleanup:
serial_close(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
diff --git a/src/hardware/testo/api.c b/src/hardware/testo/api.c
index 505df67..4d9a7a4 100644
--- a/src/hardware/testo/api.c
+++ b/src/hardware/testo/api.c
@@ -128,13 +128,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->priv = devc;
if (testo_probe_channels(sdi) != SR_OK)
continue;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
libusb_free_device_list(devlist, 1);
g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
diff --git a/src/hardware/tondaj-sl-814/api.c b/src/hardware/tondaj-sl-814/api.c
index d79bc03..cdb6f18 100644
--- a/src/hardware/tondaj-sl-814/api.c
+++ b/src/hardware/tondaj-sl-814/api.c
@@ -92,12 +92,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
diff --git a/src/hardware/uni-t-dmm/api.c b/src/hardware/uni-t-dmm/api.c
index c708d87..02e301c 100644
--- a/src/hardware/uni-t-dmm/api.c
+++ b/src/hardware/uni-t-dmm/api.c
@@ -87,15 +87,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->vendor = g_strdup(dmm->vendor);
sdi->model = g_strdup(dmm->device);
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
sdi->inst_type = SR_INST_USB;
sdi->conn = usb;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
diff --git a/src/hardware/uni-t-ut32x/api.c b/src/hardware/uni-t-ut32x/api.c
index 147ac7d..bc4ad43 100644
--- a/src/hardware/uni-t-ut32x/api.c
+++ b/src/hardware/uni-t-ut32x/api.c
@@ -70,7 +70,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR);
sdi->model = g_strdup(MODEL);
- sdi->driver = di;
sdi->inst_type = SR_INST_USB;
sdi->conn = l->data;
for (i = 0; i < ARRAY_SIZE(channel_names); i++)
@@ -80,14 +79,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->priv = devc;
devc->limit_samples = 0;
devc->data_source = DEFAULT_DATA_SOURCE;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
g_slist_free(usb_devices);
} else
g_slist_free_full(usb_devices, g_free);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c
index 6a70b14..3a132a1 100644
--- a/src/hardware/victor-dmm/api.c
+++ b/src/hardware/victor-dmm/api.c
@@ -76,7 +76,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VICTOR_VENDOR);
- sdi->driver = di;
sdi->connection_id = g_strdup(connection_id);
devc = g_malloc0(sizeof(struct dev_context));
sr_sw_limits_init(&devc->limits);
@@ -87,12 +86,11 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
libusb_get_device_address(devlist[i]), NULL);
sdi->inst_type = SR_INST_USB;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
libusb_free_device_list(devlist, 1);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c
index 2cbb5f6..547d815 100644
--- a/src/hardware/zeroplus-logic-cube/api.c
+++ b/src/hardware/zeroplus-logic-cube/api.c
@@ -212,7 +212,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR_NAME);
sdi->model = g_strdup(prof->model_name);
- sdi->driver = di;
sdi->serial_num = g_strdup(serial_num);
sdi->connection_id = g_strdup(connection_id);
@@ -238,7 +237,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
channel_names[j]);
devices = g_slist_append(devices, sdi);
- drvc->instances = g_slist_append(drvc->instances, sdi);
sdi->inst_type = SR_INST_USB;
sdi->conn = sr_usb_dev_inst_new(
libusb_get_bus_number(devlist[i]),
@@ -246,7 +244,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
}
libusb_free_device_list(devlist, 1);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h
index 68f0a29..ad578e9 100644
--- a/src/libsigrok-internal.h
+++ b/src/libsigrok-internal.h
@@ -938,6 +938,7 @@ SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver,
std_dev_clear_callback clear_private);
SR_PRIV GSList *std_dev_list(const struct sr_dev_driver *di);
SR_PRIV int std_serial_dev_close(struct sr_dev_inst *sdi);
+SR_PRIV GSList *std_scan_complete(struct sr_dev_driver *di, GSList *devices);
/*--- resource.c ------------------------------------------------------------*/
diff --git a/src/std.c b/src/std.c
index a03e509..4af3c68 100644
--- a/src/std.c
+++ b/src/std.c
@@ -349,3 +349,51 @@ SR_PRIV GSList *std_dev_list(const struct sr_dev_driver *di)
return drvc->instances;
}
+
+/**
+ * Standard scan() callback API helper.
+ *
+ * This function can be used to perform common tasks required by a driver's
+ * scan() callback. It will initialize the driver for each device on the list
+ * and add the devices on the list to the driver's device instance list.
+ * Usually it should be used as the last step in the scan() callback, right
+ * before returning.
+ *
+ * Note: This function can only be used if std_init() has been called
+ * previously by the driver.
+ *
+ * Example:
+ * @code{c}
+ * static GSList *scan(struct sr_dev_driver *di, GSList *options)
+ * {
+ * struct GSList *device;
+ * struct sr_dev_inst *sdi;
+ *
+ * sdi = g_new0(sr_dev_inst, 1);
+ * sdi->vendor = ...;
+ * ...
+ * devices = g_slist_append(devices, sdi);
+ * ...
+ * return std_scan_complete(di, devices);
+ * }
+ * @endcode
+ *
+ * @param di The driver instance to use.
+ * @param devices List of newly discovered devices (struct sr_dev_inst).
+ *
+ * @return The @p devices list.
+ */
+SR_PRIV GSList *std_scan_complete(struct sr_dev_driver *di, GSList *devices)
+{
+ struct drv_context *drvc = di->context;
+ GSList *l;
+
+ for (l = devices; l; l = l->next) {
+ struct sr_dev_inst *sdi = l->data;
+ sdi->driver = di;
+ }
+
+ drvc->instances = g_slist_concat(drvc->instances, g_slist_copy(devices));
+
+ return devices;
+}