[gnome-builder] build-command: add deep copy support for command queues



commit 6ba2b8dcc0a98f15e4df6a26945077d723c45a90
Author: Christian Hergert <chergert redhat com>
Date:   Fri Sep 2 20:02:04 2016 -0700

    build-command: add deep copy support for command queues
    
    We need this so we can have independent command queues when duplicating
    configurations (or making a copy for use by build workers).

 libide/buildsystem/ide-build-command-queue.c |   24 ++++++++++++++++++
 libide/buildsystem/ide-build-command-queue.h |    1 +
 libide/buildsystem/ide-build-command.c       |   24 ++++++++++++++++++
 libide/buildsystem/ide-build-command.h       |   34 +++++++++++++------------
 4 files changed, 67 insertions(+), 16 deletions(-)
---
diff --git a/libide/buildsystem/ide-build-command-queue.c b/libide/buildsystem/ide-build-command-queue.c
index f60c14b..d4924c9 100644
--- a/libide/buildsystem/ide-build-command-queue.c
+++ b/libide/buildsystem/ide-build-command-queue.c
@@ -273,3 +273,27 @@ ide_build_command_queue_execute_finish (IdeBuildCommandQueue  *self,
 
   IDE_RETURN (ret);
 }
+
+/**
+ * ide_build_command_queue_copy:
+ *
+ * Returns: (transfer full): An #IdeBuildCommandQueue
+ */
+IdeBuildCommandQueue *
+ide_build_command_queue_copy (IdeBuildCommandQueue *self)
+{
+  IdeBuildCommandQueue *ret;
+
+  g_return_val_if_fail (IDE_IS_BUILD_COMMAND_QUEUE (self), NULL);
+
+  ret = g_object_new (IDE_TYPE_BUILD_COMMAND_QUEUE, NULL);
+
+  for (const GList *iter = self->queue.head; iter; iter = iter->next)
+    {
+      IdeBuildCommand *command = iter->data;
+
+      g_queue_push_tail (&ret->queue, ide_build_command_copy (command));
+    }
+
+  return ret;
+}
diff --git a/libide/buildsystem/ide-build-command-queue.h b/libide/buildsystem/ide-build-command-queue.h
index 583a5d7..0f6ab9c 100644
--- a/libide/buildsystem/ide-build-command-queue.h
+++ b/libide/buildsystem/ide-build-command-queue.h
@@ -46,6 +46,7 @@ void                  ide_build_command_queue_execute_async  (IdeBuildCommandQue
 gboolean              ide_build_command_queue_execute_finish (IdeBuildCommandQueue  *self,
                                                               GAsyncResult          *result,
                                                               GError               **error);
+IdeBuildCommandQueue *ide_build_command_queue_copy           (IdeBuildCommandQueue  *self);
 
 G_END_DECLS
 
diff --git a/libide/buildsystem/ide-build-command.c b/libide/buildsystem/ide-build-command.c
index 6002636..3aa69e3 100644
--- a/libide/buildsystem/ide-build-command.c
+++ b/libide/buildsystem/ide-build-command.c
@@ -220,6 +220,18 @@ ide_build_command_real_run_finish (IdeBuildCommand  *self,
   return g_task_propagate_boolean (G_TASK (result), error);
 }
 
+static IdeBuildCommand *
+ide_build_command_real_copy (IdeBuildCommand *self)
+{
+  IdeBuildCommandPrivate *priv = ide_build_command_get_instance_private (self);
+
+  g_assert (IDE_IS_BUILD_COMMAND (self));
+
+  return g_object_new (G_OBJECT_TYPE (self),
+                       "command-text", priv->command_text,
+                       NULL);
+}
+
 static void
 ide_build_command_finalize (GObject *object)
 {
@@ -278,6 +290,7 @@ ide_build_command_class_init (IdeBuildCommandClass *klass)
   object_class->get_property = ide_build_command_get_property;
   object_class->set_property = ide_build_command_set_property;
 
+  klass->copy = ide_build_command_real_copy;
   klass->run = ide_build_command_real_run;
   klass->run_async = ide_build_command_real_run_async;
   klass->run_finish = ide_build_command_real_run_finish;
@@ -374,3 +387,14 @@ ide_build_command_set_command_text (IdeBuildCommand *self,
       g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_COMMAND_TEXT]);
     }
 }
+
+/**
+ * ide_build_command_copy:
+ *
+ * Returns: (transfer full): An #IdeBuildCommand
+ */
+IdeBuildCommand *
+ide_build_command_copy (IdeBuildCommand *self)
+{
+  return IDE_BUILD_COMMAND_GET_CLASS (self)->copy (self);
+}
diff --git a/libide/buildsystem/ide-build-command.h b/libide/buildsystem/ide-build-command.h
index c62cfdd..2d9d7ab 100644
--- a/libide/buildsystem/ide-build-command.h
+++ b/libide/buildsystem/ide-build-command.h
@@ -33,22 +33,23 @@ struct _IdeBuildCommandClass
 {
   GObjectClass parent_class;
 
-  gboolean  (*run)        (IdeBuildCommand     *self,
-                           IdeRuntime          *runtime,
-                           IdeEnvironment      *environment,
-                           IdeBuildResult      *build_result,
-                           GCancellable        *cancellable,
-                           GError             **error);
-  void      (*run_async)  (IdeBuildCommand     *self,
-                           IdeRuntime          *runtime,
-                           IdeEnvironment      *environment,
-                           IdeBuildResult      *build_result,
-                           GCancellable        *cancellable,
-                           GAsyncReadyCallback  callback,
-                           gpointer             user_data);
-  gboolean  (*run_finish) (IdeBuildCommand     *self,
-                           GAsyncResult        *result,
-                           GError             **error);
+  gboolean         (*run)        (IdeBuildCommand     *self,
+                                  IdeRuntime          *runtime,
+                                  IdeEnvironment      *environment,
+                                  IdeBuildResult      *build_result,
+                                  GCancellable        *cancellable,
+                                  GError             **error);
+  void             (*run_async)  (IdeBuildCommand     *self,
+                                  IdeRuntime          *runtime,
+                                  IdeEnvironment      *environment,
+                                  IdeBuildResult      *build_result,
+                                  GCancellable        *cancellable,
+                                  GAsyncReadyCallback  callback,
+                                  gpointer             user_data);
+  gboolean         (*run_finish) (IdeBuildCommand     *self,
+                                  GAsyncResult        *result,
+                                  GError             **error);
+  IdeBuildCommand *(*copy)       (IdeBuildCommand     *self);
 
   gpointer _reserved1;
   gpointer _reserved2;
@@ -80,6 +81,7 @@ void             ide_build_command_run_async        (IdeBuildCommand      *self,
 gboolean         ide_build_command_run_finish       (IdeBuildCommand      *self,
                                                      GAsyncResult         *result,
                                                      GError              **error);
+IdeBuildCommand *ide_build_command_copy             (IdeBuildCommand      *self);
 
 G_END_DECLS
 


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