[gnome-online-accounts] Port goa_provider_factory_get_providers() to GTask



commit 37b39b83304c9333bb71eda48e5a9fe8f1a7dcf7
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Mon Nov 23 18:31:53 2015 +0100

    Port goa_provider_factory_get_providers() to GTask
    
    https://bugzilla.gnome.org/show_bug.cgi?id=764157

 src/goabackend/goaproviderfactory.c  |   21 +++++++++++++--------
 src/goabackend/goaproviderfactory.h  |    2 +-
 src/goabackend/goatelepathyfactory.c |   20 ++++++++------------
 3 files changed, 22 insertions(+), 21 deletions(-)
---
diff --git a/src/goabackend/goaproviderfactory.c b/src/goabackend/goaproviderfactory.c
index 5c51ceb..a0df2a2 100644
--- a/src/goabackend/goaproviderfactory.c
+++ b/src/goabackend/goaproviderfactory.c
@@ -100,7 +100,7 @@ goa_provider_factory_get_providers (GoaProviderFactory  *factory,
  * Finishes an operation started with goa_provider_factory_get_providers()
  *
  * This is a virtual method that subclasses may implement. The default implementation is suitable for
- * #GSimpleAsyncResult an implementation of goa_provider_factory_get_providers() using #GSimpleAsyncResult.
+ * an implementation of goa_provider_factory_get_providers() using #GTask.
  *
  * Returns: %TRUE if the list was successfully retrieved, %FALSE if @error is set.
  */
@@ -124,22 +124,27 @@ get_providers_finish_default (GoaProviderFactory  *factory,
                               GAsyncResult        *result,
                               GError             **error)
 {
-
-  GSimpleAsyncResult *simple = (GSimpleAsyncResult *) result;
+  GTask *task;
   GList *providers;
+  gboolean had_error;
+
+  g_return_val_if_fail (g_task_is_valid (result, factory), FALSE);
 
-  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (factory), NULL),
-      FALSE);
+  task = G_TASK (result);
 
-  if (g_simple_async_result_propagate_error (simple, error))
+  /* Workaround for bgo#764163 */
+  had_error = g_task_had_error (task);
+  providers = g_task_propagate_pointer (task, error);
+  if (had_error)
     return FALSE;
 
   if (out_providers != NULL)
     {
-      providers = g_simple_async_result_get_op_res_gpointer (simple);
-      *out_providers = g_list_copy_deep (providers, (GCopyFunc) g_object_ref, NULL);
+      *out_providers = providers;
+      providers = NULL;
     }
 
+  g_list_free_full (providers, g_object_unref);
   return TRUE;
 }
 
diff --git a/src/goabackend/goaproviderfactory.h b/src/goabackend/goaproviderfactory.h
index a4918af..d5d87db 100644
--- a/src/goabackend/goaproviderfactory.h
+++ b/src/goabackend/goaproviderfactory.h
@@ -69,7 +69,7 @@ struct _GoaProviderFactoryClass
                                              const gchar           *provider_name);
 
   /* The async method is mandatory to implement, but _finish has a default
-   * implementation suitable for a GSimpleAsyncResult. */
+   * implementation suitable for a GTask. */
   void         (*get_providers)             (GoaProviderFactory    *factory,
                                              GAsyncReadyCallback    callback,
                                              gpointer               user_data);
diff --git a/src/goabackend/goatelepathyfactory.c b/src/goabackend/goatelepathyfactory.c
index be28690..caa04e4 100644
--- a/src/goabackend/goatelepathyfactory.c
+++ b/src/goabackend/goatelepathyfactory.c
@@ -67,7 +67,7 @@ get_protocols_cb (GObject      *source,
                   GAsyncResult *res,
                   gpointer      user_data)
 {
-  GSimpleAsyncResult *outer_result = user_data;
+  GTask *outer_task = user_data;
   GList *protocols = NULL;
   GList *ret;
   GList *l;
@@ -80,9 +80,8 @@ get_protocols_cb (GObject      *source,
 
   if (!tpaw_protocol_get_all_finish (&protocols, res, &error))
     {
-      g_simple_async_result_take_error (outer_result, error);
-      g_simple_async_result_complete_in_idle (outer_result);
-      g_object_unref (outer_result);
+      g_task_return_error (outer_task, error);
+      g_object_unref (outer_task);
       return;
     }
 
@@ -117,10 +116,8 @@ get_protocols_cb (GObject      *source,
   ret = g_list_reverse (ret);
   g_list_free_full (protocols, g_object_unref);
 
-  g_simple_async_result_set_op_res_gpointer (outer_result, ret, free_list_and_unref);
-  g_simple_async_result_complete_in_idle (outer_result);
-
-  g_object_unref (outer_result);
+  g_task_return_pointer (outer_task, ret, free_list_and_unref);
+  g_object_unref (outer_task);
 }
 
 static void
@@ -128,13 +125,12 @@ get_providers (GoaProviderFactory  *factory,
                GAsyncReadyCallback  callback,
                gpointer             user_data)
 {
-  GSimpleAsyncResult *result;
+  GTask *task;
 
   g_return_if_fail (GOA_IS_TELEPATHY_FACTORY (factory));
 
-  result = g_simple_async_result_new (G_OBJECT (factory), callback, user_data,
-      get_providers);
-  tpaw_protocol_get_all_async (get_protocols_cb, result);
+  task = g_task_new (factory, NULL, callback, user_data);
+  tpaw_protocol_get_all_async (get_protocols_cb, task);
 }
 
 /* ---------------------------------------------------------------------------------------------------- */


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