diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2009-05-03 18:54:22 -0700 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2009-05-03 18:54:22 -0700 |
commit | 1ab388feb37980f1afc940c7cf530b9baadeabb1 (patch) | |
tree | a39892543ea5c738b975b463d6795493029fd1bf /src | |
parent | c369f322aa87e30a025a6e3b6facb1fa77c0c79b (diff) | |
download | bluez-1ab388feb37980f1afc940c7cf530b9baadeabb1.tar.gz |
Add support for builtin plugins
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/plugin.c | 23 | ||||
-rw-r--r-- | src/plugin.h | 7 |
3 files changed, 30 insertions, 3 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index af525773a..9e72bf0f5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,6 +22,7 @@ bluetoothd_SOURCES = main.c security.c hcid.h sdpd.h \ device.h device.c dbus-common.c dbus-common.h dbus-hci.h dbus-hci.c bluetoothd_LDADD = $(top_builddir)/common/libhelper.a \ + $(top_builddir)/plugins/libbuiltin.la \ @GDBUS_LIBS@ @GLIB_LIBS@ @DBUS_LIBS@ @BLUEZ_LIBS@ -ldl bluetoothd_LDFLAGS = -Wl,--export-dynamic @@ -35,7 +36,7 @@ endif AM_CFLAGS = @BLUEZ_CFLAGS@ @DBUS_CFLAGS@ @GLIB_CFLAGS@ @GDBUS_CFLAGS@ \ -DPLUGINDIR=\""$(plugindir)"\" -INCLUDES = -I$(top_srcdir)/common +INCLUDES = -I$(top_srcdir)/common -I$(top_builddir)/plugins if MANPAGES man_MANS = bluetoothd.8 diff --git a/src/plugin.c b/src/plugin.c index a17a7eaf6..a57bf2cbc 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -63,10 +63,12 @@ static gboolean add_plugin(void *handle, struct bluetooth_plugin_desc *desc) return FALSE; if (g_str_equal(desc->version, VERSION) == FALSE) { - DBG("version mismatch for %s", desc->name); + error("Version mismatch for %s", desc->name); return FALSE; } + debug("Loading %s plugin", desc->name); + plugin = g_try_new0(struct bluetooth_plugin, 1); if (plugin == NULL) return FALSE; @@ -88,6 +90,9 @@ static gboolean is_disabled(const char *name, char **list) char *str; gboolean equal; + if (g_str_equal(name, list[i])) + return TRUE; + str = g_strdup_printf("%s.so", list[i]); equal = g_str_equal(str, name); @@ -101,12 +106,15 @@ static gboolean is_disabled(const char *name, char **list) return FALSE; } +#include "builtin.h" + gboolean plugin_init(GKeyFile *config) { GSList *list; GDir *dir; const gchar *file; gchar **disabled; + unsigned int i; if (strlen(PLUGINDIR) == 0) return FALSE; @@ -122,6 +130,16 @@ gboolean plugin_init(GKeyFile *config) else disabled = NULL; + debug("Loading builtin plugins"); + + for (i = 0; __bluetooth_builtin[i]; i++) { + if (disabled && is_disabled(__bluetooth_builtin[i]->name, + disabled)) + continue; + + add_plugin(NULL, __bluetooth_builtin[i]); + } + debug("Loading plugins %s", PLUGINDIR); dir = g_dir_open(PLUGINDIR, 0, NULL); @@ -201,7 +219,8 @@ void plugin_cleanup(void) if (plugin->active == TRUE && plugin->desc->exit) plugin->desc->exit(); - dlclose(plugin->handle); + if (plugin->handle != NULL) + dlclose(plugin->handle); g_free(plugin); } diff --git a/src/plugin.h b/src/plugin.h index d5c5b4963..00e0b3b1e 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -32,9 +32,16 @@ struct bluetooth_plugin_desc { void (*exit) (void); }; +#ifdef BLUETOOTH_PLUGIN_BUILTIN +#define BLUETOOTH_PLUGIN_DEFINE(name, version, priority, init, exit) \ + struct bluetooth_plugin_desc __bluetooth_builtin_ ## name = { \ + #name, version, priority, init, exit \ + }; +#else #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 \ }; +#endif |