[gnome-software: 3/29] gs-plugin: Add a shutdown vfunc




commit 029086887f28c2a3b13381c40c9a17589fd24249
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Oct 14 14:31:55 2021 +0100

    gs-plugin: Add a shutdown vfunc
    
    This will allow plugins to be shut down and gracefully stop any
    long-running processes they might have started. For example, joining
    background threads or cancelling ongoing operations.
    
    There was previously no equivalent of this in the API; it does not
    replace a previous vfunc in `gs-plugin-vfuncs.h`. Currently, no plugins
    implement this new vfunc, but they will do in subsequent commits.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1472

 lib/gs-plugin-loader.c |  8 +++++++-
 lib/gs-plugin.h        | 23 +++++++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 19e958ece..d70466354 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -2797,7 +2797,13 @@ gs_plugin_loader_dispose (GObject *object)
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
 
        if (plugin_loader->plugins != NULL) {
-               /* FIXME: call a ->stop() (or similar) method on every plugin */
+               /* Shut down all the plugins first. */
+               for (guint i = 0; i < plugin_loader->plugins->len; i++) {
+                       GsPlugin *plugin = GS_PLUGIN (plugin_loader->plugins->pdata[i]);
+                       if (GS_PLUGIN_GET_CLASS (plugin)->shutdown_async != NULL)
+                               GS_PLUGIN_GET_CLASS (plugin)->shutdown_async (plugin, NULL, NULL, NULL);
+               }
+
                g_clear_pointer (&plugin_loader->plugins, g_ptr_array_unref);
        }
        if (plugin_loader->updates_changed_id != 0) {
diff --git a/lib/gs-plugin.h b/lib/gs-plugin.h
index 0f1e3e9d3..0903a735f 100644
--- a/lib/gs-plugin.h
+++ b/lib/gs-plugin.h
@@ -26,6 +26,20 @@ G_BEGIN_DECLS
 
 G_DECLARE_DERIVABLE_TYPE (GsPlugin, gs_plugin, GS, PLUGIN, GObject)
 
+/**
+ * GsPluginClass:
+ * @shutdown_async: (nullable): Shutdown method for the plugin. This is called
+ *   by the #GsPluginLoader when the process is terminating or the
+ *   #GsPluginLoader is being destroyed. It should be used to cancel or stop any
+ *   ongoing operations or threads in the plugin. It may be %NULL if the plugin
+ *   doesn’t need to be explicitly shut down.
+ * @shutdown_finish: (nullable): Finish method for @shutdown_async. Must be
+ *   implemented if @shutdown_async is implemented.
+ *
+ * The class structure for a #GsPlugin. Virtual methods here should be
+ * implemented by plugin implementations derived from #GsPlugin to provide their
+ * plugin-specific behaviour.
+ */
 struct _GsPluginClass
 {
        GObjectClass             parent_class;
@@ -50,6 +64,15 @@ struct _GsPluginClass
                                                         const gchar    *msg,
                                                         const gchar    *details,
                                                         const gchar    *accept_label);
+
+       void                    (*shutdown_async)       (GsPlugin               *plugin,
+                                                        GCancellable           *cancellable,
+                                                        GAsyncReadyCallback     callback,
+                                                        gpointer                user_data);
+       gboolean                (*shutdown_finish)      (GsPlugin               *plugin,
+                                                        GAsyncResult           *result,
+                                                        GError                 **error);
+
        gpointer                 padding[23];
 };
 


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