[gnome-online-accounts/gnome-3-20] daemon: Add a synchronous version	of goa_provider_get_all
- From: Debarshi Ray <debarshir src gnome org>
 
- To: commits-list gnome org
 
- Cc: 
 
- Subject: [gnome-online-accounts/gnome-3-20] daemon: Add a synchronous version	of goa_provider_get_all
 
- Date: Thu, 14 Jul 2016 16:52:52 +0000 (UTC)
 
commit 77abfdae065f0196748ff6d11da839ed03936415
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu May 26 19:07:01 2016 +0200
    daemon: 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.
    
    This function is not suitable for wider use because we can't push a
    new thread-default GMainContext due to limitations (or bugs) inside
    telepathy-glib.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=766733
 src/daemon/goadaemon.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c
index 0540ba8..155f9e9 100644
--- a/src/daemon/goadaemon.c
+++ b/src/daemon/goadaemon.c
@@ -89,6 +89,52 @@ static void goa_daemon_reload_configuration (GoaDaemon *self);
 
 G_DEFINE_TYPE (GoaDaemon, goa_daemon, G_TYPE_OBJECT);
 
+/* ---------------------------------------------------------------------------------------------------- */
+
+typedef struct
+{
+  GError **error;
+  GList **out_providers;
+  GMainLoop *loop;
+  gboolean op_res;
+} GetAllSyncData;
+
+static void
+get_all_providers_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);
+}
+
+static gboolean
+get_all_providers_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 (get_all_providers_sync_cb, &data);
+  g_main_loop_run (data.loop);
+  g_main_loop_unref (data.loop);
+
+  return data.op_res;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
 static void
 goa_daemon_finalize (GObject *object)
 {
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]