[gnome-software/1276-software-became-unresponsive-while-updating-flatpaks] gs-plugin-loader-sync: Avoid code duplication



commit f193fd16c354c3b01be71e723194e47024dae268
Author: Milan Crha <mcrha redhat com>
Date:   Tue Jul 20 19:57:26 2021 +0200

    gs-plugin-loader-sync: Avoid code duplication
    
    No need to duplicate code for the functions, which do exactly
    the same thing. Also corrected parameter indentation.

 lib/gs-plugin-loader-sync.c | 56 ++++++++++++---------------------------------
 1 file changed, 14 insertions(+), 42 deletions(-)
---
diff --git a/lib/gs-plugin-loader-sync.c b/lib/gs-plugin-loader-sync.c
index bf6f076bb..bf83fe224 100644
--- a/lib/gs-plugin-loader-sync.c
+++ b/lib/gs-plugin-loader-sync.c
@@ -19,10 +19,11 @@ typedef struct {
 } GsPluginLoaderHelper;
 
 static void
-_job_process_finish_sync (GsPluginLoader *plugin_loader,
-                         GAsyncResult *res,
-                         GsPluginLoaderHelper *helper)
+_helper_finish_sync (GObject *source_object,
+                    GAsyncResult *res,
+                    gpointer user_data)
 {
+       GsPluginLoaderHelper *helper = user_data;
        helper->res = g_object_ref (res);
        g_main_loop_quit (helper->loop);
 }
@@ -47,7 +48,7 @@ gs_plugin_loader_job_process (GsPluginLoader *plugin_loader,
        gs_plugin_loader_job_process_async (plugin_loader,
                                            plugin_job,
                                            cancellable,
-                                           (GAsyncReadyCallback) _job_process_finish_sync,
+                                           _helper_finish_sync,
                                            &helper);
        g_main_loop_run (helper.loop);
        list = gs_plugin_loader_job_process_finish (plugin_loader,
@@ -64,20 +65,11 @@ gs_plugin_loader_job_process (GsPluginLoader *plugin_loader,
        return list;
 }
 
-static void
-_job_get_categories_finish_sync (GsPluginLoader *plugin_loader,
-                                GAsyncResult *res,
-                                GsPluginLoaderHelper *helper)
-{
-       helper->res = g_object_ref (res);
-       g_main_loop_quit (helper->loop);
-}
-
 GPtrArray *
 gs_plugin_loader_job_get_categories (GsPluginLoader *plugin_loader,
-                                   GsPluginJob *plugin_job,
-                                   GCancellable *cancellable,
-                                   GError **error)
+                                    GsPluginJob *plugin_job,
+                                    GCancellable *cancellable,
+                                    GError **error)
 {
        GsPluginLoaderHelper helper;
        GPtrArray *catlist;
@@ -93,7 +85,7 @@ gs_plugin_loader_job_get_categories (GsPluginLoader *plugin_loader,
        gs_plugin_loader_job_get_categories_async (plugin_loader,
                                                   plugin_job,
                                                   cancellable,
-                                                  (GAsyncReadyCallback) _job_get_categories_finish_sync,
+                                                  _helper_finish_sync,
                                                   &helper);
        g_main_loop_run (helper.loop);
        catlist = gs_plugin_loader_job_get_categories_finish (plugin_loader,
@@ -110,20 +102,11 @@ gs_plugin_loader_job_get_categories (GsPluginLoader *plugin_loader,
        return catlist;
 }
 
-static void
-_job_action_finish_sync (GsPluginLoader *plugin_loader,
-                        GAsyncResult *res,
-                        GsPluginLoaderHelper *helper)
-{
-       helper->res = g_object_ref (res);
-       g_main_loop_quit (helper->loop);
-}
-
 gboolean
 gs_plugin_loader_job_action (GsPluginLoader *plugin_loader,
-                             GsPluginJob *plugin_job,
-                             GCancellable *cancellable,
-                             GError **error)
+                            GsPluginJob *plugin_job,
+                            GCancellable *cancellable,
+                            GError **error)
 {
        GsPluginLoaderHelper helper;
        gboolean ret;
@@ -139,7 +122,7 @@ gs_plugin_loader_job_action (GsPluginLoader *plugin_loader,
        gs_plugin_loader_job_process_async (plugin_loader,
                                            plugin_job,
                                            cancellable,
-                                           (GAsyncReadyCallback) _job_action_finish_sync,
+                                           _helper_finish_sync,
                                            &helper);
        g_main_loop_run (helper.loop);
        ret = gs_plugin_loader_job_action_finish (plugin_loader,
@@ -156,17 +139,6 @@ gs_plugin_loader_job_action (GsPluginLoader *plugin_loader,
        return ret;
 }
 
-static void
-_job_process_app_finish_sync (GObject *source_object,
-                             GAsyncResult *res,
-                             gpointer user_data)
-{
-       GsPluginLoaderHelper *helper = (GsPluginLoaderHelper *) user_data;
-
-       helper->res = g_object_ref (res);
-       g_main_loop_quit (helper->loop);
-}
-
 GsApp *
 gs_plugin_loader_job_process_app (GsPluginLoader *plugin_loader,
                                  GsPluginJob *plugin_job,
@@ -188,7 +160,7 @@ gs_plugin_loader_job_process_app (GsPluginLoader *plugin_loader,
        gs_plugin_loader_job_process_async (plugin_loader,
                                            plugin_job,
                                            cancellable,
-                                           _job_process_app_finish_sync,
+                                           _helper_finish_sync,
                                            &helper);
        g_main_loop_run (helper.loop);
        list = gs_plugin_loader_job_process_finish (plugin_loader,


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