[gnome-software/wip/async-plugin-repo-funcs: 3/29] gs-plugin-helpers: Add helper for manage repository job




commit a3ad0cd5d4bd8ba17ad58f3c594b9f520f4927d3
Author: Milan Crha <mcrha redhat com>
Date:   Tue Jun 14 14:41:02 2022 +0200

    gs-plugin-helpers: Add helper for manage repository job

 lib/gs-plugin-helpers.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++
 lib/gs-plugin-helpers.h | 17 ++++++++++++
 2 files changed, 86 insertions(+)
---
diff --git a/lib/gs-plugin-helpers.c b/lib/gs-plugin-helpers.c
index 753e9415e..5711cf985 100644
--- a/lib/gs-plugin-helpers.c
+++ b/lib/gs-plugin-helpers.c
@@ -199,3 +199,72 @@ gs_plugin_list_apps_data_free (GsPluginListAppsData *data)
        g_clear_object (&data->query);
        g_free (data);
 }
+
+/**
+ * gs_plugin_manage_repository_data_new:
+ * @repository: (not-nullable) (transfer none): a repository to manage
+ * @flags: manage repository flags
+ *
+ * Common context data for a call to #GsPluginClass.install_repository_async,
+ * #GsPluginClass.remove_repository_async, #GsPluginClass.enable_repository_async
+ * and #GsPluginClass.disable_repository_async.
+ *
+ * Returns: (transfer full): context data structure
+ * Since: 43
+ */
+GsPluginManageRepositoryData *
+gs_plugin_manage_repository_data_new (GsApp                       *repository,
+                                     GsPluginManageRepositoryFlags flags)
+{
+       g_autoptr(GsPluginManageRepositoryData) data = g_new0 (GsPluginManageRepositoryData, 1);
+       data->repository = g_object_ref (repository);
+       data->flags = flags;
+
+       return g_steal_pointer (&data);
+}
+
+/**
+ * gs_plugin_manage_repository_data_new_task:
+ * @source_object: task source object
+ * @repository: (not-nullable) (transfer none): a repository to manage
+ * @flags: manage repository flags
+ * @cancellable: (nullable): a #GCancellable, or %NULL
+ * @callback: function to call once asynchronous operation is finished
+ * @user_data: data to pass to @callback
+ *
+ * Create a #GTask for a manage repository operation with the given arguments. The task
+ * data will be set to a #GsPluginManageRepositoryData containing the given context.
+ *
+ * This is essentially a combination of gs_plugin_manage_repository_data_new(),
+ * g_task_new() and g_task_set_task_data().
+ *
+ * Returns: (transfer full): new #GTask with the given context data
+ * Since: 43
+ */
+GTask *
+gs_plugin_manage_repository_data_new_task (gpointer                     source_object,
+                                          GsApp                        *repository,
+                                          GsPluginManageRepositoryFlags flags,
+                                          GCancellable                 *cancellable,
+                                          GAsyncReadyCallback           callback,
+                                          gpointer                      user_data)
+{
+       g_autoptr(GTask) task = g_task_new (source_object, cancellable, callback, user_data);
+       g_task_set_task_data (task, gs_plugin_manage_repository_data_new (repository, flags), 
(GDestroyNotify) gs_plugin_manage_repository_data_free);
+       return g_steal_pointer (&task);
+}
+
+/**
+ * gs_plugin_manage_repository_data_free:
+ * @data: (transfer full): a #GsPluginManageRepositoryData
+ *
+ * Free the given @data.
+ *
+ * Since: 43
+ */
+void
+gs_plugin_manage_repository_data_free (GsPluginManageRepositoryData *data)
+{
+       g_clear_object (&data->repository);
+       g_free (data);
+}
diff --git a/lib/gs-plugin-helpers.h b/lib/gs-plugin-helpers.h
index 3d7f2347b..78c0697ca 100644
--- a/lib/gs-plugin-helpers.h
+++ b/lib/gs-plugin-helpers.h
@@ -60,4 +60,21 @@ GTask *gs_plugin_list_apps_data_new_task (gpointer               source_object,
 void gs_plugin_list_apps_data_free (GsPluginListAppsData *data);
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GsPluginListAppsData, gs_plugin_list_apps_data_free)
 
+typedef struct {
+       GsApp *repository;  /* (owned) (nullable) */
+       GsPluginManageRepositoryFlags flags;
+} GsPluginManageRepositoryData;
+
+GsPluginManageRepositoryData *
+               gs_plugin_manage_repository_data_new            (GsApp                          *repository,
+                                                                GsPluginManageRepositoryFlags   flags);
+GTask *                gs_plugin_manage_repository_data_new_task       (gpointer                        
source_object,
+                                                                GsApp                          *repository,
+                                                                GsPluginManageRepositoryFlags   flags,
+                                                                GCancellable                   *cancellable,
+                                                                GAsyncReadyCallback             callback,
+                                                                gpointer                        user_data);
+void           gs_plugin_manage_repository_data_free           (GsPluginManageRepositoryData   *data);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GsPluginManageRepositoryData, gs_plugin_manage_repository_data_free)
+
 G_END_DECLS


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