From 19223803f5e0baad8f691fd86790325ce88d09ef Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 13 May 2024 12:45:29 +0100 Subject: [PATCH] gdbus: Use symbolic constants to subscribe to message bus signals Unlike the various functions to call D-Bus methods, these sort their arguments in a non-obvious order (bus name, interface, signal, path), presumably aiming to sort the most-likely-to-be-used arguments first. Signed-off-by: Simon McVittie --- gio/gapplicationimpl-dbus.c | 6 +++--- gio/gdbusnameowning.c | 12 ++++++------ gio/gdbusnamewatching.c | 6 +++--- gio/gdbusproxy.c | 6 +++--- gio/tests/gdbus-connection.c | 18 +++++++++--------- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/gio/gapplicationimpl-dbus.c b/gio/gapplicationimpl-dbus.c index 0dc3c1c69..23bf5f911 100644 --- a/gio/gapplicationimpl-dbus.c +++ b/gio/gapplicationimpl-dbus.c @@ -511,10 +511,10 @@ g_application_impl_attempt_primary (GApplicationImpl *impl, if (app_flags & G_APPLICATION_ALLOW_REPLACEMENT) { impl->name_lost_signal = g_dbus_connection_signal_subscribe (impl->session_bus, - "org.freedesktop.DBus", - "org.freedesktop.DBus", + DBUS_SERVICE_DBUS, + DBUS_INTERFACE_DBUS, "NameLost", - "/org/freedesktop/DBus", + DBUS_PATH_DBUS, impl->bus_name, G_DBUS_SIGNAL_FLAGS_NONE, name_lost, diff --git a/gio/gdbusnameowning.c b/gio/gdbusnameowning.c index 27036beb5..53bab8f6b 100644 --- a/gio/gdbusnameowning.c +++ b/gio/gdbusnameowning.c @@ -419,10 +419,10 @@ has_connection (Client *client) * ensure that the user callbacks get called an appropriate number of times. */ client->name_lost_subscription_id = g_dbus_connection_signal_subscribe (client->connection, - "org.freedesktop.DBus", - "org.freedesktop.DBus", + DBUS_SERVICE_DBUS, + DBUS_INTERFACE_DBUS, "NameLost", - "/org/freedesktop/DBus", + DBUS_PATH_DBUS, client->name, G_DBUS_SIGNAL_FLAGS_NONE, on_name_lost_or_acquired, @@ -430,10 +430,10 @@ has_connection (Client *client) (GDestroyNotify) client_unref); client->name_acquired_subscription_id = g_dbus_connection_signal_subscribe (client->connection, - "org.freedesktop.DBus", - "org.freedesktop.DBus", + DBUS_SERVICE_DBUS, + DBUS_INTERFACE_DBUS, "NameAcquired", - "/org/freedesktop/DBus", + DBUS_PATH_DBUS, client->name, G_DBUS_SIGNAL_FLAGS_NONE, on_name_lost_or_acquired, diff --git a/gio/gdbusnamewatching.c b/gio/gdbusnamewatching.c index aa7027033..a76a89fc7 100644 --- a/gio/gdbusnamewatching.c +++ b/gio/gdbusnamewatching.c @@ -504,10 +504,10 @@ has_connection (Client *client) /* start listening to NameOwnerChanged messages immediately */ client->name_owner_changed_subscription_id = g_dbus_connection_signal_subscribe (client->connection, - "org.freedesktop.DBus", /* name */ - "org.freedesktop.DBus", /* if */ + DBUS_SERVICE_DBUS, + DBUS_INTERFACE_DBUS, "NameOwnerChanged", /* signal */ - "/org/freedesktop/DBus", /* path */ + DBUS_PATH_DBUS, client->name, G_DBUS_SIGNAL_FLAGS_NONE, on_name_owner_changed, diff --git a/gio/gdbusproxy.c b/gio/gdbusproxy.c index 36979eab0..ac83cfc71 100644 --- a/gio/gdbusproxy.c +++ b/gio/gdbusproxy.c @@ -1719,10 +1719,10 @@ async_initable_init_first (GAsyncInitable *initable) { proxy->priv->name_owner_changed_subscription_id = g_dbus_connection_signal_subscribe (proxy->priv->connection, - "org.freedesktop.DBus", /* name */ - "org.freedesktop.DBus", /* interface */ + DBUS_SERVICE_DBUS, + DBUS_INTERFACE_DBUS, "NameOwnerChanged", /* signal name */ - "/org/freedesktop/DBus", /* path */ + DBUS_PATH_DBUS, proxy->priv->name, /* arg0 */ signal_flags, on_name_owner_changed, diff --git a/gio/tests/gdbus-connection.c b/gio/tests/gdbus-connection.c index 03759d71e..40c68ac11 100644 --- a/gio/tests/gdbus-connection.c +++ b/gio/tests/gdbus-connection.c @@ -214,10 +214,10 @@ test_connection_life_cycle (void) /* signal registration */ g_atomic_int_set (&on_signal_registration_freed_called, FALSE); g_dbus_connection_signal_subscribe (c2, - "org.freedesktop.DBus", /* bus name */ - "org.freedesktop.DBus", /* interface */ + DBUS_SERVICE_DBUS, + DBUS_INTERFACE_DBUS, "NameOwnerChanged", /* member */ - "/org/freedesktop/DBus", /* path */ + DBUS_PATH_DBUS, NULL, /* arg0 */ G_DBUS_SIGNAL_FLAGS_NONE, on_name_owner_changed, @@ -619,10 +619,10 @@ test_connection_signals (void) &count_s2, NULL); s3 = g_dbus_connection_signal_subscribe (c1, - "org.freedesktop.DBus", /* sender */ - "org.freedesktop.DBus", /* interface */ + DBUS_SERVICE_DBUS, + DBUS_INTERFACE_DBUS, "NameOwnerChanged", /* member */ - "/org/freedesktop/DBus", /* path */ + DBUS_PATH_DBUS, NULL, G_DBUS_SIGNAL_FLAGS_NONE, test_connection_signal_handler, @@ -1115,10 +1115,10 @@ test_connection_filter (void) /* wait for service to be available */ signal_handler_id = g_dbus_connection_signal_subscribe (c, - "org.freedesktop.DBus", /* sender */ - "org.freedesktop.DBus", + DBUS_SERVICE_DBUS, + DBUS_INTERFACE_DBUS, "NameOwnerChanged", - "/org/freedesktop/DBus", + DBUS_PATH_DBUS, NULL, /* arg0 */ G_DBUS_SIGNAL_FLAGS_NONE, test_connection_filter_name_owner_changed_signal_handler,