sr: No need for dynamic hardware driver registration.

We don't need or allow run-time registration of hardware
drivers/plugins, they're added at compile-time.
This commit is contained in:
Uwe Hermann 2012-02-22 21:48:30 +01:00
parent 47671b0f26
commit 050e9219d6
5 changed files with 36 additions and 47 deletions

View File

@ -28,7 +28,7 @@
*/ */
SR_API int sr_init(void) SR_API int sr_init(void)
{ {
return sr_hw_load_all(); return SR_OK;
} }
/** /**

View File

@ -59,10 +59,11 @@ static GSList *devs = NULL;
*/ */
SR_API int sr_dev_scan(void) SR_API int sr_dev_scan(void)
{ {
GSList *plugins, *l; int i;
struct sr_dev_plugin *plugin; 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__); sr_err("dev: %s: no supported devices/hwplugins", __func__);
return SR_ERR; /* TODO: More specific error? */ 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 * a firmware upload and associated delay, we may as well get all
* of these out of the way first. * of these out of the way first.
*/ */
for (l = plugins; l; l = l->next) { for (i = 0; plugins[i]; i++)
plugin = l->data; sr_hw_init(plugins[i]);
/* TODO: Handle 'plugin' being NULL. */
sr_hw_init(plugin);
}
return SR_OK; return SR_OK;
} }

View File

@ -26,9 +26,6 @@
#include "sigrok.h" #include "sigrok.h"
#include "sigrok-internal.h" #include "sigrok-internal.h"
/* The list of loaded plugins lives here. */
static GSList *plugins;
/* /*
* This enumerates which plugin capabilities correspond to user-settable * This enumerates which plugin capabilities correspond to user-settable
* options. * options.
@ -43,62 +40,57 @@ SR_API struct sr_hwcap_option sr_hwcap_options[] = {
}; };
#ifdef HAVE_LA_DEMO #ifdef HAVE_LA_DEMO
extern struct sr_dev_plugin demo_plugin_info; extern SR_PRIV struct sr_dev_plugin demo_plugin_info;
#endif #endif
#ifdef HAVE_LA_SALEAE_LOGIC #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 #endif
#ifdef HAVE_LA_OLS #ifdef HAVE_LA_OLS
extern struct sr_dev_plugin ols_plugin_info; extern SR_PRIV struct sr_dev_plugin ols_plugin_info;
#endif #endif
#ifdef HAVE_LA_ZEROPLUS_LOGIC_CUBE #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 #endif
#ifdef HAVE_LA_ASIX_SIGMA #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 #endif
#ifdef HAVE_LA_CHRONOVU_LA8 #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 #endif
#ifdef HAVE_LA_LINK_MSO19 #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 #endif
#ifdef HAVE_LA_ALSA #ifdef HAVE_LA_ALSA
extern struct sr_dev_plugin alsa_plugin_info; extern SR_PRIV struct sr_dev_plugin alsa_plugin_info;
#endif #endif
/* TODO: No linked list needed, this can be a simple array. */ static struct sr_dev_plugin *plugins_list[] = {
SR_PRIV int sr_hw_load_all(void)
{
#ifdef HAVE_LA_DEMO #ifdef HAVE_LA_DEMO
plugins = g_slist_append(plugins, (gpointer *)&demo_plugin_info); &demo_plugin_info,
#endif #endif
#ifdef HAVE_LA_SALEAE_LOGIC #ifdef HAVE_LA_SALEAE_LOGIC
plugins = &saleae_logic_plugin_info,
g_slist_append(plugins, (gpointer *)&saleae_logic_plugin_info);
#endif #endif
#ifdef HAVE_LA_OLS #ifdef HAVE_LA_OLS
plugins = g_slist_append(plugins, (gpointer *)&ols_plugin_info); &ols_plugin_info,
#endif #endif
#ifdef HAVE_LA_ZEROPLUS_LOGIC_CUBE #ifdef HAVE_LA_ZEROPLUS_LOGIC_CUBE
plugins = g_slist_append(plugins, &zeroplus_logic_cube_plugin_info,
(gpointer *)&zeroplus_logic_cube_plugin_info);
#endif #endif
#ifdef HAVE_LA_ASIX_SIGMA #ifdef HAVE_LA_ASIX_SIGMA
plugins = g_slist_append(plugins, (gpointer *)&asix_sigma_plugin_info); &asix_sigma_plugin_info,
#endif #endif
#ifdef HAVE_LA_CHRONOVU_LA8 #ifdef HAVE_LA_CHRONOVU_LA8
plugins = g_slist_append(plugins, (gpointer *)&chronovu_la8_plugin_info); &chronovu_la8_plugin_info,
#endif #endif
#ifdef HAVE_LA_LINK_MSO19 #ifdef HAVE_LA_LINK_MSO19
plugins = g_slist_append(plugins, (gpointer *)&link_mso19_plugin_info); &link_mso19_plugin_info,
#endif #endif
#ifdef HAVE_LA_ALSA #ifdef HAVE_LA_ALSA
plugins = g_slist_append(plugins, (gpointer *)&alsa_plugin_info); &alsa_plugin_info,
#endif #endif
NULL,
return SR_OK; };
}
/** /**
* Return the list of loaded hardware plugins. * 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 * The list of plugins is initialized from sr_init(), and can only be reset
* by calling sr_exit(). * 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) SR_PRIV void sr_hw_cleanup_all(void)
{ {
struct sr_dev_plugin *plugin; int i;
GSList *l; struct sr_dev_plugin **plugins;
for (l = plugins; l; l = l->next) { plugins = sr_hw_list();
plugin = l->data; for (i = 0; plugins[i]; i++) {
if (plugin->cleanup) if (plugins[i]->cleanup)
plugin->cleanup(); plugins[i]->cleanup();
} }
} }

View File

@ -76,7 +76,6 @@ SR_PRIV int sr_err(const char *format, ...);
/*--- hwplugin.c ------------------------------------------------------------*/ /*--- hwplugin.c ------------------------------------------------------------*/
SR_PRIV int sr_hw_load_all(void);
SR_PRIV void sr_hw_cleanup_all(void); SR_PRIV void sr_hw_cleanup_all(void);
/*--- session.c -------------------------------------------------------------*/ /*--- session.c -------------------------------------------------------------*/

View File

@ -71,7 +71,7 @@ SR_API int sr_filter_probes(int in_unitsize, int out_unitsize,
/*--- hwplugin.c ------------------------------------------------------------*/ /*--- 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 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 gboolean sr_hw_has_hwcap(struct sr_dev_plugin *plugin, int hwcap);
SR_API struct sr_hwcap_option *sr_hw_hwcap_get(int hwcap); SR_API struct sr_hwcap_option *sr_hw_hwcap_get(int hwcap);