[gnome-builder] foundry: add cancellable for test-manager
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] foundry: add cancellable for test-manager
- Date: Sun, 28 Apr 2019 00:42:35 +0000 (UTC)
commit 5842129fb7b234772226b18ce065a25e29606356
Author: Christian Hergert <chergert redhat com>
Date: Sat Apr 27 17:41:54 2019 -0700
foundry: add cancellable for test-manager
This allows using a common GCancellable for the test-manager tests to
execute.
src/libide/foundry/ide-test-manager.c | 63 ++++++++++++++++++++++++++++++++
src/libide/foundry/ide-test-manager.h | 2 +
src/plugins/testui/gbp-test-tree-addin.c | 2 +-
3 files changed, 66 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/foundry/ide-test-manager.c b/src/libide/foundry/ide-test-manager.c
index 9b4486e80..69d2a79e9 100644
--- a/src/libide/foundry/ide-test-manager.c
+++ b/src/libide/foundry/ide-test-manager.c
@@ -58,8 +58,10 @@ struct _IdeTestManager
PeasExtensionSet *providers;
GPtrArray *tests_by_provider;
GtkTreeStore *tests_store;
+ GCancellable *cancellable;
VtePty *pty;
gint child_pty;
+ gint n_active;
};
typedef struct
@@ -85,8 +87,11 @@ static void ide_test_manager_actions_run_all (IdeTestManager *self,
GVariant *param);
static void ide_test_manager_actions_reload (IdeTestManager *self,
GVariant *param);
+static void ide_test_manager_actions_cancel (IdeTestManager *self,
+ GVariant *param);
DZL_DEFINE_ACTION_GROUP (IdeTestManager, ide_test_manager, {
+ { "cancel", ide_test_manager_actions_cancel },
{ "run-all", ide_test_manager_actions_run_all },
{ "reload-tests", ide_test_manager_actions_reload },
})
@@ -125,6 +130,9 @@ ide_test_manager_destroy (IdeObject *object)
g_clear_object (&self->tests_store);
}
+ g_cancellable_cancel (self->cancellable);
+ g_clear_object (&self->cancellable);
+
g_clear_object (&self->providers);
g_clear_pointer (&self->tests_by_provider, g_ptr_array_unref);
@@ -184,8 +192,11 @@ static void
ide_test_manager_init (IdeTestManager *self)
{
self->child_pty = -1;
+ self->cancellable = g_cancellable_new ();
self->tests_by_provider = g_ptr_array_new_with_free_func (tests_by_provider_free);
self->tests_store = gtk_tree_store_new (2, G_TYPE_STRING, IDE_TYPE_TEST);
+
+ ide_test_manager_set_action_enabled (self, "cancel", FALSE);
}
static void
@@ -669,6 +680,20 @@ ide_test_manager_run_all_finish (IdeTestManager *self,
IDE_RETURN (ret);
}
+static void
+run_task_completed_cb (IdeTestManager *self,
+ GParamSpec *pspec,
+ IdeTask *task)
+{
+ g_assert (IDE_IS_TEST_MANAGER (self));
+ g_assert (G_IS_TASK (task));
+ g_assert (self->n_active > 0);
+
+ self->n_active--;
+
+ ide_test_manager_set_action_enabled (self, "cancel", self->n_active > 0);
+}
+
static void
ide_test_manager_run_cb (GObject *object,
GAsyncResult *result,
@@ -730,6 +755,14 @@ ide_test_manager_run_async (IdeTestManager *self,
g_task_set_priority (task, G_PRIORITY_LOW);
g_task_set_source_tag (task, ide_test_manager_run_async);
+ self->n_active++;
+ g_signal_connect_object (task,
+ "notify::completed",
+ G_CALLBACK (run_task_completed_cb),
+ self,
+ G_CONNECT_SWAPPED);
+ ide_test_manager_set_action_enabled (self, "cancel", TRUE);
+
context = ide_object_get_context (IDE_OBJECT (self));
build_manager = ide_build_manager_from_context (context);
pipeline = ide_build_manager_get_pipeline (build_manager);
@@ -1090,3 +1123,33 @@ ide_test_manager_open_pty (IdeTestManager *self)
return dup (self->child_pty);
}
+
+/**
+ * ide_test_manager_get_cancellable:
+ * @self: a #IdeTestManager
+ *
+ * Gets the cancellable for the test manager which will be cancelled
+ * when the cancel action is called.
+ *
+ * Returns: (transfer none): a #GCancellable
+ *
+ * Since: 3.34
+ */
+GCancellable *
+ide_test_manager_get_cancellable (IdeTestManager *self)
+{
+ g_return_val_if_fail (IDE_IS_TEST_MANAGER (self), NULL);
+
+ return self->cancellable;
+}
+
+static void
+ide_test_manager_actions_cancel (IdeTestManager *self,
+ GVariant *param)
+{
+ g_assert (IDE_IS_TEST_MANAGER (self));
+
+ g_cancellable_cancel (self->cancellable);
+ g_clear_object (&self->cancellable);
+ self->cancellable = g_cancellable_new ();
+}
diff --git a/src/libide/foundry/ide-test-manager.h b/src/libide/foundry/ide-test-manager.h
index bbbf950df..edb3e28b5 100644
--- a/src/libide/foundry/ide-test-manager.h
+++ b/src/libide/foundry/ide-test-manager.h
@@ -69,6 +69,8 @@ GPtrArray *ide_test_manager_get_tests (IdeTestManager *se
IDE_AVAILABLE_IN_3_32
gchar **ide_test_manager_get_folders (IdeTestManager *self,
const gchar *path);
+IDE_AVAILABLE_IN_3_34
+GCancellable *ide_test_manager_get_cancellable (IdeTestManager *self);
IDE_AVAILABLE_IN_3_32
void ide_test_manager_ensure_loaded_async (IdeTestManager *self,
GCancellable *cancellable,
diff --git a/src/plugins/testui/gbp-test-tree-addin.c b/src/plugins/testui/gbp-test-tree-addin.c
index 6b54fdeba..ddd4638c1 100644
--- a/src/plugins/testui/gbp-test-tree-addin.c
+++ b/src/plugins/testui/gbp-test-tree-addin.c
@@ -420,7 +420,7 @@ gbp_test_tree_addin_node_activated (IdeTreeAddin *addin,
ide_test_manager_run_async (test_manager,
test,
- NULL,
+ ide_test_manager_get_cancellable (test_manager),
gbp_test_tree_addin_run_cb,
g_steal_pointer (&task));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]