Add priority field to plugin descriptor definition and load plugins in priority order.

This commit is contained in:
Alok Barsode 2009-04-21 16:33:36 +05:30 committed by Marcel Holtmann
parent 49d0b05136
commit 2f28c39a63
11 changed files with 46 additions and 18 deletions

View File

@ -176,4 +176,5 @@ static void audio_exit(void)
dbus_connection_unref(connection);
}
BLUETOOTH_PLUGIN_DEFINE("audio", VERSION, audio_init, audio_exit)
BLUETOOTH_PLUGIN_DEFINE("audio", VERSION,
BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, audio_init, audio_exit)

View File

@ -82,4 +82,5 @@ static void input_exit(void)
dbus_connection_unref(connection);
}
BLUETOOTH_PLUGIN_DEFINE("input", VERSION, input_init, input_exit)
BLUETOOTH_PLUGIN_DEFINE("input", VERSION,
BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, input_init, input_exit)

View File

@ -55,4 +55,5 @@ static void network_exit(void)
dbus_connection_unref(connection);
}
BLUETOOTH_PLUGIN_DEFINE("network", VERSION, network_init, network_exit)
BLUETOOTH_PLUGIN_DEFINE("network", VERSION,
BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, network_init, network_exit)

View File

@ -163,4 +163,5 @@ static void echo_exit(void)
btd_unregister_adapter_driver(&echo_server);
}
BLUETOOTH_PLUGIN_DEFINE("echo", VERSION, echo_init, echo_exit)
BLUETOOTH_PLUGIN_DEFINE("echo", VERSION,
BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, echo_init, echo_exit)

View File

@ -158,4 +158,5 @@ static void hal_exit(void)
btd_unregister_adapter_driver(&hal_driver);
}
BLUETOOTH_PLUGIN_DEFINE("hal", VERSION, hal_init, hal_exit)
BLUETOOTH_PLUGIN_DEFINE("hal", VERSION,
BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, hal_init, hal_exit)

View File

@ -123,4 +123,5 @@ static void netlink_exit(void)
nl_handle_destroy(handle);
}
BLUETOOTH_PLUGIN_DEFINE("netlink", VERSION, netlink_init, netlink_exit)
BLUETOOTH_PLUGIN_DEFINE("netlink", VERSION,
BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, netlink_init, netlink_exit)

View File

@ -859,4 +859,5 @@ static void service_exit(void)
dbus_connection_unref(connection);
}
BLUETOOTH_PLUGIN_DEFINE("service", VERSION, service_init, service_exit)
BLUETOOTH_PLUGIN_DEFINE("service", VERSION,
BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, service_init, service_exit)

View File

@ -39,4 +39,5 @@ static void storage_exit(void)
{
}
BLUETOOTH_PLUGIN_DEFINE("storage", VERSION, storage_init, storage_exit)
BLUETOOTH_PLUGIN_DEFINE("storage", VERSION,
BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, storage_init, storage_exit)

View File

@ -55,4 +55,5 @@ static void serial_exit(void)
dbus_connection_unref(connection);
}
BLUETOOTH_PLUGIN_DEFINE("serial", VERSION, serial_init, serial_exit)
BLUETOOTH_PLUGIN_DEFINE("serial", VERSION,
BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, serial_init, serial_exit)

View File

@ -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);

View File

@ -20,17 +20,21 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#define BLUETOOTH_PLUGIN_PRIORITY_LOW -100
#define BLUETOOTH_PLUGIN_PRIORITY_DEFAULT 0
#define BLUETOOTH_PLUGIN_PRIORITY_HIGH 100
struct bluetooth_plugin_desc {
const char *name;
const char *version;
int priority;
int (*init) (void);
void (*exit) (void);
};
#define BLUETOOTH_PLUGIN_DEFINE(name,version,init,exit) \
#define BLUETOOTH_PLUGIN_DEFINE(name, version, priority, init, exit) \
extern struct bluetooth_plugin_desc bluetooth_plugin_desc \
__attribute__ ((visibility("default"))); \
struct bluetooth_plugin_desc bluetooth_plugin_desc = { \
name, version, init, exit \
name, version, priority, init, exit \
};