[sysprof] libsysprof-ui: stub out proxy source



commit 588fd43d8b72a1ae25984ce4c98b86b6733c0a8e
Author: Christian Hergert <chergert redhat com>
Date:   Sun May 19 22:46:22 2019 -0700

    libsysprof-ui: stub out proxy source
    
    The goal for this (which is unfinished) is to setup a dbus proxy to the
    peer. That can be reused for both gtk and mutter, if configured correctly.
    
    We'll likely need to allow some specific config tweaks in the UI.

 src/libsysprof-ui/meson.build                      |   2 +
 src/libsysprof-ui/sysprof-profiler-assistant.c     |   2 +
 src/libsysprof-ui/sysprof-proxy-aid.c              | 209 +++++++++++++++++++++
 src/libsysprof-ui/sysprof-proxy-aid.h              |  49 +++++
 src/libsysprof-ui/sysprof-ui.h                     |   1 +
 src/libsysprof-ui/ui/sysprof-profiler-assistant.ui |  13 ++
 src/libsysprof/meson.build                         |   2 +
 src/libsysprof/sysprof-proxy-source.c              | 116 ++++++++++++
 src/libsysprof/sysprof-proxy-source.h              |  39 ++++
 src/libsysprof/sysprof.h                           |   1 +
 10 files changed, 434 insertions(+)
---
diff --git a/src/libsysprof-ui/meson.build b/src/libsysprof-ui/meson.build
index f5087a7..3f6858d 100644
--- a/src/libsysprof-ui/meson.build
+++ b/src/libsysprof-ui/meson.build
@@ -17,6 +17,7 @@ libsysprof_ui_public_sources = [
   'sysprof-model-filter.c',
   'sysprof-notebook.c',
   'sysprof-process-model-row.c',
+  'sysprof-proxy-aid.c',
   'sysprof-profiler-assistant.c',
   'sysprof-profiler-menu-button.c',
   'sysprof-recording-state-view.c',
@@ -64,6 +65,7 @@ libsysprof_ui_public_headers = [
   'sysprof-model-filter.h',
   'sysprof-notebook.h',
   'sysprof-process-model-row.h',
+  'sysprof-proxy-aid.h',
   'sysprof-profiler-assistant.h',
   'sysprof-profiler-menu-button.h',
   'sysprof-recording-state-view.h',
diff --git a/src/libsysprof-ui/sysprof-profiler-assistant.c b/src/libsysprof-ui/sysprof-profiler-assistant.c
index 06bfef4..5a96ace 100644
--- a/src/libsysprof-ui/sysprof-profiler-assistant.c
+++ b/src/libsysprof-ui/sysprof-profiler-assistant.c
@@ -28,6 +28,7 @@
 #include "sysprof-cpu-aid.h"
 #include "sysprof-environ-editor.h"
 #include "sysprof-profiler-assistant.h"
+#include "sysprof-proxy-aid.h"
 #include "sysprof-process-model-row.h"
 
 struct _SysprofProfilerAssistant
@@ -267,6 +268,7 @@ sysprof_profiler_assistant_class_init (SysprofProfilerAssistantClass *klass)
 
   g_type_ensure (SYSPROF_TYPE_AID_ICON);
   g_type_ensure (SYSPROF_TYPE_CPU_AID);
+  g_type_ensure (SYSPROF_TYPE_PROXY_AID);
   g_type_ensure (SYSPROF_TYPE_ENVIRON_EDITOR);
 }
 
diff --git a/src/libsysprof-ui/sysprof-proxy-aid.c b/src/libsysprof-ui/sysprof-proxy-aid.c
new file mode 100644
index 0000000..6fd05c0
--- /dev/null
+++ b/src/libsysprof-ui/sysprof-proxy-aid.c
@@ -0,0 +1,209 @@
+/* sysprof-proxy-aid.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 "sysprof-proxy-aid"
+
+#include "sysprof-proxy-aid.h"
+
+typedef struct
+{
+  GBusType bus_type;
+  gchar *bus_name;
+  gchar *object_path;
+} SysprofProxyAidPrivate;
+
+enum {
+  PROP_0,
+  PROP_BUS_TYPE,
+  PROP_BUS_NAME,
+  PROP_OBJECT_PATH,
+  N_PROPS
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (SysprofProxyAid, sysprof_proxy_aid, SYSPROF_TYPE_AID)
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+sysprof_proxy_aid_prepare (SysprofAid      *aid,
+                           SysprofProfiler *profiler)
+{
+  SysprofProxyAid *self = (SysprofProxyAid *)aid;
+  SysprofProxyAidPrivate *priv = sysprof_proxy_aid_get_instance_private (self);
+  g_autoptr(SysprofSource) source = NULL;
+
+  g_assert (SYSPROF_IS_PROXY_AID (self));
+  g_assert (SYSPROF_IS_PROFILER (profiler));
+
+  source = sysprof_proxy_source_new (priv->bus_type, priv->bus_name, priv->object_path);
+  sysprof_profiler_add_source (profiler, source);
+}
+
+static void
+sysprof_proxy_aid_finalize (GObject *object)
+{
+  SysprofProxyAid *self = (SysprofProxyAid *)object;
+  SysprofProxyAidPrivate *priv = sysprof_proxy_aid_get_instance_private (self);
+
+  g_clear_pointer (&priv->bus_name, g_free);
+  g_clear_pointer (&priv->object_path, g_free);
+
+  G_OBJECT_CLASS (sysprof_proxy_aid_parent_class)->finalize (object);
+}
+
+static void
+sysprof_proxy_aid_get_property (GObject    *object,
+                                guint       prop_id,
+                                GValue     *value,
+                                GParamSpec *pspec)
+{
+  SysprofProxyAid *self = SYSPROF_PROXY_AID (object);
+  SysprofProxyAidPrivate *priv = sysprof_proxy_aid_get_instance_private (self);
+
+  switch (prop_id)
+    {
+    case PROP_BUS_NAME:
+      g_value_set_string (value, priv->bus_name);
+      break;
+
+    case PROP_OBJECT_PATH:
+      g_value_set_string (value, priv->object_path);
+      break;
+
+    case PROP_BUS_TYPE:
+      g_value_set_enum (value, priv->bus_type);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+sysprof_proxy_aid_set_property (GObject      *object,
+                                guint         prop_id,
+                                const GValue *value,
+                                GParamSpec   *pspec)
+{
+  SysprofProxyAid *self = SYSPROF_PROXY_AID (object);
+
+  switch (prop_id)
+    {
+    case PROP_BUS_NAME:
+      sysprof_proxy_aid_set_bus_name (self, g_value_get_string (value));
+      break;
+
+    case PROP_BUS_TYPE:
+      sysprof_proxy_aid_set_bus_type (self, g_value_get_enum (value));
+      break;
+
+    case PROP_OBJECT_PATH:
+      sysprof_proxy_aid_set_object_path (self, g_value_get_string (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+sysprof_proxy_aid_class_init (SysprofProxyAidClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  SysprofAidClass *aid_class = SYSPROF_AID_CLASS (klass);
+
+  object_class->finalize = sysprof_proxy_aid_finalize;
+  object_class->get_property = sysprof_proxy_aid_get_property;
+  object_class->set_property = sysprof_proxy_aid_set_property;
+
+  aid_class->prepare = sysprof_proxy_aid_prepare;
+
+  properties [PROP_OBJECT_PATH] =
+    g_param_spec_string ("object-path", NULL, NULL,
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_BUS_NAME] =
+    g_param_spec_string ("bus-name", NULL, NULL,
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_BUS_TYPE] =
+    g_param_spec_enum ("bus-type", NULL, NULL,
+                       G_TYPE_BUS_TYPE,
+                       G_BUS_TYPE_SESSION,
+                       (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+  
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+sysprof_proxy_aid_init (SysprofProxyAid *self)
+{
+  SysprofProxyAidPrivate *priv = sysprof_proxy_aid_get_instance_private (self);
+
+  priv->bus_type = G_BUS_TYPE_SESSION;
+  priv->object_path = g_strdup ("/org/gnome/Sysprof3/Profiler");
+}
+
+void
+sysprof_proxy_aid_set_bus_type (SysprofProxyAid *self,
+                                GBusType         bus_type)
+{
+  SysprofProxyAidPrivate *priv = sysprof_proxy_aid_get_instance_private (self);
+
+  g_return_if_fail (SYSPROF_IS_PROXY_AID (self));
+  g_return_if_fail (bus_type == G_BUS_TYPE_SESSION || bus_type == G_BUS_TYPE_SYSTEM);
+
+  priv->bus_type = bus_type;
+  g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_BUS_TYPE]);
+}
+
+void
+sysprof_proxy_aid_set_bus_name (SysprofProxyAid *self,
+                                const gchar     *bus_name)
+{
+  SysprofProxyAidPrivate *priv = sysprof_proxy_aid_get_instance_private (self);
+
+  g_return_if_fail (SYSPROF_IS_PROXY_AID (self));
+
+  if (g_strcmp0 (bus_name, priv->bus_name) != 0)
+    {
+      g_free (priv->bus_name);
+      priv->bus_name = g_strdup (bus_name);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_BUS_NAME]);
+    }
+}
+
+void
+sysprof_proxy_aid_set_object_path (SysprofProxyAid *self,
+                                   const gchar     *object_path)
+{
+  SysprofProxyAidPrivate *priv = sysprof_proxy_aid_get_instance_private (self);
+
+  g_return_if_fail (SYSPROF_IS_PROXY_AID (self));
+
+  if (g_strcmp0 (object_path, priv->object_path) != 0)
+    {
+      g_free (priv->object_path);
+      priv->object_path = g_strdup (object_path);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_OBJECT_PATH]);
+    }
+}
diff --git a/src/libsysprof-ui/sysprof-proxy-aid.h b/src/libsysprof-ui/sysprof-proxy-aid.h
new file mode 100644
index 0000000..4f6a79d
--- /dev/null
+++ b/src/libsysprof-ui/sysprof-proxy-aid.h
@@ -0,0 +1,49 @@
+/* sysprof-proxy-aid.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 "sysprof-aid.h"
+
+G_BEGIN_DECLS
+
+#define SYSPROF_TYPE_PROXY_AID (sysprof_proxy_aid_get_type())
+
+G_DECLARE_DERIVABLE_TYPE (SysprofProxyAid, sysprof_proxy_aid, SYSPROF, PROXY_AID, SysprofAid)
+
+struct _SysprofProxyAidClass
+{
+  SysprofAidClass parent_class;
+
+  /*< private >*/
+  gpointer _reserved[8];
+};
+
+SYSPROF_AVAILABLE_IN_ALL
+void sysprof_proxy_aid_set_bus_type    (SysprofProxyAid *self,
+                                        GBusType         bus_type);
+SYSPROF_AVAILABLE_IN_ALL
+void sysprof_proxy_aid_set_bus_name    (SysprofProxyAid *self,
+                                        const gchar     *bus_name);
+SYSPROF_AVAILABLE_IN_ALL
+void sysprof_proxy_aid_set_object_path (SysprofProxyAid *self,
+                                        const gchar     *obj_path);
+
+G_END_DECLS
diff --git a/src/libsysprof-ui/sysprof-ui.h b/src/libsysprof-ui/sysprof-ui.h
index 5517f41..b724e06 100644
--- a/src/libsysprof-ui/sysprof-ui.h
+++ b/src/libsysprof-ui/sysprof-ui.h
@@ -47,6 +47,7 @@ G_BEGIN_DECLS
 # include "sysprof-process-model-row.h"
 # include "sysprof-profiler-assistant.h"
 # include "sysprof-profiler-menu-button.h"
+# include "sysprof-proxy-aid.h"
 # include "sysprof-recording-state-view.h"
 # include "sysprof-visualizer-row.h"
 # include "sysprof-visualizer-view.h"
diff --git a/src/libsysprof-ui/ui/sysprof-profiler-assistant.ui 
b/src/libsysprof-ui/ui/sysprof-profiler-assistant.ui
index daec81f..dfe7087 100644
--- a/src/libsysprof-ui/ui/sysprof-profiler-assistant.ui
+++ b/src/libsysprof-ui/ui/sysprof-profiler-assistant.ui
@@ -4,6 +4,13 @@
   <object class="SysprofCpuAid" id="cpu_aid"/>
   <object class="SysprofMemoryAid" id="memory_aid"/>
   <object class="SysprofCallgraphAid" id="callgraph_aid"/>
+  <object class="SysprofProxyAid" id="mutter_aid">
+    <property name="object-path">/org/gnome/Sysprof3/Profiler</property>
+    <property name="bus-type">session</property>
+    <property name="bus-name">org.gnome.Mutter</property>
+    <property name="display-name">Display Compositor</property>
+    <property name="icon-name">org.gnome.Sysprof-symbolic</property>
+  </object>
   <template class="SysprofProfilerAssistant" parent="GtkBin">
     <child>
       <object class="GtkScrolledWindow">
@@ -66,6 +73,12 @@
                         <property name="visible">true</property>
                       </object>
                     </child>
+                    <child>
+                      <object class="SysprofAidIcon">
+                        <property name="aid">mutter_aid</property>
+                        <property name="visible">true</property>
+                      </object>
+                    </child>
                   </object>
                   <packing>
                     <property name="column">center</property>
diff --git a/src/libsysprof/meson.build b/src/libsysprof/meson.build
index cb0b5d2..60d565c 100644
--- a/src/libsysprof/meson.build
+++ b/src/libsysprof/meson.build
@@ -15,6 +15,7 @@ libsysprof_public_sources = [
   'sysprof-process-model-item.c',
   'sysprof-profile.c',
   'sysprof-profiler.c',
+  'sysprof-proxy-source.c',
   'sysprof-selection.c',
   'sysprof-source.c',
   'sysprof-symbol-dirs.c',
@@ -36,6 +37,7 @@ libsysprof_public_headers = [
   'sysprof-process-model-item.h',
   'sysprof-profile.h',
   'sysprof-profiler.h',
+  'sysprof-proxy-source.h',
   'sysprof-selection.h',
   'sysprof-source.h',
   'sysprof-symbol-dirs.h',
diff --git a/src/libsysprof/sysprof-proxy-source.c b/src/libsysprof/sysprof-proxy-source.c
new file mode 100644
index 0000000..5582994
--- /dev/null
+++ b/src/libsysprof/sysprof-proxy-source.c
@@ -0,0 +1,116 @@
+/* sysprof-proxy-source.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 "sysprof-proxy-source"
+
+#include "config.h"
+
+#include "sysprof-proxy-source.h"
+
+struct _SysprofProxySource
+{
+  GObject parent_instance;
+  gchar *bus_name;
+  gchar *object_path;
+  GBusType bus_type;
+};
+
+static void
+sysprof_proxy_source_prepare (SysprofSource *source)
+{
+  SysprofProxySource *self = (SysprofProxySource *)source;
+
+  g_assert (SYSPROF_IS_PROXY_SOURCE (self));
+}
+
+static gboolean
+sysprof_proxy_source_get_is_ready (SysprofSource *source)
+{
+  SysprofProxySource *self = (SysprofProxySource *)source;
+
+  g_assert (SYSPROF_IS_PROXY_SOURCE (self));
+
+  return FALSE;
+}
+
+static void
+sysprof_proxy_source_set_writer (SysprofSource        *source,
+                                 SysprofCaptureWriter *writer)
+{
+  SysprofProxySource *self = (SysprofProxySource *)source;
+
+  g_assert (SYSPROF_IS_PROXY_SOURCE (self));
+  g_assert (writer != NULL);
+
+}
+
+static void
+source_iface_init (SysprofSourceInterface *iface)
+{
+  iface->prepare = sysprof_proxy_source_prepare;
+  iface->set_writer = sysprof_proxy_source_set_writer;
+  iface->get_is_ready = sysprof_proxy_source_get_is_ready;
+}
+
+G_DEFINE_TYPE_WITH_CODE (SysprofProxySource, sysprof_proxy_source, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (SYSPROF_TYPE_SOURCE, source_iface_init))
+
+static void
+sysprof_proxy_source_finalize (GObject *object)
+{
+  SysprofProxySource *self = (SysprofProxySource *)object;
+
+  g_clear_pointer (&self->bus_name, g_free);
+  g_clear_pointer (&self->object_path, g_free);
+
+  G_OBJECT_CLASS (sysprof_proxy_source_parent_class)->finalize (object);
+}
+
+static void
+sysprof_proxy_source_class_init (SysprofProxySourceClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = sysprof_proxy_source_finalize;
+}
+
+static void
+sysprof_proxy_source_init (SysprofProxySource *self)
+{
+}
+
+SysprofSource *
+sysprof_proxy_source_new (GBusType     bus_type,
+                          const gchar *bus_name,
+                          const gchar *object_path)
+{
+  SysprofProxySource *self;
+
+  g_return_val_if_fail (bus_type == G_BUS_TYPE_SESSION || bus_type == G_BUS_TYPE_SYSTEM, NULL);
+  g_return_val_if_fail (bus_name != NULL, NULL);
+  g_return_val_if_fail (object_path != NULL, NULL);
+
+  self = g_object_new (SYSPROF_TYPE_PROXY_SOURCE, NULL);
+  self->bus_type = bus_type;
+  self->bus_name = g_strdup (bus_name);
+  self->object_path = g_strdup (object_path);
+
+  return SYSPROF_SOURCE (g_steal_pointer (&self));
+}
diff --git a/src/libsysprof/sysprof-proxy-source.h b/src/libsysprof/sysprof-proxy-source.h
new file mode 100644
index 0000000..284d1bc
--- /dev/null
+++ b/src/libsysprof/sysprof-proxy-source.h
@@ -0,0 +1,39 @@
+/* sysprof-proxy-source.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>
+
+#include "sysprof-source.h"
+
+G_BEGIN_DECLS
+
+#define SYSPROF_TYPE_PROXY_SOURCE (sysprof_proxy_source_get_type())
+
+SYSPROF_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (SysprofProxySource, sysprof_proxy_source, SYSPROF, PROXY_SOURCE, GObject)
+
+SYSPROF_AVAILABLE_IN_ALL
+SysprofSource *sysprof_proxy_source_new (GBusType     bus_type,
+                                         const gchar *bus_name,
+                                         const gchar *object_path);
+
+G_END_DECLS
diff --git a/src/libsysprof/sysprof.h b/src/libsysprof/sysprof.h
index b0ca8fd..4ea6c12 100644
--- a/src/libsysprof/sysprof.h
+++ b/src/libsysprof/sysprof.h
@@ -38,6 +38,7 @@ G_BEGIN_DECLS
 # include "sysprof-jitmap-symbol-resolver.h"
 # include "sysprof-kernel-symbol-resolver.h"
 # include "sysprof-kernel-symbol.h"
+# include "sysprof-proxy-source.h"
 # include "sysprof-symbol-dirs.h"
 # include "sysprof-symbol-resolver.h"
 # include "sysprof-map-lookaside.h"


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