[gnome-builder/wip/chergert/dspy] wip
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/dspy] wip
- Date: Thu, 11 Apr 2019 21:41:41 +0000 (UTC)
commit e1d070aff4627b7601a01da76ea1815ce6262641
Author: Christian Hergert <chergert redhat com>
Date: Thu Apr 11 14:41:12 2019 -0700
wip
meson_options.txt | 1 +
src/plugins/dspy/dspy-connection-model.c | 354 ++++++++++++++++++++++++++++
src/plugins/dspy/dspy-connection-model.h | 36 +++
src/plugins/dspy/dspy-plugin.c | 34 +++
src/plugins/dspy/dspy.gresource.xml | 7 +
src/plugins/dspy/dspy.plugin | 9 +
src/plugins/dspy/gbp-dspy-workspace-addin.c | 66 ++++++
src/plugins/dspy/gbp-dspy-workspace-addin.h | 31 +++
src/plugins/dspy/gtk/menus.ui | 3 +
src/plugins/dspy/meson.build | 17 ++
src/plugins/meson.build | 2 +
11 files changed, 560 insertions(+)
---
diff --git a/meson_options.txt b/meson_options.txt
index 57fe9301c..3d6fc2e40 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -31,6 +31,7 @@ option('plugin_color_picker', type: 'boolean')
option('plugin_ctags', type: 'boolean')
option('plugin_devhelp', type: 'boolean')
option('plugin_deviced', type: 'boolean', value: false)
+option('plugin_dspy', type: 'boolean')
option('plugin_editorconfig', type: 'boolean')
option('plugin_eslint', type: 'boolean')
option('plugin_file_search', type: 'boolean')
diff --git a/src/plugins/dspy/dspy-connection-model.c b/src/plugins/dspy/dspy-connection-model.c
new file mode 100644
index 000000000..57e82115e
--- /dev/null
+++ b/src/plugins/dspy/dspy-connection-model.c
@@ -0,0 +1,354 @@
+/* dspy-connection-model.c
+ *
+ * Copyright 2019 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 "dspy-connection-model"
+
+#include "config.h"
+
+#include "dspy-connection-model.h"
+
+struct _DspyConnectionModel
+{
+ GObject parent;
+
+ GDBusConnection *connection;
+ GCancellable *cancellable;
+ GSequence *peers;
+ GDBusProxy *bus_proxy;
+
+ guint name_owner_changed_handler;
+};
+
+enum {
+ PROP_0,
+ PROP_CONNECTION,
+ N_PROPS
+};
+
+static guint
+dspy_connection_model_get_n_items (GListModel *model)
+{
+ DspyConnectionModel *self = DSPY_CONNECTION_MODEL (model);
+ return g_sequence_get_length (self->peers);
+}
+
+static GType
+dspy_connection_model_get_item_type (GListModel *model)
+{
+ /* XXX: switch to type */
+ return G_TYPE_OBJECT;
+}
+
+static gpointer
+dspy_connection_model_get_item (GListModel *model,
+ guint position)
+{
+ DspyConnectionModel *self = DSPY_CONNECTION_MODEL (model);
+ GSequenceIter *iter = g_sequence_get_iter_at_pos (self->peers, position);
+
+ if (g_sequence_iter_is_end (iter))
+ return NULL;
+
+ return g_object_ref (g_sequence_get (iter));
+}
+
+static void
+list_model_iface_init (GListModelInterface *iface)
+{
+ iface->get_item_type = dspy_connection_model_get_item_type;
+ iface->get_n_items = dspy_connection_model_get_n_items;
+ iface->get_item = dspy_connection_model_get_item;
+}
+
+G_DEFINE_TYPE_WITH_CODE (DspyConnectionModel, dspy_connection_model, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, list_model_iface_init))
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+dspy_connection_model_finalize (GObject *object)
+{
+ DspyConnectionModel *self = (DspyConnectionModel *)object;
+
+ g_assert (self->connection == NULL);
+ g_assert (self->cancellable == NULL);
+
+ g_clear_object (&self->connection);
+ g_clear_object (&self->cancellable);
+ g_clear_pointer (&self->peers, g_sequence_free);
+
+ G_OBJECT_CLASS (dspy_connection_model_parent_class)->finalize (object);
+}
+
+static void
+dspy_connection_model_dispose (GObject *object)
+{
+ DspyConnectionModel *self = (DspyConnectionModel *)object;
+
+ dspy_connection_model_set_connection (self, NULL);
+
+ G_OBJECT_CLASS (dspy_connection_model_parent_class)->dispose (object);
+}
+
+static void
+dspy_connection_model_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ DspyConnectionModel *self = DSPY_CONNECTION_MODEL (object);
+
+ switch (prop_id)
+ {
+ case PROP_CONNECTION:
+ g_value_set_object (value, dspy_connection_model_get_connection (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+dspy_connection_model_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ DspyConnectionModel *self = DSPY_CONNECTION_MODEL (object);
+
+ switch (prop_id)
+ {
+ case PROP_CONNECTION:
+ dspy_connection_model_set_connection (self, g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+dspy_connection_model_class_init (DspyConnectionModelClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = dspy_connection_model_dispose;
+ object_class->finalize = dspy_connection_model_finalize;
+ object_class->get_property = dspy_connection_model_get_property;
+ object_class->set_property = dspy_connection_model_set_property;
+
+ /**
+ * DspyConnectionModel:connection:
+ *
+ * The "connection" property contains the #GDBusConnection that will be monitored
+ * for changes to the bus.
+ */
+ properties [PROP_CONNECTION] =
+ g_param_spec_object ("connection",
+ "Connection",
+ "A GDBus connection for the source of bus changes",
+ G_TYPE_DBUS_CONNECTION,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+dspy_connection_model_init (DspyConnectionModel *self)
+{
+ self->peers = g_sequence_new (g_object_unref);
+}
+
+static void
+dspy_connection_model_name_owner_changed_cb (GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *params,
+ gpointer user_data)
+{
+ DspyConnectionModel *self = user_data;
+
+ g_assert (G_IS_DBUS_CONNECTION (connection));
+ g_assert (DSPY_IS_CONNECTION_MODEL (self));
+
+}
+
+static void
+dspy_connection_model_add_names (DspyConnectionModel *self,
+ GVariant *names)
+{
+ const gchar * const *strv = NULL;
+ GVariantIter iter;
+
+ g_assert (DSPY_IS_CONNECTION_MODEL (self));
+ g_assert (names != NULL);
+
+ g_variant_iter_init (&iter, names);
+ if (g_variant_iter_next (&iter, "^as", &strv))
+ {
+ for (guint i = 0; strv[i]; i++)
+ g_printerr ("Found name: %s\n", strv[i]);
+ }
+}
+
+static void
+dspy_connection_model_list_activatable_names_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GDBusProxy *proxy = (GDBusProxy *)object;
+ g_autoptr(DspyConnectionModel) self = user_data;
+ g_autoptr(GVariant) ret = NULL;
+ g_autoptr(GError) error = NULL;
+
+ g_assert (G_IS_DBUS_PROXY (proxy));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (DSPY_IS_CONNECTION_MODEL (self));
+
+ if (!(ret = g_dbus_proxy_call_finish (proxy, result, &error)))
+ g_warning ("Failed to list activatable names: %s", error->message);
+ else
+ dspy_connection_model_add_names (self, ret);
+}
+
+static void
+dspy_connection_model_list_names_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GDBusProxy *proxy = (GDBusProxy *)object;
+ g_autoptr(DspyConnectionModel) self = user_data;
+ g_autoptr(GVariant) ret = NULL;
+ g_autoptr(GError) error = NULL;
+
+ g_assert (G_IS_DBUS_PROXY (proxy));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (DSPY_IS_CONNECTION_MODEL (self));
+
+ if (!(ret = g_dbus_proxy_call_finish (proxy, result, &error)))
+ g_warning ("Failed to list names: %s", error->message);
+ else
+ dspy_connection_model_add_names (self, ret);
+}
+
+DspyConnectionModel *
+dspy_connection_model_new (void)
+{
+ return g_object_new (DSPY_TYPE_CONNECTION_MODEL, NULL);
+}
+
+/**
+ * dspy_connection_model_get_connection:
+ * @self: a #DspyConnectionModel
+ *
+ * Gets the #GDBusConnection used for the model.
+ *
+ * Returns: (transfer none) (nullable): a #GDBusConnection or %NULL
+ */
+GDBusConnection *
+dspy_connection_model_get_connection (DspyConnectionModel *self)
+{
+ g_return_val_if_fail (DSPY_IS_CONNECTION_MODEL (self), NULL);
+
+ return self->connection;
+}
+
+void
+dspy_connection_model_set_connection (DspyConnectionModel *self,
+ GDBusConnection *connection)
+{
+ g_return_if_fail (DSPY_IS_CONNECTION_MODEL (self));
+
+ if (self->connection == connection)
+ return;
+
+ if (self->connection != NULL)
+ {
+ g_cancellable_cancel (self->cancellable);
+ g_dbus_connection_signal_unsubscribe (self->connection,
+ self->name_owner_changed_handler);
+ g_clear_object (&self->cancellable);
+ g_clear_object (&self->connection);
+ g_clear_object (&self->bus_proxy);
+ g_clear_pointer (&self->peers, g_sequence_free);
+ self->peers = g_sequence_new (g_object_unref);
+ }
+
+ g_assert (self->cancellable == NULL);
+ g_assert (self->connection == NULL);
+ g_assert (self->bus_proxy == NULL);
+ g_assert (g_sequence_is_empty (self->peers));
+
+ if (connection != NULL)
+ {
+ g_autoptr(GError) error = NULL;
+
+ self->connection = g_object_ref (connection);
+ self->cancellable = g_cancellable_new ();
+ self->name_owner_changed_handler =
+ g_dbus_connection_signal_subscribe (self->connection,
+ NULL,
+ "org.freedesktop.DBus",
+ "NameOwnerChanged",
+ NULL,
+ NULL,
+ 0,
+ dspy_connection_model_name_owner_changed_cb,
+ self,
+ NULL);
+ self->bus_proxy = g_dbus_proxy_new_sync (self->connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ self->cancellable, &error);
+
+ if (self->bus_proxy == NULL)
+ {
+ g_warning ("Failed to create DBus proxy: %s", error->message);
+ goto notify;
+ }
+
+ g_dbus_proxy_call (self->bus_proxy,
+ "ListActivatableNames",
+ g_variant_new ("()"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ self->cancellable,
+ dspy_connection_model_list_activatable_names_cb,
+ g_object_ref (self));
+
+ g_dbus_proxy_call (self->bus_proxy,
+ "ListNames",
+ g_variant_new ("()"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ self->cancellable,
+ dspy_connection_model_list_names_cb,
+ g_object_ref (self));
+ }
+
+notify:
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CONNECTION]);
+}
diff --git a/src/plugins/dspy/dspy-connection-model.h b/src/plugins/dspy/dspy-connection-model.h
new file mode 100644
index 000000000..dd5083efa
--- /dev/null
+++ b/src/plugins/dspy/dspy-connection-model.h
@@ -0,0 +1,36 @@
+/* dspy-connection-model.h
+ *
+ * Copyright 2019 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
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define DSPY_TYPE_CONNECTION_MODEL (dspy_connection_model_get_type())
+
+G_DECLARE_FINAL_TYPE (DspyConnectionModel, dspy_connection_model, DSPY, CONNECTION_MODEL, GObject)
+
+DspyConnectionModel *dspy_connection_model_new (void);
+GDBusConnection *dspy_connection_model_get_connection (DspyConnectionModel *self);
+void dspy_connection_model_set_connection (DspyConnectionModel *self,
+ GDBusConnection *connection);
+
+G_END_DECLS
diff --git a/src/plugins/dspy/dspy-plugin.c b/src/plugins/dspy/dspy-plugin.c
new file mode 100644
index 000000000..85bd90efc
--- /dev/null
+++ b/src/plugins/dspy/dspy-plugin.c
@@ -0,0 +1,34 @@
+/* dspy-plugin.c
+ *
+ * Copyright 2019 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
+ */
+
+#include "config.h"
+
+#include <libide-editor.h>
+#include <libpeas/peas.h>
+
+#include "gbp-dspy-workspace-addin.h"
+
+_IDE_EXTERN void
+_gbp_dspy_register_types (PeasObjectModule *module)
+{
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_WORKSPACE_ADDIN,
+ GBP_TYPE_DSPY_WORKSPACE_ADDIN);
+}
diff --git a/src/plugins/dspy/dspy.gresource.xml b/src/plugins/dspy/dspy.gresource.xml
new file mode 100644
index 000000000..5e17faaa8
--- /dev/null
+++ b/src/plugins/dspy/dspy.gresource.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/plugins/dspy">
+ <file>dspy.plugin</file>
+ <file>gtk/menus.ui</file>
+ </gresource>
+</gresources>
diff --git a/src/plugins/dspy/dspy.plugin b/src/plugins/dspy/dspy.plugin
new file mode 100644
index 000000000..b98a209a9
--- /dev/null
+++ b/src/plugins/dspy/dspy.plugin
@@ -0,0 +1,9 @@
+[Plugin]
+Authors=Christian Hergert <christian hergert me>
+Builtin=true
+Copyright=Copyright © 2019 Christian Hergert
+Description=Explore DBus session and system connections
+Embedded=_gbp_dspy_register_types
+Module=dspy
+Name=DBus Connection Explorer
+X-Workspace-Kind=primary;editor;
diff --git a/src/plugins/dspy/gbp-dspy-workspace-addin.c b/src/plugins/dspy/gbp-dspy-workspace-addin.c
new file mode 100644
index 000000000..74ed238aa
--- /dev/null
+++ b/src/plugins/dspy/gbp-dspy-workspace-addin.c
@@ -0,0 +1,66 @@
+/* gbp-dspy-workspace-addin.c
+ *
+ * Copyright 2019 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 "gbp-dspy-workspace-addin"
+
+#include <libide-editor.h>
+
+#include "dspy-connection-model.h"
+#include "gbp-dspy-workspace-addin.h"
+
+struct _GbpDspyWorkspaceAddin
+{
+ GObject parent_instance;
+ DspyConnectionModel *model;
+};
+
+static void
+gbp_dspy_workspace_addin_load (IdeWorkspaceAddin *addin,
+ IdeWorkspace *workspace)
+{
+ GbpDspyWorkspaceAddin *self = (GbpDspyWorkspaceAddin *)addin;
+
+ g_assert (GBP_IS_DSPY_WORKSPACE_ADDIN (addin));
+ g_assert (IDE_IS_PRIMARY_WORKSPACE (workspace) || IDE_IS_EDITOR_WORKSPACE (workspace));
+
+ g_print ("WEEE\n");
+
+ self->model = dspy_connection_model_new ();
+ dspy_connection_model_set_connection (self->model, g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL));
+}
+
+static void
+workspace_addin_iface_init (IdeWorkspaceAddinInterface *iface)
+{
+ iface->load = gbp_dspy_workspace_addin_load;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpDspyWorkspaceAddin, gbp_dspy_workspace_addin, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKSPACE_ADDIN, workspace_addin_iface_init))
+
+static void
+gbp_dspy_workspace_addin_class_init (GbpDspyWorkspaceAddinClass *klass)
+{
+}
+
+static void
+gbp_dspy_workspace_addin_init (GbpDspyWorkspaceAddin *self)
+{
+}
diff --git a/src/plugins/dspy/gbp-dspy-workspace-addin.h b/src/plugins/dspy/gbp-dspy-workspace-addin.h
new file mode 100644
index 000000000..e4cfec50e
--- /dev/null
+++ b/src/plugins/dspy/gbp-dspy-workspace-addin.h
@@ -0,0 +1,31 @@
+/* gbp-dspy-workspace-addin.h
+ *
+ * Copyright 2019 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
+
+#include <libide-gui.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_DSPY_WORKSPACE_ADDIN (gbp_dspy_workspace_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpDspyWorkspaceAddin, gbp_dspy_workspace_addin, GBP, DSPY_WORKSPACE_ADDIN, GObject)
+
+G_END_DECLS
diff --git a/src/plugins/dspy/gtk/menus.ui b/src/plugins/dspy/gtk/menus.ui
new file mode 100644
index 000000000..b2e03ef3a
--- /dev/null
+++ b/src/plugins/dspy/gtk/menus.ui
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+</interface>
diff --git a/src/plugins/dspy/meson.build b/src/plugins/dspy/meson.build
new file mode 100644
index 000000000..d99248f70
--- /dev/null
+++ b/src/plugins/dspy/meson.build
@@ -0,0 +1,17 @@
+if get_option('plugin_dspy')
+
+plugins_sources += files([
+ 'dspy-plugin.c',
+ 'dspy-connection-model.c',
+ 'gbp-dspy-workspace-addin.c',
+])
+
+plugin_dspy_resources = gnome.compile_resources(
+ 'dspy-resources',
+ 'dspy.gresource.xml',
+ c_name: 'gbp_dspy',
+)
+
+plugins_sources += plugin_dspy_resources
+
+endif
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index 0c5fd6aa4..4feeb4a41 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -56,6 +56,7 @@ subdir('devhelp')
subdir('deviceui')
subdir('deviced')
subdir('doap')
+subdir('dspy')
subdir('editor')
subdir('editorconfig')
subdir('emacs')
@@ -143,6 +144,7 @@ status += [
'CTags ................. : @0@'.format(get_option('plugin_ctags')),
'Devhelp ............... : @0@'.format(get_option('plugin_devhelp')),
'Deviced ............... : @0@'.format(get_option('plugin_deviced')),
+ 'DBus Spy .............. : @0@'.format(get_option('plugin_dspy')),
'Editorconfig .......... : @0@'.format(get_option('plugin_editorconfig')),
'ESLint ................ : @0@'.format(get_option('plugin_eslint')),
'File Search ........... : @0@'.format(get_option('plugin_file_search')),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]