From: Bert Vermeulen Date: Mon, 24 Jan 2011 01:49:14 +0000 (+0100) Subject: cli: don't initialize and scan for hardware unless needed X-Git-Tag: libsigrok-0.1.0~375 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e54bcdc5d17daf9a0641763bc33f5c8a723c4cbb;p=libsigrok.git cli: don't initialize and scan for hardware unless needed If the -d option is used, only initialize the specified plugin. --- diff --git a/device.c b/device.c index 84cf6d1f..ff1e6e3a 100644 --- 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; } diff --git a/sigrok-proto.h b/sigrok-proto.h index 1abdadd8..ec80e404 100644 --- a/sigrok-proto.h +++ b/sigrok-proto.h @@ -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,