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>
33 static GSList *plugins = NULL;
35 struct connman_plugin {
37 struct connman_plugin_desc *desc;
40 static gboolean add_plugin(GModule *module, struct connman_plugin_desc *desc)
42 struct connman_plugin *plugin;
44 plugin = g_try_new0(struct connman_plugin, 1);
48 plugin->module = module;
51 plugins = g_slist_append(plugins, plugin);
58 static void load_plugins(const gchar *path)
64 dir = g_dir_open(path, 0, NULL);
66 while ((file = g_dir_read_name(dir)) != NULL) {
68 struct connman_plugin_desc *desc;
70 if (g_str_has_prefix(file, "lib") == TRUE ||
71 g_str_has_suffix(file, ".so") == FALSE)
74 filename = g_build_filename(path, file, NULL);
76 module = g_module_open(filename, 0);
78 g_warning("Can't load %s: %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);