5 * Copyright (C) 2007-2009 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
32 static GSList *plugins = NULL;
34 struct connman_plugin {
36 struct connman_plugin_desc *desc;
39 static gboolean add_plugin(void *handle, struct connman_plugin_desc *desc)
41 struct connman_plugin *plugin;
43 if (desc->init == NULL)
46 plugin = g_try_new0(struct connman_plugin, 1);
50 plugin->handle = handle;
53 if (desc->init() < 0) {
58 plugins = g_slist_append(plugins, plugin);
63 int __connman_plugin_init(void)
71 dir = g_dir_open(PLUGINDIR, 0, NULL);
73 while ((file = g_dir_read_name(dir)) != NULL) {
75 struct connman_plugin_desc *desc;
77 if (g_str_has_prefix(file, "lib") == TRUE ||
78 g_str_has_suffix(file, ".so") == FALSE)
81 filename = g_build_filename(PLUGINDIR, file, NULL);
83 handle = dlopen(filename, RTLD_NOW);
85 g_warning("Can't load %s: %s", filename,
93 desc = dlsym(handle, "connman_plugin_desc");
95 g_warning("Can't load symbol: %s", dlerror());
100 if (add_plugin(handle, desc) == FALSE)
110 void __connman_plugin_cleanup(void)
116 for (list = plugins; list; list = list->next) {
117 struct connman_plugin *plugin = list->data;
119 if (plugin->desc->exit)
120 plugin->desc->exit();
122 dlclose(plugin->handle);
127 g_slist_free(plugins);