[gnome-builder/wip/gtk4-port] libide/foundry: add IdeRunCommand and Provider object/interface
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port] libide/foundry: add IdeRunCommand and Provider object/interface
- Date: Sat, 21 May 2022 02:35:34 +0000 (UTC)
commit df6c6ef9f467a5fef81c58ba5045ec1db390a5ea
Author: Christian Hergert <chergert redhat com>
Date: Fri May 20 19:15:16 2022 -0700
libide/foundry: add IdeRunCommand and Provider object/interface
The goal here is to move a few IdeBuildTargetProvider into
IdeRunCommandProvider so we stop conflating the two.
src/libide/foundry/ide-run-command-provider.c | 64 +++++++
src/libide/foundry/ide-run-command-provider.h | 57 ++++++
src/libide/foundry/ide-run-command.c | 261 ++++++++++++++++++++++++++
src/libide/foundry/ide-run-command.h | 62 ++++++
src/libide/foundry/libide-foundry.h | 2 +
src/libide/foundry/meson.build | 4 +
6 files changed, 450 insertions(+)
---
diff --git a/src/libide/foundry/ide-run-command-provider.c b/src/libide/foundry/ide-run-command-provider.c
new file mode 100644
index 000000000..cefee71ca
--- /dev/null
+++ b/src/libide/foundry/ide-run-command-provider.c
@@ -0,0 +1,64 @@
+/* ide-run-command-provider.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-run-command-provider"
+
+#include "config.h"
+
+#include "ide-run-command-provider.h"
+
+G_DEFINE_INTERFACE (IdeRunCommandProvider, ide_run_command_provider, IDE_TYPE_OBJECT)
+
+static void
+ide_run_command_provider_default_init (IdeRunCommandProviderInterface *iface)
+{
+}
+
+void
+ide_run_command_provider_list_commands_async (IdeRunCommandProvider *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_return_if_fail (IDE_IS_RUN_COMMAND_PROVIDER (self));
+ g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ IDE_RUN_COMMAND_PROVIDER_GET_IFACE (self)->list_commands_async (self, cancellable, callback, user_data);
+}
+
+/**
+ * ide_run_command_provider_list_commands_finish:
+ * @self: a #IdeRunCommandProvider
+ * @result: a #GAsyncResult
+ * @error: location for a #GError
+ *
+ * Completes request to list run commands.
+ *
+ * Returns: (transfer full): a #GListModel of #IdeRunCommand
+ */
+GListModel *
+ide_run_command_provider_list_commands_finish (IdeRunCommandProvider *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (IDE_IS_RUN_COMMAND_PROVIDER (self), NULL);
+
+ return IDE_RUN_COMMAND_PROVIDER_GET_IFACE (self)->list_commands_finish (self, result, error);
+}
diff --git a/src/libide/foundry/ide-run-command-provider.h b/src/libide/foundry/ide-run-command-provider.h
new file mode 100644
index 000000000..e79054289
--- /dev/null
+++ b/src/libide/foundry/ide-run-command-provider.h
@@ -0,0 +1,57 @@
+/* ide-run-command-provider.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#if !defined (IDE_FOUNDRY_INSIDE) && !defined (IDE_FOUNDRY_COMPILATION)
+# error "Only <libide-foundry.h> can be included directly."
+#endif
+
+#include <libide-core.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_RUN_COMMAND_PROVIDER (ide_run_command_provider_get_type())
+
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_INTERFACE (IdeRunCommandProvider, ide_run_command_provider, IDE, RUN_COMMAND_PROVIDER, IdeObject)
+
+struct _IdeRunCommandProviderInterface
+{
+ void (*list_commands_async) (IdeRunCommandProvider *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ GListModel *(*list_commands_finish) (IdeRunCommandProvider *self,
+ GAsyncResult *result,
+ GError **error);
+};
+
+IDE_AVAILABLE_IN_ALL
+void ide_run_command_provider_list_commands_async (IdeRunCommandProvider *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+IDE_AVAILABLE_IN_ALL
+GListModel *ide_run_command_provider_list_commands_finish (IdeRunCommandProvider *self,
+ GAsyncResult *result,
+ GError **error);
+
+G_END_DECLS
diff --git a/src/libide/foundry/ide-run-command.c b/src/libide/foundry/ide-run-command.c
new file mode 100644
index 000000000..ad0fc41a9
--- /dev/null
+++ b/src/libide/foundry/ide-run-command.c
@@ -0,0 +1,261 @@
+/* ide-run-command.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-run-command"
+
+#include "config.h"
+
+#include "ide-run-command.h"
+
+typedef struct
+{
+ char *display_name;
+ char **env;
+ char **argv;
+ int priority;
+} IdeRunCommandPrivate;
+
+enum {
+ PROP_0,
+ PROP_ARGV,
+ PROP_DISPLAY_NAME,
+ PROP_ENV,
+ PROP_PRIORITY,
+ N_PROPS
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (IdeRunCommand, ide_run_command, G_TYPE_OBJECT)
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+ide_run_command_finalize (GObject *object)
+{
+ IdeRunCommand *self = (IdeRunCommand *)object;
+ IdeRunCommandPrivate *priv = ide_run_command_get_instance_private (self);
+
+ g_clear_pointer (&priv->display_name, g_free);
+ g_clear_pointer (&priv->env, g_strfreev);
+ g_clear_pointer (&priv->argv, g_strfreev);
+
+ G_OBJECT_CLASS (ide_run_command_parent_class)->finalize (object);
+}
+
+static void
+ide_run_command_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ IdeRunCommand *self = IDE_RUN_COMMAND (object);
+
+ switch (prop_id)
+ {
+ case PROP_DISPLAY_NAME:
+ g_value_set_string (value, ide_run_command_get_display_name (self));
+ break;
+
+ case PROP_ARGV:
+ g_value_set_boxed (value, ide_run_command_get_argv (self));
+ break;
+
+ case PROP_ENV:
+ g_value_set_boxed (value, ide_run_command_get_env (self));
+ break;
+
+ case PROP_PRIORITY:
+ g_value_set_int (value, ide_run_command_get_priority (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ide_run_command_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ IdeRunCommand *self = IDE_RUN_COMMAND (object);
+
+ switch (prop_id)
+ {
+ case PROP_DISPLAY_NAME:
+ ide_run_command_set_display_name (self, g_value_get_string (value));
+ break;
+
+ case PROP_ARGV:
+ ide_run_command_set_argv (self, g_value_get_boxed (value));
+ break;
+
+ case PROP_ENV:
+ ide_run_command_set_env (self, g_value_get_boxed (value));
+ break;
+
+ case PROP_PRIORITY:
+ ide_run_command_set_priority (self, g_value_get_int (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ide_run_command_class_init (IdeRunCommandClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = ide_run_command_finalize;
+ object_class->get_property = ide_run_command_get_property;
+ object_class->set_property = ide_run_command_set_property;
+
+ properties [PROP_ARGV] =
+ g_param_spec_boxed ("argv", NULL, NULL,
+ G_TYPE_STRV,
+ (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+ properties [PROP_DISPLAY_NAME] =
+ g_param_spec_string ("display-name", NULL, NULL,
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+ properties [PROP_ENV] =
+ g_param_spec_boxed ("env", NULL, NULL,
+ G_TYPE_STRV,
+ (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+ properties [PROP_PRIORITY] =
+ g_param_spec_int ("priority", NULL, NULL,
+ G_MININT, G_MAXINT, 0,
+ (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+ide_run_command_init (IdeRunCommand *self)
+{
+}
+
+const char *
+ide_run_command_get_display_name (IdeRunCommand *self)
+{
+ IdeRunCommandPrivate *priv = ide_run_command_get_instance_private (self);
+
+ g_return_val_if_fail (IDE_IS_RUN_COMMAND (self), NULL);
+
+ return priv->display_name;
+}
+
+void
+ide_run_command_set_display_name (IdeRunCommand *self,
+ const char *display_name)
+{
+ IdeRunCommandPrivate *priv = ide_run_command_get_instance_private (self);
+
+ g_return_if_fail (IDE_IS_RUN_COMMAND (self));
+
+ if (g_strcmp0 (priv->display_name, display_name) != 0)
+ {
+ g_free (priv->display_name);
+ priv->display_name = g_strdup (display_name);
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_DISPLAY_NAME]);
+ }
+}
+
+const char * const *
+ide_run_command_get_argv (IdeRunCommand *self)
+{
+ IdeRunCommandPrivate *priv = ide_run_command_get_instance_private (self);
+
+ g_return_val_if_fail (IDE_IS_RUN_COMMAND (self), NULL);
+
+ return (const char * const *)priv->argv;
+}
+
+void
+ide_run_command_set_argv (IdeRunCommand *self,
+ const char * const *argv)
+{
+ IdeRunCommandPrivate *priv = ide_run_command_get_instance_private (self);
+
+ g_return_if_fail (IDE_IS_RUN_COMMAND (self));
+
+ if (argv == (const char * const *)priv->argv)
+ return;
+
+ g_strfreev (priv->argv);
+ priv->argv = g_strdupv ((char **)argv);
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ARGV]);
+}
+
+const char * const *
+ide_run_command_get_env (IdeRunCommand *self)
+{
+ IdeRunCommandPrivate *priv = ide_run_command_get_instance_private (self);
+
+ g_return_val_if_fail (IDE_IS_RUN_COMMAND (self), NULL);
+
+ return (const char * const *)priv->env;
+}
+
+void
+ide_run_command_set_env (IdeRunCommand *self,
+ const char * const *env)
+{
+ IdeRunCommandPrivate *priv = ide_run_command_get_instance_private (self);
+
+ g_return_if_fail (IDE_IS_RUN_COMMAND (self));
+
+ if (env == (const char * const *)priv->env)
+ return;
+
+ g_strfreev (priv->env);
+ priv->env = g_strdupv ((char **)env);
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ENV]);
+}
+
+int
+ide_run_command_get_priority (IdeRunCommand *self)
+{
+ IdeRunCommandPrivate *priv = ide_run_command_get_instance_private (self);
+
+ g_return_val_if_fail (IDE_IS_RUN_COMMAND (self), -1);
+
+ return priv->priority;
+}
+
+void
+ide_run_command_set_priority (IdeRunCommand *self,
+ int priority)
+{
+ IdeRunCommandPrivate *priv = ide_run_command_get_instance_private (self);
+
+ g_return_if_fail (IDE_IS_RUN_COMMAND (self));
+
+ if (priority != priv->priority)
+ {
+ priv->priority = priority;
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PRIORITY]);
+ }
+}
diff --git a/src/libide/foundry/ide-run-command.h b/src/libide/foundry/ide-run-command.h
new file mode 100644
index 000000000..a863dc5cd
--- /dev/null
+++ b/src/libide/foundry/ide-run-command.h
@@ -0,0 +1,62 @@
+/* ide-run-command.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#if !defined (IDE_FOUNDRY_INSIDE) && !defined (IDE_FOUNDRY_COMPILATION)
+# error "Only <libide-foundry.h> can be included directly."
+#endif
+
+#include <libide-core.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_RUN_COMMAND (ide_run_command_get_type())
+
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_DERIVABLE_TYPE (IdeRunCommand, ide_run_command, IDE, RUN_COMMAND, GObject)
+
+struct _IdeRunCommandClass
+{
+ GObjectClass parent_class;
+};
+
+IDE_AVAILABLE_IN_ALL
+const char *ide_run_command_get_display_name (IdeRunCommand *self);
+IDE_AVAILABLE_IN_ALL
+void ide_run_command_set_display_name (IdeRunCommand *self,
+ const char *display_name);
+IDE_AVAILABLE_IN_ALL
+const char * const *ide_run_command_get_argv (IdeRunCommand *self);
+IDE_AVAILABLE_IN_ALL
+void ide_run_command_set_argv (IdeRunCommand *self,
+ const char * const *argv);
+IDE_AVAILABLE_IN_ALL
+const char * const *ide_run_command_get_env (IdeRunCommand *self);
+IDE_AVAILABLE_IN_ALL
+void ide_run_command_set_env (IdeRunCommand *self,
+ const char * const *env);
+IDE_AVAILABLE_IN_ALL
+int ide_run_command_get_priority (IdeRunCommand *self);
+IDE_AVAILABLE_IN_ALL
+void ide_run_command_set_priority (IdeRunCommand *self,
+ int priority);
+
+G_END_DECLS
diff --git a/src/libide/foundry/libide-foundry.h b/src/libide/foundry/libide-foundry.h
index b08361d60..ad8035a79 100644
--- a/src/libide/foundry/libide-foundry.h
+++ b/src/libide/foundry/libide-foundry.h
@@ -55,6 +55,8 @@ G_BEGIN_DECLS
#include "ide-pipeline-stage-transfer.h"
#include "ide-pipeline-stage.h"
#include "ide-pipeline.h"
+#include "ide-run-command.h"
+#include "ide-run-command-provider.h"
#include "ide-run-manager.h"
#include "ide-runner-addin.h"
#include "ide-runner.h"
diff --git a/src/libide/foundry/meson.build b/src/libide/foundry/meson.build
index 2e9e1652b..1167a13fd 100644
--- a/src/libide/foundry/meson.build
+++ b/src/libide/foundry/meson.build
@@ -40,6 +40,8 @@ libide_foundry_public_headers = [
'ide-pipeline-stage-transfer.h',
'ide-pipeline-stage.h',
'ide-pipeline.h',
+ 'ide-run-command.h',
+ 'ide-run-command-provider.h',
'ide-run-manager.h',
'ide-runner-addin.h',
'ide-runner.h',
@@ -114,6 +116,8 @@ libide_foundry_public_sources = [
'ide-pipeline-stage-transfer.c',
'ide-pipeline-stage.c',
'ide-pipeline.c',
+ 'ide-run-command.c',
+ 'ide-run-command-provider.c',
'ide-run-manager.c',
'ide-runner-addin.c',
'ide-runner.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]