public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: alok barsode <alokbarsode@gmail.com>
To: Marcel Holtmann <marcel@holtmann.org>
Cc: linux-bluetooth <linux-bluetooth@vger.kernel.org>
Subject: Re: [PATCH] Adding priority check for plugins.
Date: Mon, 20 Apr 2009 21:22:11 +0530	[thread overview]
Message-ID: <8b5debfa0904200852o7ba92880u15e950bf655eb81d@mail.gmail.com> (raw)
In-Reply-To: <1240241475.5260.4.camel@localhost.localdomain>

[-- Attachment #1: Type: text/plain, Size: 349 bytes --]

Marcel,

modified patch attached.

Cheers,
Alok.

On Mon, Apr 20, 2009 at 9:01 PM, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Alok,
>
>> 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
>
>
>

[-- Attachment #2: 0001-Add-priority-field-to-plugin-descriptor-definition-a.patch --]
[-- Type: text/x-diff, Size: 6761 bytes --]

From 0ac51fa00ceb3e0aaf55c309da12a3b2c98f0480 Mon Sep 17 00:00:00 2001
From: Alok Barsode <alok.barsode@azingo.com>
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(-)

diff --git a/audio/main.c b/audio/main.c
index 565c83b..7cda44a 100644
--- a/audio/main.c
+++ b/audio/main.c
@@ -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)
diff --git a/input/main.c b/input/main.c
index 010b731..7c58228 100644
--- a/input/main.c
+++ b/input/main.c
@@ -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)
diff --git a/network/main.c b/network/main.c
index 5f96d4b..40d5654 100644
--- a/network/main.c
+++ b/network/main.c
@@ -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)
diff --git a/plugins/echo.c b/plugins/echo.c
index 832bf8b..c804975 100644
--- a/plugins/echo.c
+++ b/plugins/echo.c
@@ -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)
diff --git a/plugins/hal.c b/plugins/hal.c
index 219b46e..31e267f 100644
--- a/plugins/hal.c
+++ b/plugins/hal.c
@@ -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)
diff --git a/plugins/netlink.c b/plugins/netlink.c
index f777cf9..5b3bb85 100644
--- a/plugins/netlink.c
+++ b/plugins/netlink.c
@@ -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)
diff --git a/plugins/service.c b/plugins/service.c
index b28c9c1..b228cb6 100644
--- a/plugins/service.c
+++ b/plugins/service.c
@@ -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)
diff --git a/plugins/storage.c b/plugins/storage.c
index c4dbe16..fba39ec 100644
--- a/plugins/storage.c
+++ b/plugins/storage.c
@@ -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)
diff --git a/serial/main.c b/serial/main.c
index 5db389c..c74973e 100644
--- a/serial/main.c
+++ b/serial/main.c
@@ -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)
diff --git a/src/plugin.c b/src/plugin.c
index 051c33c..a17a7ea 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);
diff --git a/src/plugin.h b/src/plugin.h
index 62d5f75..dc37224 100644
--- a/src/plugin.h
+++ b/src/plugin.h
@@ -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 \
 		};
-- 
1.5.6.3


  reply	other threads:[~2009-04-20 15:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-20 15:19 [PATCH] Adding priority check for plugins alok barsode
2009-04-20 15:31 ` Marcel Holtmann
2009-04-20 15:52   ` alok barsode [this message]
2009-04-20 16:28     ` Marcel Holtmann
2009-04-20 19:18       ` alok barsode
2009-04-21 10:41         ` Marcel Holtmann
2009-04-21 11:41           ` alok barsode
2009-04-21 12:25             ` Marcel Holtmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8b5debfa0904200852o7ba92880u15e950bf655eb81d@mail.gmail.com \
    --to=alokbarsode@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=marcel@holtmann.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox