Add support for builtin plugins

This commit is contained in:
Marcel Holtmann 2009-05-10 22:35:29 -07:00
parent 64c4276473
commit f2e2cd7787
6 changed files with 74 additions and 18 deletions

1
.gitignore vendored
View File

@ -26,3 +26,4 @@ include/version.h
src/ofonod
src/ofono.exp
src/ofono.ver
plugins/builtin.h

View File

@ -1,5 +1,5 @@
SUBDIRS = gdbus gatchat include src plugins doc
SUBDIRS = gdbus gatchat include plugins src doc
DISTCHECK_CONFIGURE_FLAGS = --disable-datafiles

View File

@ -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
}

View File

@ -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 };" >> $@

View File

@ -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

View File

@ -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);
}