]> sigrok.org Git - libsigrok.git/commitdiff
sr: No need for dynamic hardware driver registration.
authorUwe Hermann <redacted>
Wed, 22 Feb 2012 20:48:30 +0000 (21:48 +0100)
committerUwe Hermann <redacted>
Wed, 22 Feb 2012 23:28:20 +0000 (00:28 +0100)
We don't need or allow run-time registration of hardware
drivers/plugins, they're added at compile-time.

backend.c
device.c
hwplugin.c
sigrok-internal.h
sigrok-proto.h

index b60bce8b6f558c2355499a755faafaddddb19e04..e67f48247af5192e942c0b26806824a190e5baf4 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -28,7 +28,7 @@
  */
 SR_API int sr_init(void)
 {
-       return sr_hw_load_all();
+       return SR_OK;
 }
 
 /**
index 9cc3b6800691b4debd76555b8b572bb1d20486b7..eb2e2b4cb2c02b392c8f02f31095ca027128a9de 100644 (file)
--- a/device.c
+++ b/device.c
@@ -59,10 +59,11 @@ static GSList *devs = NULL;
  */
 SR_API int sr_dev_scan(void)
 {
-       GSList *plugins, *l;
-       struct sr_dev_plugin *plugin;
+       int i;
+       struct sr_dev_plugin **plugins;
 
-       if (!(plugins = sr_hw_list())) {
+       plugins = sr_hw_list();
+       if (!plugins[0]) {
                sr_err("dev: %s: no supported devices/hwplugins", __func__);
                return SR_ERR; /* TODO: More specific error? */
        }
@@ -72,11 +73,8 @@ SR_API int sr_dev_scan(void)
         * a firmware upload and associated delay, we may as well get all
         * of these out of the way first.
         */
-       for (l = plugins; l; l = l->next) {
-               plugin = l->data;
-               /* TODO: Handle 'plugin' being NULL. */
-               sr_hw_init(plugin);
-       }
+       for (i = 0; plugins[i]; i++)
+               sr_hw_init(plugins[i]);
 
        return SR_OK;
 }
index b924f0d65c3547871634fb0d61c3bf7ec19908f3..37d98e5dfca11901ad732ac6a6819f4c8bc442b6 100644 (file)
@@ -26,9 +26,6 @@
 #include "sigrok.h"
 #include "sigrok-internal.h"
 
-/* The list of loaded plugins lives here. */
-static GSList *plugins;
-
 /*
  * This enumerates which plugin capabilities correspond to user-settable
  * options.
@@ -43,62 +40,57 @@ SR_API struct sr_hwcap_option sr_hwcap_options[] = {
 };
 
 #ifdef HAVE_LA_DEMO
-extern struct sr_dev_plugin demo_plugin_info;
+extern SR_PRIV struct sr_dev_plugin demo_plugin_info;
 #endif
 #ifdef HAVE_LA_SALEAE_LOGIC
-extern struct sr_dev_plugin saleae_logic_plugin_info;
+extern SR_PRIV struct sr_dev_plugin saleae_logic_plugin_info;
 #endif
 #ifdef HAVE_LA_OLS
-extern struct sr_dev_plugin ols_plugin_info;
+extern SR_PRIV struct sr_dev_plugin ols_plugin_info;
 #endif
 #ifdef HAVE_LA_ZEROPLUS_LOGIC_CUBE
-extern struct sr_dev_plugin zeroplus_logic_cube_plugin_info;
+extern SR_PRIV struct sr_dev_plugin zeroplus_logic_cube_plugin_info;
 #endif
 #ifdef HAVE_LA_ASIX_SIGMA
-extern struct sr_dev_plugin asix_sigma_plugin_info;
+extern SR_PRIV struct sr_dev_plugin asix_sigma_plugin_info;
 #endif
 #ifdef HAVE_LA_CHRONOVU_LA8
-extern SR_PRIV struct dev_plugin chronovu_la8_plugin_info;
+extern SR_PRIV struct sr_dev_plugin chronovu_la8_plugin_info;
 #endif
 #ifdef HAVE_LA_LINK_MSO19
-extern struct sr_dev_plugin link_mso19_plugin_info;
+extern SR_PRIV struct sr_dev_plugin link_mso19_plugin_info;
 #endif
 #ifdef HAVE_LA_ALSA
-extern struct sr_dev_plugin alsa_plugin_info;
+extern SR_PRIV struct sr_dev_plugin alsa_plugin_info;
 #endif
 
-/* TODO: No linked list needed, this can be a simple array. */
-SR_PRIV int sr_hw_load_all(void)
-{
+static struct sr_dev_plugin *plugins_list[] = {
 #ifdef HAVE_LA_DEMO
-       plugins = g_slist_append(plugins, (gpointer *)&demo_plugin_info);
+       &demo_plugin_info,
 #endif
 #ifdef HAVE_LA_SALEAE_LOGIC
-       plugins =
-           g_slist_append(plugins, (gpointer *)&saleae_logic_plugin_info);
+       &saleae_logic_plugin_info,
 #endif
 #ifdef HAVE_LA_OLS
-       plugins = g_slist_append(plugins, (gpointer *)&ols_plugin_info);
+       &ols_plugin_info,
 #endif
 #ifdef HAVE_LA_ZEROPLUS_LOGIC_CUBE
-       plugins = g_slist_append(plugins,
-                          (gpointer *)&zeroplus_logic_cube_plugin_info);
+       &zeroplus_logic_cube_plugin_info,
 #endif
 #ifdef HAVE_LA_ASIX_SIGMA
-       plugins = g_slist_append(plugins, (gpointer *)&asix_sigma_plugin_info);
+       &asix_sigma_plugin_info,
 #endif
 #ifdef HAVE_LA_CHRONOVU_LA8
-       plugins = g_slist_append(plugins, (gpointer *)&chronovu_la8_plugin_info);
+       &chronovu_la8_plugin_info,
 #endif
 #ifdef HAVE_LA_LINK_MSO19
-       plugins = g_slist_append(plugins, (gpointer *)&link_mso19_plugin_info);
+       &link_mso19_plugin_info,
 #endif
 #ifdef HAVE_LA_ALSA
-       plugins = g_slist_append(plugins, (gpointer *)&alsa_plugin_info);
+       &alsa_plugin_info,
 #endif
-
-       return SR_OK;
-}
+       NULL,
+};
 
 /**
  * Return the list of loaded hardware plugins.
@@ -106,11 +98,11 @@ SR_PRIV int sr_hw_load_all(void)
  * The list of plugins is initialized from sr_init(), and can only be reset
  * by calling sr_exit().
  *
- * @return A GSList of pointers to loaded plugins.
+ * @return Pointer to the NULL-terminated list of hardware plugin pointers.
  */
-SR_API GSList *sr_hw_list(void)
+SR_API struct sr_dev_plugin **sr_hw_list(void)
 {
-       return plugins;
+       return plugins_list;
 }
 
 /**
@@ -155,13 +147,13 @@ SR_API int sr_hw_init(struct sr_dev_plugin *plugin)
 
 SR_PRIV void sr_hw_cleanup_all(void)
 {
-       struct sr_dev_plugin *plugin;
-       GSList *l;
+       int i;
+       struct sr_dev_plugin **plugins;
 
-       for (l = plugins; l; l = l->next) {
-               plugin = l->data;
-               if (plugin->cleanup)
-                       plugin->cleanup();
+       plugins = sr_hw_list();
+       for (i = 0; plugins[i]; i++) {
+               if (plugins[i]->cleanup)
+                       plugins[i]->cleanup();
        }
 }
 
index 1a297f9988a2ceccd546943881fbecb58fee513a..f0032e98622902858e7dd7693efc983379fdc837 100644 (file)
@@ -76,7 +76,6 @@ SR_PRIV int sr_err(const char *format, ...);
 
 /*--- hwplugin.c ------------------------------------------------------------*/
 
-SR_PRIV int sr_hw_load_all(void);
 SR_PRIV void sr_hw_cleanup_all(void);
 
 /*--- session.c -------------------------------------------------------------*/
index 4c96d30d24e840b3a7382ffb990957f7e5e37506..d5f1c0cd51a07028040354984245dcf436f5cd83 100644 (file)
@@ -71,7 +71,7 @@ SR_API int sr_filter_probes(int in_unitsize, int out_unitsize,
 
 /*--- hwplugin.c ------------------------------------------------------------*/
 
-SR_API GSList *sr_hw_list(void);
+SR_API struct sr_dev_plugin **sr_hw_list(void);
 SR_API int sr_hw_init(struct sr_dev_plugin *plugin);
 SR_API gboolean sr_hw_has_hwcap(struct sr_dev_plugin *plugin, int hwcap);
 SR_API struct sr_hwcap_option *sr_hw_hwcap_get(int hwcap);