From f2e2cd7787b14eba5160f3ff4f1b2493e55d6f4d Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 10 May 2009 22:35:29 -0700 Subject: [PATCH] Add support for builtin plugins --- .gitignore | 1 + Makefile.am | 2 +- include/plugin.h | 6 ++++++ plugins/Makefile.am | 26 +++++++++++++++++++++++ src/Makefile.am | 5 +++-- src/plugin.c | 52 ++++++++++++++++++++++++++++++++------------- 6 files changed, 74 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 9682c7f6..7e04fdf2 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ include/version.h src/ofonod src/ofono.exp src/ofono.ver +plugins/builtin.h diff --git a/Makefile.am b/Makefile.am index 972b420d..e125f4bf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ -SUBDIRS = gdbus gatchat include src plugins doc +SUBDIRS = gdbus gatchat include plugins src doc DISTCHECK_CONFIGURE_FLAGS = --disable-datafiles diff --git a/include/plugin.h b/include/plugin.h index 7c133e39..db97c0b4 100644 --- a/include/plugin.h +++ b/include/plugin.h @@ -62,12 +62,18 @@ struct ofono_plugin_desc { * * Macro for defining a plugin descriptor */ +#ifdef OFONO_PLUGIN_BUILTIN + struct ofono_plugin_desc __ofono_builtin_ ## name = { \ + #name, description, version, priority, init, exit \ + }; +#else #define OFONO_PLUGIN_DEFINE(name, description, version, priority, init, exit) \ extern struct ofono_plugin_desc ofono_plugin_desc \ __attribute__ ((visibility("default"))); \ struct ofono_plugin_desc ofono_plugin_desc = { \ #name, description, version, priority, init, exit \ }; +#endif #ifdef __cplusplus } diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 02742923..e2ad41f0 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,2 +1,28 @@ +builtin_modules = +builtin_sources = +builtin_cflags = + +noinst_LTLIBRARIES = libbuiltin.la + +libbuiltin_la_SOURCES = $(builtin_sources) +libbuiltin_la_LDFLAGS = +libbuiltin_la_CFLAGS = $(AM_CFLAGS) $(builtin_cflags) -DOFONO_PLUGIN_BUILTIN + +BUILT_SOURCES = builtin.h + +nodist_libbuiltin_la_SOURCES = $(BUILT_SOURCES) + +CLEANFILES = $(BUILT_SOURCES) + MAINTAINERCLEANFILES = Makefile.in + +builtin.h: + echo "" > $@ + list='$(builtin_modules)'; for i in $$list; \ + do echo "extern struct ofono_plugin_desc __ofono_builtin_$$i;" >> $@; done + echo "" >> $@ + echo "static struct ofono_plugin_desc *__ofono_builtin[] = {" >> $@ + list='$(builtin_modules)'; for i in $$list; \ + do echo "&__ofono_builtin_$$i," >> $@; done + echo "NULL };" >> $@ diff --git a/src/Makefile.am b/src/Makefile.am index 0c0c8a5b..91449599 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,7 +13,8 @@ ofonod_SOURCES = main.c ofono.h log.c plugin.c \ network.c voicecall.c ussd.h ussd.c \ call-settings.c call-waiting.c call-forwarding.c call-meter.c -ofonod_LDADD = @GDBUS_LIBS@ @GLIB_LIBS@ @GTHREAD_LIBS@ -ldl +ofonod_LDADD = $(top_builddir)/plugins/libbuiltin.la \ + @GDBUS_LIBS@ @GLIB_LIBS@ @GTHREAD_LIBS@ -ldl ofonod_LDFLAGS = -Wl,--export-dynamic -Wl,--version-script=ofono.ver @@ -30,7 +31,7 @@ endif AM_CFLAGS = @GTHREAD_CFLAGS@ @GLIB_CFLAGS@ @GDBUS_CFLAGS@ \ -DPLUGINDIR=\""$(plugindir)"\" -INCLUDES = -I$(top_builddir)/include +INCLUDES = -I$(top_builddir)/include -I$(top_builddir) EXTRA_DIST = ofono.conf diff --git a/src/plugin.c b/src/plugin.c index 9822359f..27c2a929 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -53,7 +53,7 @@ static gboolean add_plugin(void *handle, struct ofono_plugin_desc *desc) return FALSE; if (g_str_equal(desc->version, OFONO_VERSION) == FALSE) { - DBG("version mismatch for %s", desc->description); + ofono_error("Version mismatch for %s", desc->description); return FALSE; } @@ -70,15 +70,44 @@ static gboolean add_plugin(void *handle, struct ofono_plugin_desc *desc) return TRUE; } +static gboolean check_plugin(struct ofono_plugin_desc *desc, + const char *pattern, const char *exclude) +{ + if (exclude != NULL && + g_pattern_match_simple(exclude, desc->name) == TRUE) { + ofono_info("Excluding %s", desc->description); + return FALSE; + } + + if (pattern != NULL && + g_pattern_match_simple(pattern, desc->name) == FALSE) { + ofono_info("Ignoring %s", desc->description); + return FALSE; + } + + return TRUE; +} + +#include "plugins/builtin.h" + int __ofono_plugin_init(const char *pattern, const char *exclude) { GSList *list; GDir *dir; const gchar *file; gchar *filename; + unsigned int i; DBG(""); + for (i = 0; __ofono_builtin[i]; i++) { + if (check_plugin(__ofono_builtin[i], + pattern, exclude) == FALSE) + continue; + + add_plugin(NULL, __ofono_builtin[i]); + } + dir = g_dir_open(PLUGINDIR, 0, NULL); if (dir != NULL) { while ((file = g_dir_read_name(dir)) != NULL) { @@ -93,8 +122,8 @@ int __ofono_plugin_init(const char *pattern, const char *exclude) handle = dlopen(filename, RTLD_NOW); if (handle == NULL) { - g_warning("Can't load %s: %s", filename, - dlerror()); + ofono_error("Can't load %s: %s", + filename, dlerror()); g_free(filename); continue; } @@ -103,21 +132,13 @@ int __ofono_plugin_init(const char *pattern, const char *exclude) desc = dlsym(handle, "ofono_plugin_desc"); if (desc == NULL) { - g_warning("Can't load symbol: %s", dlerror()); + ofono_error("Can't load symbol: %s", + dlerror()); dlclose(handle); continue; } - if (exclude != NULL && g_pattern_match_simple(exclude, - desc->name) == TRUE) { - DBG("excluding %s", desc->description); - dlclose(handle); - continue; - } - - if (pattern != NULL && g_pattern_match_simple(pattern, - desc->name) == FALSE) { - DBG("ignoring %s", desc->description); + if (check_plugin(desc, pattern, exclude) == FALSE) { dlclose(handle); continue; } @@ -153,7 +174,8 @@ void __ofono_plugin_cleanup(void) if (plugin->active == TRUE && plugin->desc->exit) plugin->desc->exit(); - dlclose(plugin->handle); + if (plugin->handle) + dlclose(plugin->handle); g_free(plugin); }