[gnome-software/wip/iainl/ubuntu-xenial: 281/287] Support ordering plugings before other plugins



commit 41df2c0f11824cec3b5c41c6fb6c1e662a251f82
Author: Richard Hughes <richard hughsie com>
Date:   Thu Apr 7 18:26:34 2016 +0100

    Support ordering plugings before other plugins
    
    This lets a new plugin control the dep chain without patching other plugins.

 src/gs-plugin-loader.c |   50 ++++++++++++++++++++++++++++++++++++++---------
 src/gs-plugin.h        |    4 ++-
 2 files changed, 43 insertions(+), 11 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 6a99408..5551fd1 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -2984,7 +2984,8 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
        gboolean ret;
        GModule *module;
        GsPluginGetNameFunc plugin_name = NULL;
-       GsPluginGetDepsFunc plugin_deps = NULL;
+       GsPluginGetDepsFunc order_after = NULL;
+       GsPluginGetDepsFunc order_before = NULL;
        GsPluginGetDepsFunc plugin_conflicts = NULL;
        GsPlugin *plugin = NULL;
 
@@ -3006,9 +3007,12 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
        }
 
        /* get plugins this plugin depends on */
-       (void) g_module_symbol (module,
-                               "gs_plugin_order_after",
-                               (gpointer *) &plugin_deps);
+       g_module_symbol (module,
+                        "gs_plugin_order_after",
+                        (gpointer *) &order_after);
+       g_module_symbol (module,
+                        "gs_plugin_order_before",
+                        (gpointer *) &order_before);
        g_module_symbol (module,
                         "gs_plugin_get_conflicts",
                         (gpointer *) &plugin_conflicts);
@@ -3019,7 +3023,8 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
        plugin->module = module;
        plugin->pixbuf_size = 64;
        plugin->priority = 0.f;
-       plugin->deps = plugin_deps != NULL ? plugin_deps (plugin) : NULL;
+       plugin->order_after = order_after != NULL ? order_after (plugin) : NULL;
+       plugin->order_before = order_before != NULL ? order_before (plugin) : NULL;
        plugin->conflicts = plugin_conflicts != NULL ? plugin_conflicts (plugin) : NULL;
        plugin->name = g_strdup (plugin_name ());
        plugin->locale = priv->locale;
@@ -3167,20 +3172,20 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader, GError **error)
                changes = FALSE;
                for (i = 0; i < priv->plugins->len; i++) {
                        plugin = g_ptr_array_index (priv->plugins, i);
-                       if (plugin->deps == NULL)
+                       if (plugin->order_after == NULL)
                                continue;
-                       for (j = 0; plugin->deps[j] != NULL && !changes; j++) {
+                       for (j = 0; plugin->order_after[j] != NULL && !changes; j++) {
                                dep = gs_plugin_loader_find_plugin (plugin_loader,
-                                                                   plugin->deps[j]);
+                                                                   plugin->order_after[j]);
                                if (dep == NULL) {
                                        g_debug ("cannot find plugin '%s'",
-                                                plugin->deps[j]);
+                                                plugin->order_after[j]);
                                        continue;
                                }
                                if (!dep->enabled)
                                        continue;
                                if (plugin->priority <= dep->priority) {
-                                       g_debug ("%s [%.1f] requires %s [%.1f] "
+                                       g_debug ("%s [%.1f] to be ordered after %s [%.1f] "
                                                 "so promoting to [%.1f]",
                                                 plugin->name, plugin->priority,
                                                 dep->name, dep->priority,
@@ -3190,6 +3195,31 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader, GError **error)
                                }
                        }
                }
+               for (i = 0; i < priv->plugins->len; i++) {
+                       plugin = g_ptr_array_index (priv->plugins, i);
+                       if (plugin->order_before == NULL)
+                               continue;
+                       for (j = 0; plugin->order_before[j] != NULL && !changes; j++) {
+                               dep = gs_plugin_loader_find_plugin (plugin_loader,
+                                                                   plugin->order_before[j]);
+                               if (dep == NULL) {
+                                       g_debug ("cannot find plugin '%s'",
+                                                plugin->order_before[j]);
+                                       continue;
+                               }
+                               if (!dep->enabled)
+                                       continue;
+                               if (plugin->priority <= dep->priority) {
+                                       g_debug ("%s [%.1f] to be ordered before %s [%.1f] "
+                                                "so promoting to [%.1f]",
+                                                plugin->name, plugin->priority,
+                                                dep->name, dep->priority,
+                                                dep->priority + dep_increment);
+                                       dep->priority = plugin->priority + dep_increment;
+                                       changes = TRUE;
+                               }
+                       }
+               }
 
                /* check we're not stuck */
                if (dep_loop_check++ > 100) {
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index 74867d9..31417c2 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -64,7 +64,8 @@ typedef gboolean (*GsPluginListFilter)        (GsApp          *app,
 struct GsPlugin {
        GModule                 *module;
        gdouble                  priority;      /* largest number gets run first */
-       const gchar             **deps;         /* allow-none */
+       const gchar             **order_after;  /* allow-none */
+       const gchar             **order_before; /* allow-none */
        const gchar             **conflicts;    /* allow-none */
        gboolean                 enabled;
        gchar                   *name;
@@ -215,6 +216,7 @@ gboolean     gs_plugin_add_search_what_provides     (GsPlugin       *plugin,
                                                         GCancellable   *cancellable,
                                                         GError         **error);
 const gchar    **gs_plugin_order_after                 (GsPlugin       *plugin);
+const gchar    **gs_plugin_order_before                (GsPlugin       *plugin);
 const gchar    **gs_plugin_get_conflicts               (GsPlugin       *plugin);
 gboolean        gs_plugin_add_installed                (GsPlugin       *plugin,
                                                         GList          **list,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]