]> sigrok.org Git - libsigrok.git/commitdiff
cli: don't initialize and scan for hardware unless needed
authorBert Vermeulen <redacted>
Mon, 24 Jan 2011 01:49:14 +0000 (02:49 +0100)
committerBert Vermeulen <redacted>
Mon, 24 Jan 2011 01:49:14 +0000 (02:49 +0100)
If the -d <plugin> option is used, only initialize the specified plugin.

device.c
sigrok-proto.h

index 84cf6d1f87c48c8cfd96d839c5e9a55cb6f5a009..ff1e6e3a75154ffd1ff08545d686a9dbfb8588c7 100644 (file)
--- a/device.c
+++ b/device.c
@@ -29,7 +29,6 @@ void device_scan(void)
 {
        GSList *plugins, *l;
        struct device_plugin *plugin;
-       int num_devices, num_probes, i;
 
        plugins = list_hwplugins();
 
@@ -40,15 +39,23 @@ void device_scan(void)
         */
        for (l = plugins; l; l = l->next) {
                plugin = l->data;
-               g_message("initializing %s plugin", plugin->name);
-               num_devices = plugin->init(NULL);
-               for (i = 0; i < num_devices; i++) {
-                       num_probes
-                         = (int)(unsigned long)plugin->get_device_info(i,
-                           DI_NUM_PROBES);
-                       device_new(plugin, i, num_probes);
-               }
+               device_plugin_init(plugin);
+       }
+
+}
+
+int device_plugin_init(struct device_plugin *plugin)
+{
+       int num_devices, num_probes, i;
+
+       g_message("initializing %s plugin", plugin->name);
+       num_devices = plugin->init(NULL);
+       for (i = 0; i < num_devices; i++) {
+               num_probes = (int)plugin->get_device_info(i, DI_NUM_PROBES);
+               device_new(plugin, i, num_probes);
        }
+
+       return num_devices;
 }
 
 void device_close_all(void)
@@ -65,6 +72,10 @@ void device_close_all(void)
 
 GSList *device_list(void)
 {
+
+       if (!devices)
+               device_scan();
+
        return devices;
 }
 
index 1abdadd831482d90310cfa9a7b411a7426d90803..ec80e404853ed51e05a5f0053ef38fd58de1b9b2 100644 (file)
@@ -35,6 +35,7 @@ void datastore_put(struct datastore *ds, void *data, unsigned int length,
 /*--- device.c --------------------------------------------------------------*/
 
 void device_scan(void);
+int device_plugin_init(struct device_plugin *plugin);
 void device_close_all(void);
 GSList *device_list(void);
 struct device *device_new(struct device_plugin *plugin, int plugin_index,