5 * Copyright (C) 2007 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, "libconnman") == FALSE)
75 filename = g_build_filename(path, file, NULL);
77 module = g_module_open(filename, 0);
79 g_warning("Can't load %s", filename);
85 DBG("%s", g_module_name(module));
87 if (g_module_symbol(module, "connman_plugin_desc",
88 (gpointer) &desc) == FALSE) {
89 g_warning("Can't load symbol");
90 g_module_close(module);
94 if (desc == NULL || desc->init == NULL) {
95 g_module_close(module);
99 if (add_plugin(module, desc) == FALSE)
100 g_module_close(module);
107 int __connman_plugin_init(void)
111 if (g_module_supported() == FALSE) {
112 g_warning("Modules not supported: %s", g_module_error());
116 load_plugins(PLUGINDIR);
121 void __connman_plugin_cleanup(void)
127 for (list = plugins; list; list = list->next) {
128 struct connman_plugin *plugin = list->data;
130 DBG("%s", g_module_name(plugin->module));
132 if (plugin->desc->exit)
133 plugin->desc->exit();
135 g_module_close(plugin->module);
140 g_slist_free(plugins);