]> sigrok.org Git - libsigrok.git/commitdiff
sr/drivers: add API calls sr_dev_inst_list() and sr_dev_inst_clear()
authorBert Vermeulen <redacted>
Sun, 5 Aug 2012 22:59:25 +0000 (00:59 +0200)
committerBert Vermeulen <redacted>
Sun, 5 Aug 2012 22:59:25 +0000 (00:59 +0200)
These are used to list the device instances currently known to the driver,
and clear that list.

Drivers that don't necessarily clear their list of instances on every scan,
such as genericdmm, need to provide these to the frontend to keep instance
management sane.

device.c
hardware/asix-sigma/asix-sigma.c
hardware/chronovu-la8/api.c
hardware/demo/demo.c
hardware/fx2lafw/fx2lafw.c
hardware/genericdmm/api.c
hardware/hantek-dso/api.c
hardware/openbench-logic-sniffer/ols.c
hardware/zeroplus-logic-cube/zeroplus.c
libsigrok.h
proto.h

index 21ddebca47128f9855e76859498864626f921332..84d3d663dd6ff459589d844cd70cd40cd6776587 100644 (file)
--- a/device.c
+++ b/device.c
@@ -290,3 +290,22 @@ SR_API int sr_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
 
        return ret;
 }
+
+SR_API GSList *sr_dev_inst_list(const struct sr_dev_driver *driver)
+{
+
+       if (driver && driver->dev_list)
+               return driver->dev_list();
+       else
+               return NULL;
+}
+
+SR_API int sr_dev_inst_clear(const struct sr_dev_driver *driver)
+{
+
+       if (driver && driver->dev_clear)
+               return driver->dev_clear();
+       else
+               return SR_OK;
+}
+
index a1dd20729e52ef5f7aac47f0b3308fe6cc2b7878..ed32e6a5ae93516f2350ffb32883c74031eaee67 100644 (file)
@@ -406,7 +406,7 @@ static int bin2bitbang(const char *filename,
        return SR_OK;
 }
 
-static void clear_instances(void)
+static int clear_instances(void)
 {
        GSList *l;
        struct sr_dev_inst *sdi;
@@ -431,6 +431,7 @@ static void clear_instances(void)
        g_slist_free(drvc->instances);
        drvc->instances = NULL;
 
+       return SR_OK;
 }
 
 static int hw_init(void)
@@ -531,6 +532,15 @@ free:
        return NULL;
 }
 
+static GSList *hw_dev_list(void)
+{
+       struct drv_context *drvc;
+
+       drvc = adi->priv;
+
+       return drvc->instances;
+}
+
 static int upload_firmware(int firmware_idx, struct dev_context *devc)
 {
        int ret;
@@ -1455,6 +1465,8 @@ SR_PRIV struct sr_dev_driver asix_sigma_driver_info = {
        .init = hw_init,
        .cleanup = hw_cleanup,
        .scan = hw_scan,
+       .dev_list = hw_dev_list,
+       .dev_clear = clear_instances,
        .dev_open = hw_dev_open,
        .dev_close = hw_dev_close,
        .info_get = hw_info_get,
index a7fff10856c6c6c16f0fe3e859f0961dc25eb413..012ad6f1e3e8773fb8621b5701a33459ebfa8e04 100644 (file)
@@ -41,7 +41,7 @@ static const uint16_t usb_pids[] = {
 static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi,
                void *cb_data);
 
-static void clear_instances(void)
+static int clear_instances(void)
 {
        GSList *l;
        struct sr_dev_inst *sdi;
@@ -66,6 +66,7 @@ static void clear_instances(void)
        g_slist_free(drvc->instances);
        drvc->instances = NULL;
 
+       return SR_OK;
 }
 
 static int hw_init(void)
@@ -186,6 +187,15 @@ err_free_nothing:
        return NULL;
 }
 
+static GSList *hw_dev_list(void)
+{
+       struct drv_context *drvc;
+
+       drvc = cdi->priv;
+
+       return drvc->instances;
+}
+
 static int hw_dev_open(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
@@ -519,6 +529,8 @@ SR_PRIV struct sr_dev_driver chronovu_la8_driver_info = {
        .init = hw_init,
        .cleanup = hw_cleanup,
        .scan = hw_scan,
+       .dev_list = hw_dev_list,
+       .dev_clear = clear_instances,
        .dev_open = hw_dev_open,
        .dev_close = hw_dev_close,
        .info_get = hw_info_get,
index 3e3150afc6663156f0aaac25aeeb0f7505bbb269..ba440a3d0289dd170fa1aa1f1823d035cd366922 100644 (file)
@@ -192,6 +192,15 @@ static GSList *hw_scan(GSList *options)
        return devices;
 }
 
+static GSList *hw_dev_list(void)
+{
+       struct drv_context *drvc;
+
+       drvc = ddi->priv;
+
+       return drvc->instances;
+}
+
 static int hw_dev_open(struct sr_dev_inst *sdi)
 {
        /* Avoid compiler warnings. */
@@ -537,6 +546,7 @@ SR_PRIV struct sr_dev_driver demo_driver_info = {
        .init = hw_init,
        .cleanup = hw_cleanup,
        .scan = hw_scan,
+       .dev_list = hw_dev_list,
        .dev_open = hw_dev_open,
        .dev_close = hw_dev_close,
        .info_get = hw_info_get,
index 44cc9aef802adc336f34db745a4da8e1c922638f..d519db6f4099a1fd6d47b74933e65bfeb7f62137 100644 (file)
@@ -511,6 +511,15 @@ static GSList *hw_scan(GSList *options)
        return devices;
 }
 
+static GSList *hw_dev_list(void)
+{
+       struct drv_context *drvc;
+
+       drvc = fdi->priv;
+
+       return drvc->instances;
+}
+
 static int hw_dev_open(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
@@ -1046,6 +1055,8 @@ SR_PRIV struct sr_dev_driver fx2lafw_driver_info = {
        .init = hw_init,
        .cleanup = hw_cleanup,
        .scan = hw_scan,
+       .dev_list = hw_dev_list,
+       .dev_clear = clear_instances,
        .dev_open = hw_dev_open,
        .dev_close = hw_dev_close,
        .info_get = hw_info_get,
index 421360173ba3378ec3420f2a56d6109d2bffdab9..035ffedfd55eafd998cc585ee2fb55df3007d236 100644 (file)
@@ -219,6 +219,52 @@ static GSList *default_scan(GSList *options)
        return devices;
 }
 
+static int clear_instances(void)
+{
+       GSList *l;
+       struct sr_dev_inst *sdi;
+       struct dev_context *devc;
+       struct drv_context *drvc;
+
+       if (!(drvc = gdi->priv))
+               return SR_OK;
+
+       /* Properly close and free all devices. */
+       for (l = drvc->instances; l; l = l->next) {
+               if (!(sdi = l->data)) {
+                       /* Log error, but continue cleaning up the rest. */
+                       sr_err("genericdmm: sdi was NULL, continuing.");
+                       continue;
+               }
+               if (!(devc = sdi->priv)) {
+                       /* Log error, but continue cleaning up the rest. */
+                       sr_err("genericdmm: sdi->priv was NULL, continuing.");
+                       continue;
+               }
+
+               if (devc->profile) {
+                       switch (devc->profile->transport) {
+                       case DMM_TRANSPORT_USBHID:
+                               /* TODO */
+                               sr_usb_dev_inst_free(devc->usb);
+                               break;
+                       case DMM_TRANSPORT_SERIAL:
+                               if (devc->serial && devc->serial->fd != -1)
+                                       serial_close(devc->serial->fd);
+                               sr_serial_dev_inst_free(devc->serial);
+                               break;
+                       }
+               }
+
+               sr_dev_inst_free(sdi);
+       }
+
+       g_slist_free(drvc->instances);
+       drvc->instances = NULL;
+
+       return SR_OK;
+}
+
 static int hw_init(void)
 {
        struct drv_context *drvc;
@@ -338,6 +384,15 @@ static GSList *hw_scan(GSList *options)
        return devices;
 }
 
+static GSList *hw_dev_list(void)
+{
+       struct drv_context *drvc;
+
+       drvc = gdi->priv;
+
+       return drvc->instances;
+}
+
 static int hw_dev_open(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
@@ -347,14 +402,13 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
                return SR_ERR_BUG;
        }
 
-       sr_dbg("genericdmm: Opening serial port '%s'.", devc->serial->port);
-
        switch (devc->profile->transport) {
        case DMM_TRANSPORT_USBHID:
                /* TODO */
                break;
        case DMM_TRANSPORT_SERIAL:
                /* TODO: O_NONBLOCK? */
+               sr_dbg("genericdmm: Opening serial port '%s'.", devc->serial->port);
                devc->serial->fd = serial_open(devc->serial->port, O_RDWR | O_NONBLOCK);
                if (devc->serial->fd == -1) {
                        sr_err("genericdmm: Couldn't open serial port '%s'.",
@@ -397,46 +451,8 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
 
 static int hw_cleanup(void)
 {
-       GSList *l;
-       struct sr_dev_inst *sdi;
-       struct dev_context *devc;
-       struct drv_context *drvc;
-
-       if (!(drvc = gdi->priv))
-               return SR_OK;
-
-       /* Properly close and free all devices. */
-       for (l = drvc->instances; l; l = l->next) {
-               if (!(sdi = l->data)) {
-                       /* Log error, but continue cleaning up the rest. */
-                       sr_err("genericdmm: sdi was NULL, continuing.");
-                       continue;
-               }
-               if (!(devc = sdi->priv)) {
-                       /* Log error, but continue cleaning up the rest. */
-                       sr_err("genericdmm: sdi->priv was NULL, continuing.");
-                       continue;
-               }
 
-               if (devc->profile) {
-                       switch (devc->profile->transport) {
-                       case DMM_TRANSPORT_USBHID:
-                               /* TODO */
-                               sr_usb_dev_inst_free(devc->usb);
-                               break;
-                       case DMM_TRANSPORT_SERIAL:
-                               if (devc->serial && devc->serial->fd != -1)
-                                       serial_close(devc->serial->fd);
-                               sr_serial_dev_inst_free(devc->serial);
-                               break;
-                       }
-               }
-
-               sr_dev_inst_free(sdi);
-       }
-
-       g_slist_free(drvc->instances);
-       drvc->instances = NULL;
+       clear_instances();
 
        if (genericdmm_usb_context)
                libusb_exit(genericdmm_usb_context);
@@ -610,6 +626,8 @@ SR_PRIV struct sr_dev_driver genericdmm_driver_info = {
        .init = hw_init,
        .cleanup = hw_cleanup,
        .scan = hw_scan,
+       .dev_list = hw_dev_list,
+       .dev_clear = clear_instances,
        .dev_open = hw_dev_open,
        .dev_close = hw_dev_close,
        .info_get = hw_info_get,
index c1828b44a732bc72d776aabe90f5eff16a39f144..64dc0f98080af1b7f776337625d8cdd5b3c79a10 100644 (file)
@@ -221,7 +221,7 @@ static int configure_probes(const struct sr_dev_inst *sdi)
 }
 
 /* Properly close and free all devices. */
-static void clear_instances(void)
+static int clear_instances(void)
 {
        struct sr_dev_inst *sdi;
        struct drv_context *drvc;
@@ -250,6 +250,7 @@ static void clear_instances(void)
        g_slist_free(drvc->instances);
        drvc->instances = NULL;
 
+       return SR_OK;
 }
 
 static int hw_init(void)
@@ -346,6 +347,15 @@ static GSList *hw_scan(GSList *options)
        return devices;
 }
 
+static GSList *hw_dev_list(void)
+{
+       struct drv_context *drvc;
+
+       drvc = hdi->priv;
+
+       return drvc->instances;
+}
+
 static int hw_dev_open(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
@@ -904,6 +914,8 @@ SR_PRIV struct sr_dev_driver hantek_dso_driver_info = {
        .init = hw_init,
        .cleanup = hw_cleanup,
        .scan = hw_scan,
+       .dev_list = hw_dev_list,
+       .dev_clear = clear_instances,
        .dev_open = hw_dev_open,
        .dev_close = hw_dev_close,
        .info_get = hw_info_get,
index 7a89d77518f65e290778c1f7c32783d1761dc812..5b13931c1b9c95e2b2327bcbd96dd35800fdbe36 100644 (file)
@@ -519,6 +519,15 @@ hw_init_free_ports:
        return devices;
 }
 
+static GSList *hw_dev_list(void)
+{
+       struct drv_context *drvc;
+
+       drvc = odi->priv;
+
+       return drvc->instances;
+}
+
 static int hw_dev_open(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
@@ -1082,6 +1091,8 @@ SR_PRIV struct sr_dev_driver ols_driver_info = {
        .init = hw_init,
        .cleanup = hw_cleanup,
        .scan = hw_scan,
+       .dev_list = hw_dev_list,
+       .dev_clear = hw_cleanup,
        .dev_open = hw_dev_open,
        .dev_close = hw_dev_close,
        .info_get = hw_info_get,
index 72e044bca5e64247c90ec61b139b9ea6e3afa8ae..7f6196a80a8ee35dce602c41554b3cc482cb5b77 100644 (file)
@@ -226,7 +226,7 @@ static int configure_probes(const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static void clear_instances(void)
+static int clear_instances(void)
 {
        GSList *l;
        struct sr_dev_inst *sdi;
@@ -250,6 +250,7 @@ static void clear_instances(void)
        g_slist_free(drvc->instances);
        drvc->instances = NULL;
 
+       return SR_OK;
 }
 
 /*
@@ -354,6 +355,15 @@ static GSList *hw_scan(GSList *options)
        return devices;
 }
 
+static GSList *hw_dev_list(void)
+{
+       struct drv_context *drvc;
+
+       drvc = zdi->priv;
+
+       return drvc->instances;
+}
+
 static int hw_dev_open(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
@@ -687,6 +697,8 @@ SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info = {
        .init = hw_init,
        .cleanup = hw_cleanup,
        .scan = hw_scan,
+       .dev_list = hw_dev_list,
+       .dev_clear = hw_cleanup,
        .dev_open = hw_dev_open,
        .dev_close = hw_dev_close,
        .info_get = hw_info_get,
index 75f6c3c26b6a362b77c1a452aa5c15afbfd5ca63..728a63f5051b04903009a30b33d8a1df484da423 100644 (file)
@@ -482,6 +482,8 @@ struct sr_dev_driver {
        int (*init) (void);
        int (*cleanup) (void);
        GSList *(*scan) (GSList *options);
+       GSList *(*dev_list) (void);
+       int (*dev_clear) (void);
 
        /* Device-specific */
        int (*dev_open) (struct sr_dev_inst *sdi);
diff --git a/proto.h b/proto.h
index ce61d009483fcbcc3d3073c377433ec8c67c0106..6536c5a4b075b490177acdaa2a4be76f5f7eaa7c 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -56,6 +56,8 @@ SR_API int sr_dev_trigger_set(const struct sr_dev_inst *sdi, int probenum,
 SR_API gboolean sr_dev_has_hwcap(const struct sr_dev_inst *sdi, int hwcap);
 SR_API int sr_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
                const void *value);
+SR_API GSList *sr_dev_inst_list(const struct sr_dev_driver *driver);
+SR_API int sr_dev_inst_clear(const struct sr_dev_driver *driver);
 
 /*--- filter.c --------------------------------------------------------------*/