summaryrefslogtreecommitdiff
path: root/src/plugin.c
diff options
context:
space:
mode:
authorAlok Barsode <alok.barsode@azingo.com>2009-04-21 16:33:36 +0530
committerMarcel Holtmann <marcel@holtmann.org>2009-04-21 13:23:51 +0100
commit2f28c39a63e19e41598af8088c5677859364bc04 (patch)
tree383f3e4ee4a5d721585be1d48ad829b707ff35db /src/plugin.c
parent49d0b0513690beec7038ac118ab95988961d7d2d (diff)
downloadbluez-2f28c39a63e19e41598af8088c5677859364bc04.tar.gz
Add priority field to plugin descriptor definition and load plugins in priority order.
Diffstat (limited to 'src/plugin.c')
-rw-r--r--src/plugin.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/plugin.c b/src/plugin.c
index 051c33c03..a17a7eaf6 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -43,9 +43,18 @@ static GSList *plugins = NULL;
struct bluetooth_plugin {
void *handle;
+ gboolean active;
struct bluetooth_plugin_desc *desc;
};
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+ const struct bluetooth_plugin *plugin1 = a;
+ const struct bluetooth_plugin *plugin2 = b;
+
+ return plugin2->desc->priority - plugin1->desc->priority;
+}
+
static gboolean add_plugin(void *handle, struct bluetooth_plugin_desc *desc)
{
struct bluetooth_plugin *plugin;
@@ -63,14 +72,10 @@ static gboolean add_plugin(void *handle, struct bluetooth_plugin_desc *desc)
return FALSE;
plugin->handle = handle;
+ plugin->active = FALSE;
plugin->desc = desc;
- if (desc->init() < 0) {
- g_free(plugin);
- return FALSE;
- }
-
- plugins = g_slist_append(plugins, plugin);
+ plugins = g_slist_insert_sorted(plugins, plugin, compare_priority);
return TRUE;
}
@@ -98,6 +103,7 @@ static gboolean is_disabled(const char *name, char **list)
gboolean plugin_init(GKeyFile *config)
{
+ GSList *list;
GDir *dir;
const gchar *file;
gchar **disabled;
@@ -171,6 +177,15 @@ gboolean plugin_init(GKeyFile *config)
g_strfreev(disabled);
+ for (list = plugins; list; list = list->next) {
+ struct bluetooth_plugin *plugin = list->data;
+
+ if (plugin->desc->init() < 0)
+ continue;
+
+ plugin->active = TRUE;
+ }
+
return TRUE;
}
@@ -183,7 +198,7 @@ void plugin_cleanup(void)
for (list = plugins; list; list = list->next) {
struct bluetooth_plugin *plugin = list->data;
- if (plugin->desc->exit)
+ if (plugin->active == TRUE && plugin->desc->exit)
plugin->desc->exit();
dlclose(plugin->handle);