From 637dfceb859aea8d4274643d2663b4ea488e7150 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Fri, 21 Mar 2025 12:00:55 -0700 Subject: [PATCH] libsysprof/instruments: add set_connection() vfunc This is used to tell the instruments what GDBusConnection they should use to query sysprofd. Lack of a connection means they should try to do things in process without querying sysprofd. --- src/libsysprof/sysprof-instrument-private.h | 4 ++++ src/libsysprof/sysprof-instrument.c | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/libsysprof/sysprof-instrument-private.h b/src/libsysprof/sysprof-instrument-private.h index c665f38e..2ce8a941 100644 --- a/src/libsysprof/sysprof-instrument-private.h +++ b/src/libsysprof/sysprof-instrument-private.h @@ -39,6 +39,8 @@ struct _SysprofInstrumentClass GObjectClass parent_class; char **(*list_required_policy) (SysprofInstrument *self); + void (*set_connection) (SysprofInstrument *self, + GDBusConnection *connection); DexFuture *(*prepare) (SysprofInstrument *self, SysprofRecording *recording); DexFuture *(*record) (SysprofInstrument *self, @@ -52,6 +54,8 @@ struct _SysprofInstrumentClass const char *comm); }; +void _sysprof_instruments_set_connection (GPtrArray *instruments, + GDBusConnection *connection); DexFuture *_sysprof_instruments_acquire_policy (GPtrArray *instruments, SysprofRecording *recording); DexFuture *_sysprof_instruments_prepare (GPtrArray *instruments, diff --git a/src/libsysprof/sysprof-instrument.c b/src/libsysprof/sysprof-instrument.c index f44c35f4..f6085108 100644 --- a/src/libsysprof/sysprof-instrument.c +++ b/src/libsysprof/sysprof-instrument.c @@ -310,3 +310,19 @@ _sysprof_instruments_process_started (GPtrArray *instruments, return dex_future_allv ((DexFuture **)futures->pdata, futures->len); } + +void +_sysprof_instruments_set_connection (GPtrArray *instruments, + GDBusConnection *connection) +{ + g_return_if_fail (instruments != NULL); + g_return_if_fail (!connection || G_IS_DBUS_CONNECTION (connection)); + + for (guint i = 0; i < instruments->len; i++) + { + SysprofInstrument *instrument = g_ptr_array_index (instruments, i); + + if (SYSPROF_INSTRUMENT_GET_CLASS (instrument)->set_connection) + SYSPROF_INSTRUMENT_GET_CLASS (instrument)->set_connection (instrument, connection); + } +}