[gnome-software/wip/rancell/ubuntu-3-20-rebase: 19/28] Support ordering plugings before other plugins



commit eac3a2629128565ef9688226cfd70fdbe6ef2db2
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 |   55 +++++++++++++++++++++++++++++++++++++++--------
 src/gs-plugin.h        |    6 ++++-
 2 files changed, 50 insertions(+), 11 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index a648a6a..7f12ceb 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -2984,7 +2984,9 @@ 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;
 
        module = g_module_open (filename, 0);
@@ -3005,9 +3007,15 @@ 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);
 
        /* print what we know */
        plugin = g_slice_new0 (GsPlugin);
@@ -3015,7 +3023,9 @@ 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;
        plugin->status_update_fn = gs_plugin_loader_status_update_cb;
@@ -3162,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,
@@ -3185,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 f49d1eb..b6c18f8 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -64,7 +64,9 @@ 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;
        GsPluginPrivate         *priv;
@@ -219,6 +221,8 @@ 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,
                                                         GCancellable   *cancellable,


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