diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.am | 6 | ||||
-rw-r--r-- | plugins/Makefile.am | 62 | ||||
-rw-r--r-- | plugins/echo.c | 2 | ||||
-rw-r--r-- | plugins/hal.c | 2 | ||||
-rw-r--r-- | plugins/hciops.c | 2 | ||||
-rw-r--r-- | plugins/netlink.c | 2 | ||||
-rw-r--r-- | plugins/service.c | 2 | ||||
-rw-r--r-- | plugins/storage.c | 2 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/plugin.c | 23 | ||||
-rw-r--r-- | src/plugin.h | 7 |
12 files changed, 76 insertions, 38 deletions
diff --git a/.gitignore b/.gitignore index 0806a8938..0c774e9dc 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ parser.c bluez.pc include/bluetooth src/bluetoothd +plugins/builtin.h audio/telephony.c sbc/sbcdec diff --git a/Makefile.am b/Makefile.am index f2d1ca73b..b5d1ee2c2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ -SUBDIRS = include lib sbc gdbus common src client\ - plugins network serial input audio \ - tools rfcomm compat cups test scripts doc +SUBDIRS = include lib sbc gdbus common plugins src client\ + network serial input audio tools \ + rfcomm compat cups test scripts doc EXTRA_DIST = bluez.m4 diff --git a/plugins/Makefile.am b/plugins/Makefile.am index bbabf64e6..9d9f970ef 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,37 +1,41 @@ plugindir = $(libdir)/bluetooth/plugins -if NETLINK -netlink_plugins = netlink.la -else -netlink_plugins = -endif +plugin_LTLIBRARIES = + +builtin_modules = +builtin_sources = +builtin_cflags = if SERVICEPLUGIN -service_plugins = service.la -else -service_plugins = +builtin_modules += service +builtin_sources += service.c endif -plugin_LTLIBRARIES = hal.la hciops.la $(netlink_plugins) $(service_plugins) +builtin_modules += hciops +builtin_sources += hciops.c -noinst_LTLIBRARIES = echo.la storage.la +if NETLINK +plugin_LTLIBRARIES += netlink.la +netlink_la_LIBADD = @NETLINK_LIBS@ +endif -echo_la_SOURCES = echo.c +builtin_modules += hal +builtin_sources += hal.c -storage_la_SOURCES = storage.c +builtin_modules += storage +builtin_sources += storage.c -hciops_la_SOURCES = hciops.c +noinst_LTLIBRARIES = libbuiltin.la echo.la -if NETLINK -netlink_la_SOURCES = netlink.c +libbuiltin_la_SOURCES = $(builtin_sources) +libbuiltin_la_LDFLAGS = +libbuiltin_la_CFLAGS = $(AM_CFLAGS) \ + $(builtin_cflags) -DBLUETOOTH_PLUGIN_BUILTIN -netlink_la_LIBADD = @NETLINK_LIBS@ -endif +BUILT_SOURCES = builtin.h -if SERVICEPLUGIN -service_la_SOURCES = service.c -endif +nodist_libbuiltin_la_SOURCES = $(BUILT_SOURCES) AM_LDFLAGS = -module -avoid-version -no-undefined @@ -40,22 +44,28 @@ AM_CFLAGS = -fvisibility=hidden @BLUEZ_CFLAGS@ @DBUS_CFLAGS@ \ INCLUDES = -I$(top_srcdir)/common -I$(top_srcdir)/src +CLEANFILES = $(BUILT_SOURCES) + MAINTAINERCLEANFILES = Makefile.in +builtin.h: + echo "" > $@ + list='$(builtin_modules)'; for i in $$list; \ + do echo "extern struct bluetooth_plugin_desc __bluetooth_builtin_$$i;" >> $@; done + echo "" >> $@ + echo "static struct bluetooth_plugin_desc *__bluetooth_builtin[] = {" >> $@ + list='$(builtin_modules)'; for i in $$list; \ + do echo "&__bluetooth_builtin_$$i," >> $@; done + echo "NULL };" >> $@ + all-local: @$(LN_S) -f $(top_srcdir)/input/.libs/input.so @$(LN_S) -f $(top_srcdir)/audio/.libs/audio.so @$(LN_S) -f $(top_srcdir)/serial/.libs/serial.so @$(LN_S) -f $(top_srcdir)/network/.libs/network.so - @$(LN_S) -f .libs/service.so - @$(LN_S) -f .libs/hal.so - @$(LN_S) -f .libs/hciops.so clean-local: - @rm -f hal.so - @rm -f service.so @rm -f network.so @rm -f serial.so @rm -f audio.so @rm -f input.so - @rm -f hciops.so diff --git a/plugins/echo.c b/plugins/echo.c index 716742e9e..919d08539 100644 --- a/plugins/echo.c +++ b/plugins/echo.c @@ -164,4 +164,4 @@ static void echo_exit(void) } BLUETOOTH_PLUGIN_DEFINE(echo, VERSION, - BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, echo_init, echo_exit) + BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, echo_init, echo_exit) diff --git a/plugins/hal.c b/plugins/hal.c index 65f70598c..5b7e4b2cf 100644 --- a/plugins/hal.c +++ b/plugins/hal.c @@ -159,4 +159,4 @@ static void hal_exit(void) } BLUETOOTH_PLUGIN_DEFINE(hal, VERSION, - BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, hal_init, hal_exit) + BLUETOOTH_PLUGIN_PRIORITY_LOW, hal_init, hal_exit) diff --git a/plugins/hciops.c b/plugins/hciops.c index 19ef8fc42..ba4b69d4a 100644 --- a/plugins/hciops.c +++ b/plugins/hciops.c @@ -455,4 +455,4 @@ static void hciops_exit(void) } BLUETOOTH_PLUGIN_DEFINE(hciops, VERSION, - BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, hciops_init, hciops_exit) + BLUETOOTH_PLUGIN_PRIORITY_LOW, hciops_init, hciops_exit) diff --git a/plugins/netlink.c b/plugins/netlink.c index 88ab5e8fd..e85d2648b 100644 --- a/plugins/netlink.c +++ b/plugins/netlink.c @@ -124,4 +124,4 @@ static void netlink_exit(void) } BLUETOOTH_PLUGIN_DEFINE(netlink, VERSION, - BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, netlink_init, netlink_exit) + BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, netlink_init, netlink_exit) diff --git a/plugins/service.c b/plugins/service.c index 27264bba9..3ddfd2a7c 100644 --- a/plugins/service.c +++ b/plugins/service.c @@ -860,4 +860,4 @@ static void service_exit(void) } BLUETOOTH_PLUGIN_DEFINE(service, VERSION, - BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, service_init, service_exit) + BLUETOOTH_PLUGIN_PRIORITY_HIGH, service_init, service_exit) diff --git a/plugins/storage.c b/plugins/storage.c index 0649e0655..99b49525d 100644 --- a/plugins/storage.c +++ b/plugins/storage.c @@ -40,4 +40,4 @@ static void storage_exit(void) } BLUETOOTH_PLUGIN_DEFINE(storage, VERSION, - BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, storage_init, storage_exit) + BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, storage_init, storage_exit) 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 |