[gnome-software/wip/async-plugin-repo-funcs: 19/29] packagekit: Let it possible to store helper on the GsPackagekitTask




commit 3f2ead008feeb6f75e05c63f2ea7ff232821472e
Author: Milan Crha <mcrha redhat com>
Date:   Tue Jun 14 19:34:34 2022 +0200

    packagekit: Let it possible to store helper on the GsPackagekitTask
    
    This will help with memory management on the helper when running
    an asynchronous operation, because the progress data do not have
    their destroy callback and the associated GTask can have its own
    data already set.

 plugins/packagekit/gs-packagekit-task.c | 29 +++++++++++++++++++++++++++++
 plugins/packagekit/gs-packagekit-task.h |  6 ++++++
 2 files changed, 35 insertions(+)
---
diff --git a/plugins/packagekit/gs-packagekit-task.c b/plugins/packagekit/gs-packagekit-task.c
index 05c64e863..c817f3222 100644
--- a/plugins/packagekit/gs-packagekit-task.c
+++ b/plugins/packagekit/gs-packagekit-task.c
@@ -29,6 +29,8 @@
 typedef struct {
        GWeakRef plugin_weakref; /* GsPlugin * */
        GsPluginAction action;
+       GsPackagekitHelper *helper;
+
 } GsPackagekitTaskPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (GsPackagekitTask, gs_packagekit_task, PK_TYPE_TASK)
@@ -178,6 +180,7 @@ gs_packagekit_task_finalize (GObject *object)
        GsPackagekitTaskPrivate *priv = gs_packagekit_task_get_instance_private (task);
 
        g_weak_ref_clear (&priv->plugin_weakref);
+       g_clear_object (&priv->helper);
 
        G_OBJECT_CLASS (gs_packagekit_task_parent_class)->finalize (object);
 }
@@ -251,3 +254,29 @@ gs_packagekit_task_get_action (GsPackagekitTask *task)
 
        return priv->action;
 }
+
+void
+gs_packagekit_task_take_helper (GsPackagekitTask *task,
+                               GsPackagekitHelper *helper)
+{
+       GsPackagekitTaskPrivate *priv = gs_packagekit_task_get_instance_private (task);
+
+       g_return_if_fail (GS_IS_PACKAGEKIT_TASK (task));
+
+       if (priv->helper != helper) {
+               g_clear_object (&priv->helper);
+               priv->helper = helper;
+       } else {
+               g_clear_object (&helper);
+       }
+}
+
+GsPackagekitHelper *
+gs_packagekit_task_get_helper (GsPackagekitTask *task)
+{
+       GsPackagekitTaskPrivate *priv = gs_packagekit_task_get_instance_private (task);
+
+       g_return_val_if_fail (GS_IS_PACKAGEKIT_TASK (task), NULL);
+
+       return priv->helper;
+}
diff --git a/plugins/packagekit/gs-packagekit-task.h b/plugins/packagekit/gs-packagekit-task.h
index 62b67ebf0..ff4bcc60f 100644
--- a/plugins/packagekit/gs-packagekit-task.h
+++ b/plugins/packagekit/gs-packagekit-task.h
@@ -12,6 +12,8 @@
 #include <gnome-software.h>
 #include <packagekit-glib2/packagekit.h>
 
+#include "gs-packagekit-helper.h"
+
 G_BEGIN_DECLS
 
 #define GS_TYPE_PACKAGEKIT_TASK (gs_packagekit_task_get_type ())
@@ -28,5 +30,9 @@ void           gs_packagekit_task_setup       (GsPackagekitTask       *task,
                                                 GsPluginAction          action,
                                                 gboolean                interactive);
 GsPluginAction  gs_packagekit_task_get_action  (GsPackagekitTask       *task);
+void            gs_packagekit_task_take_helper (GsPackagekitTask       *task,
+                                                GsPackagekitHelper     *helper);
+GsPackagekitHelper *
+                gs_packagekit_task_get_helper  (GsPackagekitTask       *task);
 
 G_END_DECLS


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