X-Git-Url: http://pileus.org/git/?p=grits;a=blobdiff_plain;f=src%2Fgis-plugin.c;h=eb162b7c861df7a6ff6eebff77d1914bdba1712f;hp=4bfab58d71afb8d634ebd7b6d7a5957b180eb01e;hb=becee285e152746e64b6d3984e2a7229f664062d;hpb=14cdbb4a9c369576a5485315260fad5285935e80 diff --git a/src/gis-plugin.c b/src/gis-plugin.c index 4bfab58..eb162b7 100644 --- a/src/gis-plugin.c +++ b/src/gis-plugin.c @@ -1,16 +1,16 @@ /* * Copyright (C) 2009 Andy Spencer - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -56,7 +56,8 @@ void gis_plugin_expose(GisPlugin *self) GtkWidget *gis_plugin_get_config(GisPlugin *self) { g_return_val_if_fail(GIS_IS_PLUGIN(self), NULL); - return GIS_PLUGIN_GET_INTERFACE(self)->get_config(self); + GisPluginInterface *iface = GIS_PLUGIN_GET_INTERFACE(self); + return iface->get_config ? iface->get_config (self) : NULL; } @@ -68,35 +69,50 @@ typedef struct { GisPlugin *plugin; } GisPluginStore; -GisPlugins *gis_plugins_new() +GisPlugins *gis_plugins_new(gchar *dir) { - return g_ptr_array_new(); + g_debug("GisPlugins: new - dir=%s", dir); + GisPlugins *plugins = g_new0(GisPlugins, 1); + if (dir) + plugins->dir = g_strdup(dir); + plugins->plugins = g_ptr_array_new(); + return plugins; } void gis_plugins_free(GisPlugins *self) { - for (int i = 0; i < self->len; i++) { - GisPluginStore *store = g_ptr_array_index(self, i); + g_debug("GisPlugins: free"); + for (int i = 0; i < self->plugins->len; i++) { + GisPluginStore *store = g_ptr_array_index(self->plugins, i); g_object_unref(store->plugin); g_free(store->name); g_free(store); - g_ptr_array_remove_index(self, i); + g_ptr_array_remove_index(self->plugins, i); } - g_ptr_array_free(self, TRUE); + g_ptr_array_free(self->plugins, TRUE); + if (self->dir) + g_free(self->dir); + g_free(self); } -GList *gis_plugins_available() +GList *gis_plugins_available(GisPlugins *self) { - GDir *dir = g_dir_open(PLUGINDIR, 0, NULL); - if (dir == NULL) - return NULL; + g_debug("GisPlugins: available"); GList *list = NULL; - const gchar *name; - while ((name = g_dir_read_name(dir))) { - if (g_pattern_match_simple("*.so", name)) { - gchar **parts = g_strsplit(name, ".", 2); - list = g_list_prepend(list, g_strdup(parts[0])); - g_strfreev(parts); + gchar *dirs[] = {self->dir, PLUGINSDIR}; + g_debug("pluginsdir=%s", PLUGINSDIR); + for (int i = 0; i<2; i++) { + GDir *dir = g_dir_open(dirs[i], 0, NULL); + if (dir == NULL) + continue; + g_debug(" checking %s", dirs[i]); + const gchar *name; + while ((name = g_dir_read_name(dir))) { + if (g_pattern_match_simple("*.so", name)) { + gchar **parts = g_strsplit(name, ".", 2); + list = g_list_prepend(list, g_strdup(parts[0])); + g_strfreev(parts); + } } } return list; @@ -105,7 +121,17 @@ GList *gis_plugins_available() GisPlugin *gis_plugins_load(GisPlugins *self, const char *name, GisWorld *world, GisView *view, GisOpenGL *opengl, GisPrefs *prefs) { - gchar *path = g_strdup_printf("%s/%s.%s", PLUGINDIR, name, G_MODULE_SUFFIX); + g_debug("GisPlugins: load %s", name); + gchar *path = g_strdup_printf("%s/%s.%s", self->dir, name, G_MODULE_SUFFIX); + if (!g_file_test(path, G_FILE_TEST_EXISTS)) { + g_free(path); + path = g_strdup_printf("%s/%s.%s", PLUGINSDIR, name, G_MODULE_SUFFIX); + } + if (!g_file_test(path, G_FILE_TEST_EXISTS)) { + g_warning("Module %s not found", name); + g_free(path); + return NULL; + } GModule *module = g_module_open(path, 0); g_free(path); if (module == NULL) { @@ -125,32 +151,34 @@ GisPlugin *gis_plugins_load(GisPlugins *self, const char *name, g_free(constructor_str); GisPluginConstructor constructor = constructor_ptr; - GisPluginStore *store = g_malloc(sizeof(GisPluginStore)); + GisPluginStore *store = g_new0(GisPluginStore, 1); store->name = g_strdup(name); store->plugin = constructor(world, view, opengl, prefs); - g_ptr_array_add(self, store); + g_ptr_array_add(self->plugins, store); return store->plugin; } gboolean gis_plugins_unload(GisPlugins *self, const char *name) { - for (int i = 0; i < self->len; i++) { - GisPluginStore *store = g_ptr_array_index(self, i); + g_debug("GisPlugins: unload %s", name); + for (int i = 0; i < self->plugins->len; i++) { + GisPluginStore *store = g_ptr_array_index(self->plugins, i); if (g_str_equal(store->name, name)) { g_object_unref(store->plugin); g_free(store->name); g_free(store); - g_ptr_array_remove_index(self, i); + g_ptr_array_remove_index(self->plugins, i); } } return FALSE; } void gis_plugins_foreach(GisPlugins *self, GCallback _callback, gpointer user_data) { + g_debug("GisPlugins: foreach"); typedef void (*CBFunc)(GisPlugin *, const gchar *, gpointer); CBFunc callback = (CBFunc)_callback; - for (int i = 0; i < self->len; i++) { - GisPluginStore *store = g_ptr_array_index(self, i); + for (int i = 0; i < self->plugins->len; i++) { + GisPluginStore *store = g_ptr_array_index(self->plugins, i); callback(store->plugin, store->name, user_data); } }