gplugin/gplugin

Add gplugin_plugin_get_dependent_plugins. Fixes #8
develop
2017-06-05, Gary Kramlich
25f8b3733cc7
Add gplugin_plugin_get_dependent_plugins. Fixes #8
--- a/ChangeLog Mon Jun 05 21:17:00 2017 -0500
+++ b/ChangeLog Mon Jun 05 22:30:45 2017 -0500
@@ -2,6 +2,7 @@
* Fixed building on OSX with homebrew
* Added an RPM spec file
* Changed the build system to meson. See INSTALL for instructions.
+ * Added gplugin_plugin_get_dependent_plugins. (fixes #8)
0.27.0: 2016/04/18
* Bumped the glib requirement to 2.34.0
--- a/gplugin/gplugin-manager.c Mon Jun 05 21:17:00 2017 -0500
+++ b/gplugin/gplugin-manager.c Mon Jun 05 22:30:45 2017 -0500
@@ -593,7 +593,8 @@
}
static gboolean
-gplugin_manager_load_dependencies(const GPluginPluginInfo *info,
+gplugin_manager_load_dependencies(GPluginPlugin *plugin,
+ const GPluginPluginInfo *info,
GError **error)
{
const gchar * const *dependencies = NULL;
@@ -680,6 +681,8 @@
ret = gplugin_manager_load_plugin(dplugin, error);
+ gplugin_plugin_add_dependent_plugin(dplugin, plugin);
+
g_object_unref(G_OBJECT(dplugin));
if(ret) {
@@ -734,7 +737,7 @@
return FALSE;
}
- if(!gplugin_manager_load_dependencies(info, error)) {
+ if(!gplugin_manager_load_dependencies(plugin, info, error)) {
g_object_unref(G_OBJECT(info));
return FALSE;
--- a/gplugin/gplugin-plugin.c Mon Jun 05 21:17:00 2017 -0500
+++ b/gplugin/gplugin-plugin.c Mon Jun 05 22:30:45 2017 -0500
@@ -47,6 +47,8 @@
GPluginPluginInfo *info;
GPluginPluginState state;
+
+ GList *dependents;
} GPluginPluginPrivate;
/******************************************************************************
@@ -116,6 +118,15 @@
return priv->filename;
}
+void
+gplugin_plugin_add_dependent_plugin(GPluginPlugin *plugin,
+ GPluginPlugin *dependent)
+{
+ GPluginPluginPrivate *priv = GPLUGIN_PLUGIN_GET_PRIVATE(plugin);
+
+ priv->dependents = g_list_append(priv->dependents, g_object_ref(dependent));
+}
+
/******************************************************************************
* Object Stuff
*****************************************************************************/
@@ -172,6 +183,7 @@
static void
gplugin_plugin_finalize(GObject *obj) {
GPluginPluginPrivate *priv = GPLUGIN_PLUGIN_GET_PRIVATE(obj);
+ GList *l = NULL;
g_free(priv->filename);
g_object_unref(priv->loader);
@@ -179,6 +191,10 @@
if(priv->info)
g_object_unref(G_OBJECT(priv->info));
+ for(l = priv->dependents; l; l = l->next) {
+ g_object_unref(G_OBJECT(l->data));
+ }
+
G_OBJECT_CLASS(parent_class)->finalize(obj);
}
@@ -379,3 +395,22 @@
oldstate, priv->state);
}
+/**
+ * gplugin_plugin_get_dependent_plugins:
+ * @plugin: #GPluginPlugin instance
+ *
+ * Returns a list of plugins that depend on @plugin.
+ *
+ * Return value: (element-type GPlugin.Plugin) (transfer none): A #GList of
+ * each plugin that depends on this plugin.
+ */
+GList *
+gplugin_plugin_get_dependent_plugins(const GPluginPlugin *plugin) {
+ GPluginPluginPrivate *priv = NULL;
+
+ g_return_val_if_fail(GPLUGIN_IS_PLUGIN(plugin), NULL);
+
+ priv = GPLUGIN_PLUGIN_GET_PRIVATE(plugin);
+
+ return priv->dependents;
+}
--- a/gplugin/gplugin-plugin.h Mon Jun 05 21:17:00 2017 -0500
+++ b/gplugin/gplugin-plugin.h Mon Jun 05 22:30:45 2017 -0500
@@ -75,6 +75,7 @@
GPluginPluginState gplugin_plugin_get_state(const GPluginPlugin *plugin);
void gplugin_plugin_set_state(GPluginPlugin *plugin, GPluginPluginState state);
+GList *gplugin_plugin_get_dependent_plugins(const GPluginPlugin *plugin);
G_END_DECLS
--- a/gplugin/gplugin-private.h Mon Jun 05 21:17:00 2017 -0500
+++ b/gplugin/gplugin-private.h Mon Jun 05 22:30:45 2017 -0500
@@ -40,6 +40,7 @@
gboolean gplugin_boolean_accumulator(GSignalInvocationHint *hint, GValue *return_accu, const GValue *handler_return, gpointer data);
gboolean gplugin_plugin_info_get_bind_local(const GPluginPluginInfo *info);
+void gplugin_plugin_add_dependent_plugin(GPluginPlugin *plugin, GPluginPlugin *dependent);
G_END_DECLS
--- a/gplugin/tests/test-versioned-dependencies.c Mon Jun 05 21:17:00 2017 -0500
+++ b/gplugin/tests/test-versioned-dependencies.c Mon Jun 05 22:30:45 2017 -0500
@@ -23,9 +23,33 @@
#include <glib.h>
/******************************************************************************
+ * Helpers
+ *****************************************************************************/
+static void
+_test_plugin_load_and_has_dependent(GPluginPlugin *dependent,
+ const gchar *id)
+{
+ GPluginPlugin *plugin = NULL;
+ GList *l = NULL;
+ gboolean found = FALSE;
+
+ plugin = gplugin_manager_find_plugin("gplugin/test-no-version");
+ g_assert_cmpint(gplugin_plugin_get_state(plugin), ==,
+ GPLUGIN_PLUGIN_STATE_LOADED);
+
+ for(l = gplugin_plugin_get_dependent_plugins(plugin); l; l = l->next) {
+ if(l->data == dependent)
+ found = TRUE;
+ }
+
+ g_assert(found);
+
+ g_object_unref(G_OBJECT(plugin));
+}
+
+/******************************************************************************
* Tests
*****************************************************************************/
-/* load on query */
static void
test_load_with_dependencies(void) {
GPluginPlugin *plugin = NULL;
@@ -47,55 +71,16 @@
g_object_unref(G_OBJECT(plugin));
/* now make sure each dependent plugin that's available was loaded */
- plugin = gplugin_manager_find_plugin("gplugin/test-no-version");
- g_assert_cmpint(gplugin_plugin_get_state(plugin), ==,
- GPLUGIN_PLUGIN_STATE_LOADED);
- g_object_unref(G_OBJECT(plugin));
-
- plugin = gplugin_manager_find_plugin("gplugin/test-exact1");
- g_assert_cmpint(gplugin_plugin_get_state(plugin), ==,
- GPLUGIN_PLUGIN_STATE_LOADED);
- g_object_unref(G_OBJECT(plugin));
-
- plugin = gplugin_manager_find_plugin("gplugin/test-exact2");
- g_assert_cmpint(gplugin_plugin_get_state(plugin), ==,
- GPLUGIN_PLUGIN_STATE_LOADED);
- g_object_unref(G_OBJECT(plugin));
-
- plugin = gplugin_manager_find_plugin("gplugin/test-greater");
- g_assert_cmpint(gplugin_plugin_get_state(plugin), ==,
- GPLUGIN_PLUGIN_STATE_LOADED);
- g_object_unref(G_OBJECT(plugin));
-
- plugin = gplugin_manager_find_plugin("gplugin/test-greater-equal");
- g_assert_cmpint(gplugin_plugin_get_state(plugin), ==,
- GPLUGIN_PLUGIN_STATE_LOADED);
- g_object_unref(G_OBJECT(plugin));
-
- plugin = gplugin_manager_find_plugin("gplugin/test-less");
- g_assert_cmpint(gplugin_plugin_get_state(plugin), ==,
- GPLUGIN_PLUGIN_STATE_LOADED);
- g_object_unref(G_OBJECT(plugin));
-
- plugin = gplugin_manager_find_plugin("gplugin/test-less-equal");
- g_assert_cmpint(gplugin_plugin_get_state(plugin), ==,
- GPLUGIN_PLUGIN_STATE_LOADED);
- g_object_unref(G_OBJECT(plugin));
-
- plugin = gplugin_manager_find_plugin("gplugin/bar");
- g_assert_cmpint(gplugin_plugin_get_state(plugin), ==,
- GPLUGIN_PLUGIN_STATE_LOADED);
- g_object_unref(G_OBJECT(plugin));
-
- plugin = gplugin_manager_find_plugin("gplugin/baz");
- g_assert_cmpint(gplugin_plugin_get_state(plugin), ==,
- GPLUGIN_PLUGIN_STATE_LOADED);
- g_object_unref(G_OBJECT(plugin));
-
- plugin = gplugin_manager_find_plugin("gplugin/fez");
- g_assert_cmpint(gplugin_plugin_get_state(plugin), ==,
- GPLUGIN_PLUGIN_STATE_LOADED);
- g_object_unref(G_OBJECT(plugin));
+ _test_plugin_load_and_has_dependent(plugin, "gplugin/test-no-version");
+ _test_plugin_load_and_has_dependent(plugin, "gplugin/test-exact1");
+ _test_plugin_load_and_has_dependent(plugin, "gplugin/test-exact2");
+ _test_plugin_load_and_has_dependent(plugin, "gplugin/test-greater");
+ _test_plugin_load_and_has_dependent(plugin, "gplugin/test-greater-equal");
+ _test_plugin_load_and_has_dependent(plugin, "gplugin/test-less");
+ _test_plugin_load_and_has_dependent(plugin, "gplugin/test-less-equal");
+ _test_plugin_load_and_has_dependent(plugin, "gplugin/bar");
+ _test_plugin_load_and_has_dependent(plugin, "gplugin/baz");
+ _test_plugin_load_and_has_dependent(plugin, "gplugin/fez");
}
/******************************************************************************