Skip to contentSkip to conversation

Adding priority check for plugins.

PATCH In review alok barsode 2 participants 8 messages Apr 20, 2009 – Apr 21, 2009 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Adding priority check for plugins.

Hi Marcel,

Adding priority field for plugins.
Let me know if anything needs modifications.

Cheers,
Alok.

From de02d49db85b7cab49fb920d21da3c1109250510 Mon Sep 17 00:00:00 2001
From: Alok Barsode <[email protected]>
Date: Mon, 20 Apr 2009 20:40:10 +0530
Subject: [PATCH] Add priority field to plugin descriptor definition and
load plugins in priority order.

---
 audio/main.c      |    2 +-
 input/main.c      |    2 +-
 network/main.c    |    2 +-
 plugins/echo.c    |    2 +-
 plugins/hal.c     |    2 +-
 plugins/netlink.c |    2 +-
 plugins/service.c |    2 +-
 plugins/storage.c |    2 +-
 serial/main.c     |    2 +-
 src/plugin.c      |   29 ++++++++++++++++++++++-------
 src/plugin.h      |    8 ++++++--
 11 files changed, 37 insertions(+), 18 deletions(-)
audio/main.c +1 -1
index 565c83b..c481b69 100644
@@ -176,4 +176,4 @@ static void audio_exit(void)
 	dbus_connection_unref(connection);
 }
 
-BLUETOOTH_PLUGIN_DEFINE("audio", VERSION, audio_init, audio_exit)
+BLUETOOTH_PLUGIN_DEFINE("audio", VERSION, PLUGIN_PRIORITY_DEFAULT, audio_init, audio_exit)
input/main.c +1 -1
index 010b731..51ded43 100644
@@ -82,4 +82,4 @@ static void input_exit(void)
 	dbus_connection_unref(connection);
 }
 
-BLUETOOTH_PLUGIN_DEFINE("input", VERSION, input_init, input_exit)
+BLUETOOTH_PLUGIN_DEFINE("input", VERSION, PLUGIN_PRIORITY_DEFAULT, input_init, input_exit)
network/main.c +1 -1
index 5f96d4b..5074f4e 100644
@@ -55,4 +55,4 @@ static void network_exit(void)
 	dbus_connection_unref(connection);
 }
 
-BLUETOOTH_PLUGIN_DEFINE("network", VERSION, network_init, network_exit)
+BLUETOOTH_PLUGIN_DEFINE("network", VERSION, PLUGIN_PRIORITY_DEFAULT, network_init, network_exit)
plugins/echo.c +1 -1
index 832bf8b..6f918e8 100644
@@ -163,4 +163,4 @@ 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, PLUGIN_PRIORITY_DEFAULT, echo_init, echo_exit)
plugins/hal.c +1 -1
index 219b46e..f2d3083 100644
@@ -158,4 +158,4 @@ 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, PLUGIN_PRIORITY_DEFAULT, hal_init, hal_exit)
plugins/netlink.c +1 -1
index f777cf9..c50dd77 100644
@@ -123,4 +123,4 @@ static void netlink_exit(void)
 	nl_handle_destroy(handle);
 }
 
-BLUETOOTH_PLUGIN_DEFINE("netlink", VERSION, netlink_init, netlink_exit)
+BLUETOOTH_PLUGIN_DEFINE("netlink", VERSION, PLUGIN_PRIORITY_DEFAULT, netlink_init, netlink_exit)
plugins/service.c +1 -1
index b28c9c1..5bca625 100644
@@ -859,4 +859,4 @@ static void service_exit(void)
 	dbus_connection_unref(connection);
 }
 
-BLUETOOTH_PLUGIN_DEFINE("service", VERSION, service_init, service_exit)
+BLUETOOTH_PLUGIN_DEFINE("service", VERSION, PLUGIN_PRIORITY_DEFAULT, service_init, service_exit)
plugins/storage.c +1 -1
index c4dbe16..3e79b8a 100644
@@ -39,4 +39,4 @@ static void storage_exit(void)
 {
 }
 
-BLUETOOTH_PLUGIN_DEFINE("storage", VERSION, storage_init, storage_exit)
+BLUETOOTH_PLUGIN_DEFINE("storage", VERSION, PLUGIN_PRIORITY_DEFAULT, storage_init, storage_exit)
serial/main.c +1 -1
index 5db389c..509cc38 100644
@@ -55,4 +55,4 @@ static void serial_exit(void)
 	dbus_connection_unref(connection);
 }
 
-BLUETOOTH_PLUGIN_DEFINE("serial", VERSION, serial_init, serial_exit)
+BLUETOOTH_PLUGIN_DEFINE("serial", VERSION, PLUGIN_PRIORITY_DEFAULT, serial_init, serial_exit)
src/plugin.c +22 -7
index 051c33c..a17a7ea 100644
@@ -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);
src/plugin.h +6 -2
index 62d5f75..2cd50f7 100644
@@ -20,17 +20,21 @@
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
+#define PLUGIN_PRIORITY_LOW      -100
+#define PLUGIN_PRIORITY_DEFAULT     0
+#define 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 \
 		};
Signature · 1 line
1.5.6.3
maintainer
#1 lore raw

Hi Alok,

Quoted 2 lines

Adding priority field for plugins.
Let me know if anything needs modifications.

please call it BLUETOOTH_PLUGIN_PRIORITY_* and break the plugin define lines properly.

Regards

Marcel

#2 lore raw

Marcel,

modified patch attached.

Cheers,
Alok.

Quoted 5 lines · Marcel Holtmann

Hi Alok,

Quoted 2 lines

Adding priority field for plugins.
Let me know if anything needs modifications.

Quoted 9 lines

please call it BLUETOOTH_PLUGIN_PRIORITY_* and break the plugin define lines properly.

Regards

Marcel

From 0ac51fa00ceb3e0aaf55c309da12a3b2c98f0480 Mon Sep 17 00:00:00 2001
From: Alok Barsode <[email protected]>
Date: Mon, 20 Apr 2009 21:18:21 +0530
Subject: [PATCH] Add priority field to plugin descriptor definition and
load plugins in priority order.

---
 audio/main.c      |    2 +-
 input/main.c      |    2 +-
 network/main.c    |    2 +-
 plugins/echo.c    |    2 +-
 plugins/hal.c     |    2 +-
 plugins/netlink.c |    2 +-
 plugins/service.c |    2 +-
 plugins/storage.c |    2 +-
 serial/main.c     |    2 +-
 src/plugin.c      |   29 ++++++++++++++++++++++-------
 src/plugin.h      |    8 ++++++--
 11 files changed, 37 insertions(+), 18 deletions(-)
audio/main.c +1 -1
index 565c83b..7cda44a 100644
@@ -176,4 +176,4 @@ 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)
input/main.c +1 -1
index 010b731..7c58228 100644
@@ -82,4 +82,4 @@ 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)
network/main.c +1 -1
index 5f96d4b..40d5654 100644
@@ -55,4 +55,4 @@ 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)
plugins/echo.c +1 -1
index 832bf8b..c804975 100644
@@ -163,4 +163,4 @@ 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)
plugins/hal.c +1 -1
index 219b46e..31e267f 100644
@@ -158,4 +158,4 @@ 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)
plugins/netlink.c +1 -1
index f777cf9..5b3bb85 100644
@@ -123,4 +123,4 @@ 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)
plugins/service.c +1 -1
index b28c9c1..b228cb6 100644
@@ -859,4 +859,4 @@ 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)
plugins/storage.c +1 -1
index c4dbe16..fba39ec 100644
@@ -39,4 +39,4 @@ 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)
serial/main.c +1 -1
index 5db389c..c74973e 100644
@@ -55,4 +55,4 @@ 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)
src/plugin.c +22 -7
index 051c33c..a17a7ea 100644
@@ -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);
src/plugin.h +6 -2
index 62d5f75..dc37224 100644
@@ -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 \
 		};
Signature · 1 line
1.5.6.3
maintainer
#3 lore raw

Hi Alok,

Quoted 1 line

modified patch attached.

please to the line-break with BLUETOOTH_PLUGIN_DEFINE a little bit more like what ConnMan does so it looks nicer.

Regards

Marcel

#4 lore raw

Hi Marcel,

Quoted 7 lines · Marcel Holtmann

Hi Alok,

Quoted 1 line

modified patch attached.

please to the line-break with BLUETOOTH_PLUGIN_DEFINE a little bit more like what ConnMan does so it looks nicer.

Infact i copied the syntax for BLUETOOTH_PLUGIN_DEFINE from the one in connman. :D

#define CONNMAN_PLUGIN_DEFINE(name, description, version, priority, init, exit) \
extern struct connman_plugin_desc connman_plugin_desc

\
                                __attribute__
((visibility("default"))); \
                struct connman_plugin_desc connman_plugin_desc = { \
                        #name, description, version, priority, 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, priority, init, exit \
                };
Quoted 6 lines

Regards

Marcel

Cheers,
Alok.

maintainer
#5 lore raw

Hi Alok,

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

modified patch attached.

please to the line-break with BLUETOOTH_PLUGIN_DEFINE a little bit more like what ConnMan does so it looks nicer.

Infact i copied the syntax for BLUETOOTH_PLUGIN_DEFINE from the one in connman. :D

I meant the calls inside the plugins and not the definition itself.

Regards

Marcel

#6 lore raw

Hi Marcel,

Modified patch attached.

Quoted 7 lines · Marcel Holtmann

Hi Alok,

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

modified patch attached.

please to the line-break with BLUETOOTH_PLUGIN_DEFINE a little bit more like what ConnMan does so it looks nicer.

Quoted 11 lines
Quoted 2 lines

Infact i copied the syntax for BLUETOOTH_PLUGIN_DEFINE from the one in connman. :D

I meant the calls inside the plugins and not the definition itself.

Regards

Marcel

From a8c47dd5df16a0aa1eb76edea3254a5711c83327 Mon Sep 17 00:00:00 2001
From: Alok Barsode <[email protected]>
Date: Tue, 21 Apr 2009 16:33:36 +0530
Subject: [PATCH] Add priority field to plugin descriptor definition and
load plugins in priority order.

---
 audio/main.c      |    3 ++-
 input/main.c      |    3 ++-
 network/main.c    |    3 ++-
 plugins/echo.c    |    3 ++-
 plugins/hal.c     |    3 ++-
 plugins/netlink.c |    3 ++-
 plugins/service.c |    3 ++-
 plugins/storage.c |    3 ++-
 serial/main.c     |    3 ++-
 src/plugin.c      |   29 ++++++++++++++++++++++-------
 src/plugin.h      |    8 ++++++--
 11 files changed, 46 insertions(+), 18 deletions(-)
audio/main.c +2 -1
index 565c83b..761392a 100644
@@ -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)
input/main.c +2 -1
index 010b731..2834201 100644
@@ -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)
network/main.c +2 -1
index 5f96d4b..7e45eba 100644
@@ -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)
plugins/echo.c +2 -1
index 832bf8b..4443ff1 100644
@@ -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)
plugins/hal.c +2 -1
index 219b46e..683777c 100644
@@ -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)
plugins/netlink.c +2 -1
index f777cf9..d1e91b2 100644
@@ -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)
plugins/service.c +2 -1
index b28c9c1..d81abe8 100644
@@ -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)
plugins/storage.c +2 -1
index c4dbe16..0abc616 100644
@@ -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)
serial/main.c +2 -1
index 5db389c..3949271 100644
@@ -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)
src/plugin.c +22 -7
index 051c33c..a17a7ea 100644
@@ -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);
src/plugin.h +6 -2
index 62d5f75..dc37224 100644
@@ -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 \
 		};
Signature · 1 line
1.5.6.3
maintainer
#7 lore raw

Hi Alok,

no top posting. Ever.

Quoted 1 line

Modified patch attached.

Patch has been applied, but keep in mind that the 80 column rule is a actually strict one.

Regards

Marcel