[gnome-online-accounts/wip/rishi/account-remove: 5/10] provider: Add a synchronous version of goa_provider_get_all



commit 37807b46a6233c9509583c186ea40d5c05d1ea16
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu May 26 19:07:01 2016 +0200

    provider: Add a synchronous version of goa_provider_get_all
    
    This will be useful to poke at all available providers when goa-daemon
    starts. Since we are doing this in the early stages of start-up, it
    would be nice to be able to get the list of providers synchronously.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=766733

 src/goabackend/goaprovider-priv.h |    4 +++
 src/goabackend/goaprovider.c      |   44 +++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/src/goabackend/goaprovider-priv.h b/src/goabackend/goaprovider-priv.h
index ae06d95..d5da537 100644
--- a/src/goabackend/goaprovider-priv.h
+++ b/src/goabackend/goaprovider-priv.h
@@ -126,6 +126,10 @@ void        goa_provider_ensure_builtins_loaded                (void);
 
 void        goa_provider_ensure_extension_points_registered    (void);
 
+gboolean    goa_provider_get_all_sync                          (GCancellable            *cancellable,
+                                                                GList                  **out_providers,
+                                                                GError                 **error);
+
 void        goa_provider_remove_account                        (GoaProvider             *self,
                                                                 GoaObject               *object,
                                                                 GCancellable            *cancellable,
diff --git a/src/goabackend/goaprovider.c b/src/goabackend/goaprovider.c
index 336bbcb..3985f64 100644
--- a/src/goabackend/goaprovider.c
+++ b/src/goabackend/goaprovider.c
@@ -1304,6 +1304,50 @@ goa_provider_get_all_finish (GList        **out_providers,
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+typedef struct
+{
+  GError **error;
+  GList **out_providers;
+  GMainLoop *loop;
+  gboolean op_res;
+} GetAllSyncData;
+
+static void
+provider_get_all_sync_cb (GObject       *source_object,
+                          GAsyncResult  *res,
+                          gpointer       user_data)
+{
+  GetAllSyncData *data = (GetAllSyncData *) user_data;
+
+  data->op_res = goa_provider_get_all_finish (data->out_providers, res, data->error);
+  g_main_loop_quit (data->loop);
+}
+
+gboolean
+goa_provider_get_all_sync (GCancellable  *cancellable,
+                           GList        **out_providers,
+                           GError       **error)
+{
+  GetAllSyncData data;
+
+  data.error = error;
+  data.out_providers = out_providers;
+
+  /* HACK: Since telepathy-glib doesn't use the thread-default
+   * GMainContext for invoking the asynchronous callbacks, we can't
+   * push a new GMainContext here.
+   */
+  data.loop = g_main_loop_new (NULL, FALSE);
+
+  goa_provider_get_all (provider_get_all_sync_cb, &data);
+  g_main_loop_run (data.loop);
+  g_main_loop_unref (data.loop);
+
+  return data.op_res;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
 void
 goa_provider_remove_account (GoaProvider          *self,
                              GoaObject            *object,


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