From 3c33ae06a0fc349e1b3ac95189b87def6a2660d4 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 1 Aug 2023 11:20:24 -0700 Subject: [PATCH] sysprof: add dbus utility This allows viewing the message contents that were captured in a textview within the utility pane. We already limit the max size of a message in the capture file, so presumably messages are relatively small enough to fit here. --- .../sysprof-document-dbus-message.c | 23 +++ .../sysprof-document-dbus-message.h | 2 + src/sysprof/meson.build | 1 + src/sysprof/sysprof-dbus-section.c | 2 + src/sysprof/sysprof-dbus-section.ui | 13 +- src/sysprof/sysprof-dbus-utility.c | 133 ++++++++++++++++++ src/sysprof/sysprof-dbus-utility.h | 37 +++++ src/sysprof/sysprof-dbus-utility.ui | 45 ++++++ src/sysprof/sysprof.gresource.xml | 1 + 9 files changed, 252 insertions(+), 5 deletions(-) create mode 100644 src/sysprof/sysprof-dbus-utility.c create mode 100644 src/sysprof/sysprof-dbus-utility.h create mode 100644 src/sysprof/sysprof-dbus-utility.ui diff --git a/src/libsysprof/sysprof-document-dbus-message.c b/src/libsysprof/sysprof-document-dbus-message.c index 133ebd07..abb644fd 100644 --- a/src/libsysprof/sysprof-document-dbus-message.c +++ b/src/libsysprof/sysprof-document-dbus-message.c @@ -51,6 +51,7 @@ enum { PROP_SIGNATURE, PROP_SENDER, PROP_SERIAL, + PROP_STRING, N_PROPS }; @@ -130,6 +131,10 @@ sysprof_document_dbus_message_get_property (GObject *object, g_value_set_string (value, sysprof_document_dbus_message_get_signature (self)); break; + case PROP_STRING: + g_value_take_string (value, sysprof_document_dbus_message_dup_string (self)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -214,6 +219,11 @@ sysprof_document_dbus_message_class_init (SysprofDocumentDBusMessageClass *klass 0, (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + properties[PROP_STRING] = + g_param_spec_string ("string", NULL, NULL, + NULL, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_properties (object_class, N_PROPS, properties); } @@ -444,3 +454,16 @@ sysprof_document_dbus_message_get_bus_type (SysprofDocumentDBusMessage *self) return 0; } + +char * +sysprof_document_dbus_message_dup_string (SysprofDocumentDBusMessage *self) +{ + g_autoptr(GDBusMessage) message = NULL; + + g_return_val_if_fail (SYSPROF_IS_DOCUMENT_DBUS_MESSAGE (self), NULL); + + if (!(message = sysprof_document_dbus_message_dup_message (self))) + return NULL; + + return g_dbus_message_print (message, 0); +} diff --git a/src/libsysprof/sysprof-document-dbus-message.h b/src/libsysprof/sysprof-document-dbus-message.h index 57a0e7e0..85b6ba47 100644 --- a/src/libsysprof/sysprof-document-dbus-message.h +++ b/src/libsysprof/sysprof-document-dbus-message.h @@ -65,6 +65,8 @@ SYSPROF_AVAILABLE_IN_ALL GDBusMessageFlags sysprof_document_dbus_message_get_flags (SysprofDocumentDBusMessage *self); SYSPROF_AVAILABLE_IN_ALL GBusType sysprof_document_dbus_message_get_bus_type (SysprofDocumentDBusMessage *self); +SYSPROF_AVAILABLE_IN_ALL +char *sysprof_document_dbus_message_dup_string (SysprofDocumentDBusMessage *self); G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofDocumentDBusMessage, g_object_unref) diff --git a/src/sysprof/meson.build b/src/sysprof/meson.build index 0c64bb76..c09a3b2e 100644 --- a/src/sysprof/meson.build +++ b/src/sysprof/meson.build @@ -15,6 +15,7 @@ sysprof_sources = [ 'sysprof-cpu-section.c', 'sysprof-css.c', 'sysprof-dbus-section.c', + 'sysprof-dbus-utility.c', 'sysprof-duplex-layer.c', 'sysprof-energy-section.c', 'sysprof-files-section.c', diff --git a/src/sysprof/sysprof-dbus-section.c b/src/sysprof/sysprof-dbus-section.c index 2228306f..3863a7d8 100644 --- a/src/sysprof/sysprof-dbus-section.c +++ b/src/sysprof/sysprof-dbus-section.c @@ -22,6 +22,7 @@ #include "sysprof-chart.h" #include "sysprof-dbus-section.h" +#include "sysprof-dbus-utility.h" #include "sysprof-line-layer.h" #include "sysprof-time-filter-model.h" #include "sysprof-time-scrubber.h" @@ -184,6 +185,7 @@ sysprof_dbus_section_class_init (SysprofDBusSectionClass *klass) gtk_widget_class_bind_template_callback (widget_class, format_message_type); g_type_ensure (SYSPROF_TYPE_CHART); + g_type_ensure (SYSPROF_TYPE_DBUS_UTILITY); g_type_ensure (SYSPROF_TYPE_DOCUMENT_MARK); g_type_ensure (SYSPROF_TYPE_DOCUMENT_DBUS_MESSAGE); } diff --git a/src/sysprof/sysprof-dbus-section.ui b/src/sysprof/sysprof-dbus-section.ui index e77f8a09..11f2a0fa 100644 --- a/src/sysprof/sysprof-dbus-section.ui +++ b/src/sysprof/sysprof-dbus-section.ui @@ -74,7 +74,7 @@ true true - + @@ -555,9 +555,12 @@ + + + + selection + + + - - - - diff --git a/src/sysprof/sysprof-dbus-utility.c b/src/sysprof/sysprof-dbus-utility.c new file mode 100644 index 00000000..ebdd5d25 --- /dev/null +++ b/src/sysprof/sysprof-dbus-utility.c @@ -0,0 +1,133 @@ +/* sysprof-dbus-utility.c + * + * Copyright 2023 Christian Hergert + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "config.h" + +#include "sysprof-dbus-utility.h" + +struct _SysprofDBusUtility +{ + GtkWidget parent_instance; + SysprofDocumentDBusMessage *message; +}; + +enum { + PROP_0, + PROP_MESSAGE, + N_PROPS +}; + +G_DEFINE_FINAL_TYPE (SysprofDBusUtility, sysprof_dbus_utility, GTK_TYPE_WIDGET) + +static GParamSpec *properties [N_PROPS]; + +static void +sysprof_dbus_utility_finalize (GObject *object) +{ + SysprofDBusUtility *self = (SysprofDBusUtility *)object; + + g_clear_object (&self->message); + + G_OBJECT_CLASS (sysprof_dbus_utility_parent_class)->finalize (object); +} + +static void +sysprof_dbus_utility_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SysprofDBusUtility *self = SYSPROF_DBUS_UTILITY (object); + + switch (prop_id) + { + case PROP_MESSAGE: + g_value_set_object (value, sysprof_dbus_utility_get_message (self)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_dbus_utility_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + SysprofDBusUtility *self = SYSPROF_DBUS_UTILITY (object); + + switch (prop_id) + { + case PROP_MESSAGE: + sysprof_dbus_utility_set_message (self, g_value_get_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_dbus_utility_class_init (SysprofDBusUtilityClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->finalize = sysprof_dbus_utility_finalize; + object_class->get_property = sysprof_dbus_utility_get_property; + object_class->set_property = sysprof_dbus_utility_set_property; + + properties[PROP_MESSAGE] = + g_param_spec_object ("message", NULL, NULL, + SYSPROF_TYPE_DOCUMENT_DBUS_MESSAGE, + (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties (object_class, N_PROPS, properties); + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-dbus-utility.ui"); + gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); +} + +static void +sysprof_dbus_utility_init (SysprofDBusUtility *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} + +SysprofDocumentDBusMessage * +sysprof_dbus_utility_get_message (SysprofDBusUtility *self) +{ + g_return_val_if_fail (SYSPROF_IS_DBUS_UTILITY (self), NULL); + + return self->message; +} + +void +sysprof_dbus_utility_set_message (SysprofDBusUtility *self, + SysprofDocumentDBusMessage *message) +{ + g_return_if_fail (SYSPROF_IS_DBUS_UTILITY (self)); + g_return_if_fail (!message || SYSPROF_IS_DOCUMENT_DBUS_MESSAGE (message)); + + if (g_set_object (&self->message, message)) + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MESSAGE]); +} diff --git a/src/sysprof/sysprof-dbus-utility.h b/src/sysprof/sysprof-dbus-utility.h new file mode 100644 index 00000000..3beaf3fa --- /dev/null +++ b/src/sysprof/sysprof-dbus-utility.h @@ -0,0 +1,37 @@ +/* sysprof-dbus-utility.h + * + * Copyright 2023 Christian Hergert + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +#include + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_DBUS_UTILITY (sysprof_dbus_utility_get_type()) + +G_DECLARE_FINAL_TYPE (SysprofDBusUtility, sysprof_dbus_utility, SYSPROF, DBUS_UTILITY, GtkWidget) + +SysprofDocumentDBusMessage *sysprof_dbus_utility_get_message (SysprofDBusUtility *self); +void sysprof_dbus_utility_set_message (SysprofDBusUtility *self, + SysprofDocumentDBusMessage *message); + +G_END_DECLS diff --git a/src/sysprof/sysprof-dbus-utility.ui b/src/sysprof/sysprof-dbus-utility.ui new file mode 100644 index 00000000..c0644754 --- /dev/null +++ b/src/sysprof/sysprof-dbus-utility.ui @@ -0,0 +1,45 @@ + + + + diff --git a/src/sysprof/sysprof.gresource.xml b/src/sysprof/sysprof.gresource.xml index 9f80c1e9..9bb79f02 100644 --- a/src/sysprof/sysprof.gresource.xml +++ b/src/sysprof/sysprof.gresource.xml @@ -22,6 +22,7 @@ sysprof-cpu-section.ui sysprof-cpu-section-counter.ui sysprof-dbus-section.ui + sysprof-dbus-utility.ui sysprof-energy-section.ui sysprof-energy-section-counter.ui sysprof-files-section.ui