[gnome-builder] git: add synchronous form to access service



commit 1e1290af948d332b7e2ee29f046c9b328ae46719
Author: Christian Hergert <chergert redhat com>
Date:   Wed Apr 10 00:28:21 2019 -0700

    git: add synchronous form to access service
    
    This requires spawning a process, but sometimes that is more convenient
    than the async workflow.

 src/plugins/git/gbp-git-client.c | 59 +++++++++++++++++++++++++++++++++++++++-
 src/plugins/git/gbp-git-client.h |  3 ++
 2 files changed, 61 insertions(+), 1 deletion(-)
---
diff --git a/src/plugins/git/gbp-git-client.c b/src/plugins/git/gbp-git-client.c
index 441deb5b9..98b19323c 100644
--- a/src/plugins/git/gbp-git-client.c
+++ b/src/plugins/git/gbp-git-client.c
@@ -90,9 +90,10 @@ gbp_git_client_subprocess_spawned (GbpGitClient            *self,
                                                  G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING,
                                                  NULL, NULL, NULL);
   g_dbus_connection_set_exit_on_close (self->connection, FALSE);
+  g_dbus_connection_start_message_processing (self->connection);
 
   self->service = ipc_git_service_proxy_new_sync (self->connection,
-                                                  G_DBUS_PROXY_FLAGS_NONE,
+                                                  G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
                                                   NULL,
                                                   "/org/gnome/Builder/Git",
                                                   NULL,
@@ -229,6 +230,62 @@ gbp_git_client_from_context (IdeContext *context)
   return ret;
 }
 
+static void
+gbp_git_client_get_service_cb (GObject      *object,
+                               GAsyncResult *result,
+                               gpointer      user_data)
+{
+  GbpGitClient *self = (GbpGitClient *)object;
+  g_autoptr(IpcGitService) service = NULL;
+  g_autoptr(IdeTask) task = user_data;
+  g_autoptr(GError) error = NULL;
+
+  g_assert (GBP_IS_GIT_CLIENT (self));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (IDE_IS_TASK (task));
+
+  if (!(service = gbp_git_client_get_service_finish (self, result, &error)))
+    ide_task_return_error (task, g_steal_pointer (&error));
+  else
+    ide_task_return_object (task, g_steal_pointer (&service));
+}
+
+IpcGitService *
+gbp_git_client_get_service (GbpGitClient  *self,
+                            GCancellable  *cancellable,
+                            GError       **error)
+{
+  g_autoptr(IdeTask) task = NULL;
+  g_autoptr(GMainContext) gcontext = NULL;
+  IpcGitService *ret = NULL;
+
+  g_assert (GBP_IS_GIT_CLIENT (self));
+  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  ide_object_lock (IDE_OBJECT (self));
+  if (self->service != NULL)
+    ret = g_object_ref (self->service);
+  ide_object_unlock (IDE_OBJECT (self));
+
+  if (ret != NULL)
+    return g_steal_pointer (&ret);
+
+  task = ide_task_new (self, cancellable, NULL, NULL);
+  ide_task_set_source_tag (task, gbp_git_client_get_service);
+
+  gcontext = g_main_context_ref_thread_default ();
+
+  gbp_git_client_get_service_async (self,
+                                    cancellable,
+                                    gbp_git_client_get_service_cb,
+                                    g_object_ref (task));
+
+  while (!ide_task_get_completed (task))
+    g_main_context_iteration (gcontext, TRUE);
+
+  return ide_task_propagate_object (task, error);
+}
+
 void
 gbp_git_client_get_service_async (GbpGitClient        *self,
                                   GCancellable        *cancellable,
diff --git a/src/plugins/git/gbp-git-client.h b/src/plugins/git/gbp-git-client.h
index 72004c17c..55fd83ce1 100644
--- a/src/plugins/git/gbp-git-client.h
+++ b/src/plugins/git/gbp-git-client.h
@@ -31,6 +31,9 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (GbpGitClient, gbp_git_client, GBP, GIT_CLIENT, IdeObject)
 
 GbpGitClient  *gbp_git_client_from_context       (IdeContext           *context);
+IpcGitService *gbp_git_client_get_service        (GbpGitClient         *self,
+                                                  GCancellable         *cancellable,
+                                                  GError              **error);
 void           gbp_git_client_get_service_async  (GbpGitClient         *self,
                                                   GCancellable         *cancellable,
                                                   GAsyncReadyCallback   callback,


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