X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=src%2Fgis-plugin.c;h=ca009c98751b0955e25896d267feea018ea2e4ee;hb=d8271428c9bc9eea6975601ed4be313b64f968a0;hp=eb162b7c861df7a6ff6eebff77d1914bdba1712f;hpb=becee285e152746e64b6d3984e2a7229f664062d;p=grits diff --git a/src/gis-plugin.c b/src/gis-plugin.c index eb162b7..ca009c9 100644 --- a/src/gis-plugin.c +++ b/src/gis-plugin.c @@ -47,15 +47,10 @@ GType gis_plugin_get_type() return type; } -void gis_plugin_expose(GisPlugin *self) -{ - g_return_if_fail(GIS_IS_PLUGIN(self)); - GIS_PLUGIN_GET_INTERFACE(self)->expose(self); -} - GtkWidget *gis_plugin_get_config(GisPlugin *self) { - g_return_val_if_fail(GIS_IS_PLUGIN(self), NULL); + if (!GIS_IS_PLUGIN(self)) + return NULL; GisPluginInterface *iface = GIS_PLUGIN_GET_INTERFACE(self); return iface->get_config ? iface->get_config (self) : NULL; } @@ -75,21 +70,22 @@ GisPlugins *gis_plugins_new(gchar *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) { g_debug("GisPlugins: free"); - for (int i = 0; i < self->plugins->len; i++) { - GisPluginStore *store = g_ptr_array_index(self->plugins, i); + for (GList *cur = self->plugins; cur; cur = cur->next) { + GisPluginStore *store = cur->data; + g_debug("GisPlugin: freeing %s refs=%d->%d", store->name, + G_OBJECT(store->plugin)->ref_count, + G_OBJECT(store->plugin)->ref_count-1); g_object_unref(store->plugin); g_free(store->name); g_free(store); - g_ptr_array_remove_index(self->plugins, i); } - g_ptr_array_free(self->plugins, TRUE); + g_list_free(self->plugins); if (self->dir) g_free(self->dir); g_free(self); @@ -108,7 +104,7 @@ GList *gis_plugins_available(GisPlugins *self) g_debug(" checking %s", dirs[i]); const gchar *name; while ((name = g_dir_read_name(dir))) { - if (g_pattern_match_simple("*.so", name)) { + if (g_pattern_match_simple("*." G_MODULE_SUFFIX, name)) { gchar **parts = g_strsplit(name, ".", 2); list = g_list_prepend(list, g_strdup(parts[0])); g_strfreev(parts); @@ -119,20 +115,22 @@ GList *gis_plugins_available(GisPlugins *self) } GisPlugin *gis_plugins_load(GisPlugins *self, const char *name, - GisWorld *world, GisView *view, GisOpenGL *opengl, GisPrefs *prefs) + GisViewer *viewer, GisPrefs *prefs) { g_debug("GisPlugins: load %s", name); gchar *path = g_strdup_printf("%s/%s.%s", self->dir, name, G_MODULE_SUFFIX); + g_debug("GisPlugins: load - trying %s", path); if (!g_file_test(path, G_FILE_TEST_EXISTS)) { g_free(path); path = g_strdup_printf("%s/%s.%s", PLUGINSDIR, name, G_MODULE_SUFFIX); } + g_debug("GisPlugins: load - trying %s", path); 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); + GModule *module = g_module_open(path, G_MODULE_BIND_LAZY); g_free(path); if (module == NULL) { g_warning("Unable to load module %s: %s", name, g_module_error()); @@ -153,21 +151,21 @@ GisPlugin *gis_plugins_load(GisPlugins *self, const char *name, GisPluginStore *store = g_new0(GisPluginStore, 1); store->name = g_strdup(name); - store->plugin = constructor(world, view, opengl, prefs); - g_ptr_array_add(self->plugins, store); + store->plugin = constructor(viewer, prefs); + self->plugins = g_list_prepend(self->plugins, store); return store->plugin; } gboolean gis_plugins_unload(GisPlugins *self, const char *name) { g_debug("GisPlugins: unload %s", name); - for (int i = 0; i < self->plugins->len; i++) { - GisPluginStore *store = g_ptr_array_index(self->plugins, i); + for (GList *cur = self->plugins; cur; cur = cur->next) { + GisPluginStore *store = cur->data; 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->plugins, i); + self->plugins = g_list_delete_link(self->plugins, cur); } } return FALSE; @@ -175,10 +173,12 @@ gboolean gis_plugins_unload(GisPlugins *self, const char *name) void gis_plugins_foreach(GisPlugins *self, GCallback _callback, gpointer user_data) { g_debug("GisPlugins: foreach"); + if (self == NULL) + return; typedef void (*CBFunc)(GisPlugin *, const gchar *, gpointer); CBFunc callback = (CBFunc)_callback; - for (int i = 0; i < self->plugins->len; i++) { - GisPluginStore *store = g_ptr_array_index(self->plugins, i); + for (GList *cur = self->plugins; cur; cur = cur->next) { + GisPluginStore *store = cur->data; callback(store->plugin, store->name, user_data); } }