5 * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <dbus/dbus.h>
31 #include <connman/plugin.h>
35 static GSList *plugins = NULL;
37 struct connman_plugin {
39 struct connman_plugin_desc *desc;
42 static gboolean add_plugin(GModule *module, struct connman_plugin_desc *desc)
44 struct connman_plugin *plugin;
46 plugin = g_try_new0(struct connman_plugin, 1);
50 plugin->module = module;
53 plugins = g_slist_append(plugins, plugin);
60 static void load_plugins(const gchar *path)
66 dir = g_dir_open(path, 0, NULL);
68 while ((file = g_dir_read_name(dir)) != NULL) {
70 struct connman_plugin_desc *desc;
72 if (g_str_has_prefix(file, "lib") == TRUE ||
73 g_str_has_suffix(file, ".so") == FALSE)
76 filename = g_build_filename(path, file, NULL);
78 module = g_module_open(filename, 0);
80 g_warning("Can't load %s", filename);
86 DBG("%s", g_module_name(module));
88 if (g_module_symbol(module, "connman_plugin_desc",
89 (gpointer) &desc) == FALSE) {
90 g_warning("Can't load symbol");
91 g_module_close(module);
95 if (desc == NULL || desc->init == NULL) {
96 g_module_close(module);
100 if (add_plugin(module, desc) == FALSE)
101 g_module_close(module);
108 int __connman_plugin_init(void)
112 if (g_module_supported() == FALSE) {
113 g_warning("Modules not supported: %s", g_module_error());
117 load_plugins(PLUGINDIR);
122 void __connman_plugin_cleanup(void)
128 for (list = plugins; list; list = list->next) {
129 struct connman_plugin *plugin = list->data;
131 DBG("%s", g_module_name(plugin->module));
133 if (plugin->desc->exit)
134 plugin->desc->exit();
136 g_module_close(plugin->module);
141 g_slist_free(plugins);