gdbus: Use symbolic constants to call message bus methods

These function arguments are arranged in the obvious order from
conceptually largest to smallest: (bus name, path, interface, method).

Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2024-05-13 12:24:16 +01:00 committed by Philip Withnall
parent 2151a82007
commit fe14968c0d
13 changed files with 105 additions and 97 deletions

View File

@ -32,6 +32,7 @@
#include "gdbusconnection.h"
#include "gdbusintrospection.h"
#include "gdbuserror.h"
#include "gdbusprivate.h"
#include "glib/gstdio.h"
#include <string.h>
@ -526,9 +527,9 @@ g_application_impl_attempt_primary (GApplicationImpl *impl,
name_owner_flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE;
reply = g_dbus_connection_call_sync (impl->session_bus,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"RequestName",
g_variant_new ("(su)", impl->bus_name, name_owner_flags),
G_VARIANT_TYPE ("(u)"),
@ -599,8 +600,8 @@ g_application_impl_stop_primary (GApplicationImpl *impl)
if (impl->primary && impl->bus_name)
{
g_dbus_connection_call (impl->session_bus, "org.freedesktop.DBus",
"/org/freedesktop/DBus", "org.freedesktop.DBus",
g_dbus_connection_call (impl->session_bus, DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
"ReleaseName", g_variant_new ("(s)", impl->bus_name),
NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
impl->primary = FALSE;

View File

@ -37,9 +37,10 @@
#ifdef G_OS_WIN32
#include "glib/glib-private.h"
#include "gdbusprivate.h"
#endif
#include "gdbusprivate.h"
/* ---------------------------------------------------------------------------------------------------- */
/* Escape values for console colors */
@ -332,9 +333,9 @@ print_names (GDBusConnection *c,
error = NULL;
result = g_dbus_connection_call_sync (c,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"ListNames",
NULL,
G_VARIANT_TYPE ("(as)"),
@ -356,9 +357,9 @@ print_names (GDBusConnection *c,
error = NULL;
result = g_dbus_connection_call_sync (c,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"ListActivatableNames",
NULL,
G_VARIANT_TYPE ("(as)"),

View File

@ -2972,9 +2972,9 @@ initable_init (GInitable *initable,
}
hello_result = g_dbus_connection_call_sync (connection,
"org.freedesktop.DBus", /* name */
"/org/freedesktop/DBus", /* path */
"org.freedesktop.DBus", /* interface */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"Hello",
NULL, /* parameters */
G_VARIANT_TYPE ("(s)"),
@ -3655,9 +3655,9 @@ add_match_rule (GDBusConnection *connection,
if (match_rule[0] == '-')
return;
message = g_dbus_message_new_method_call ("org.freedesktop.DBus", /* name */
"/org/freedesktop/DBus", /* path */
"org.freedesktop.DBus", /* interface */
message = g_dbus_message_new_method_call (DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"AddMatch");
g_dbus_message_set_body (message, g_variant_new ("(s)", match_rule));
error = NULL;
@ -3686,9 +3686,9 @@ remove_match_rule (GDBusConnection *connection,
if (match_rule[0] == '-')
return;
message = g_dbus_message_new_method_call ("org.freedesktop.DBus", /* name */
"/org/freedesktop/DBus", /* path */
"org.freedesktop.DBus", /* interface */
message = g_dbus_message_new_method_call (DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"RemoveMatch");
g_dbus_message_set_body (message, g_variant_new ("(s)", match_rule));

View File

@ -443,9 +443,9 @@ has_connection (Client *client)
/* attempt to acquire the name */
client->needs_release = TRUE;
g_dbus_connection_call (client->connection,
"org.freedesktop.DBus", /* bus name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface name */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"RequestName", /* method name */
g_variant_new ("(su)",
client->name,
@ -936,9 +936,9 @@ g_bus_unown_name (guint owner_id)
*/
error = NULL;
result = g_dbus_connection_call_sync (client->connection,
"org.freedesktop.DBus", /* bus name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface name */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"ReleaseName", /* method name */
g_variant_new ("(s)", client->name),
G_VARIANT_TYPE ("(u)"),

View File

@ -424,9 +424,9 @@ static void
invoke_get_name_owner (Client *client)
{
g_dbus_connection_call (client->connection,
"org.freedesktop.DBus", /* bus name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface name */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetNameOwner", /* method name */
g_variant_new ("(s)", client->name),
G_VARIANT_TYPE ("(s)"),
@ -517,9 +517,9 @@ has_connection (Client *client)
if (client->flags & G_BUS_NAME_WATCHER_FLAGS_AUTO_START)
{
g_dbus_connection_call (client->connection,
"org.freedesktop.DBus", /* bus name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface name */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"StartServiceByName", /* method name */
g_variant_new ("(su)", client->name, 0),
G_VARIANT_TYPE ("(u)"),

View File

@ -1145,9 +1145,9 @@ subscribe_signals (GDBusObjectManagerClient *manager,
/* The bus daemon may not implement path_namespace so gracefully
* handle this by using a fallback triggered if @error is set. */
ret = g_dbus_connection_call_sync (manager->priv->connection,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"AddMatch",
g_variant_new ("(s)",
manager->priv->match_rule),
@ -1230,9 +1230,9 @@ maybe_unsubscribe_signals (GDBusObjectManagerClient *manager)
* fail - therefore, don't bother checking the return value
*/
g_dbus_connection_call (manager->priv->connection,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"RemoveMatch",
g_variant_new ("(s)",
manager->priv->match_rule),

View File

@ -1485,9 +1485,9 @@ async_init_call_get_name_owner (GTask *task)
GDBusProxy *proxy = g_task_get_source_object (task);
g_dbus_connection_call (proxy->priv->connection,
"org.freedesktop.DBus", /* name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetNameOwner",
g_variant_new ("(s)",
proxy->priv->name),
@ -1594,9 +1594,9 @@ async_init_call_start_service_by_name (GTask *task)
GDBusProxy *proxy = g_task_get_source_object (task);
g_dbus_connection_call (proxy->priv->connection,
"org.freedesktop.DBus", /* name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"StartServiceByName",
g_variant_new ("(su)",
proxy->priv->name,

View File

@ -22,6 +22,7 @@
#include "giomodule-priv.h"
#include "gdbusconnection.h"
#include "gdbusprivate.h"
#include "gapplication.h"
#include "gnotification-private.h"
@ -58,8 +59,8 @@ g_gtk_notification_backend_is_supported (void)
if (session_bus == NULL)
return FALSE;
reply = g_dbus_connection_call_sync (session_bus, "org.freedesktop.DBus", "/org/freedesktop/DBus",
"org.freedesktop.DBus",
reply = g_dbus_connection_call_sync (session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetNameOwner", g_variant_new ("(s)", "org.gtk.Notifications"),
G_VARIANT_TYPE ("(s)"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);

View File

@ -26,6 +26,7 @@
#include <sys/types.h>
#include "gdbusprivate.h"
#include "gdbus-tests.h"
/* all tests rely on a shared mainloop */
@ -424,9 +425,9 @@ test_connection_send (void)
ca = g_cancellable_new ();
g_cancellable_cancel (ca);
g_dbus_connection_call (c,
"org.freedesktop.DBus", /* bus_name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface name */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetId", /* method name */
NULL, NULL,
G_DBUS_CALL_FLAGS_NONE,
@ -441,9 +442,9 @@ test_connection_send (void)
* Check that we get a reply to the GetId() method call.
*/
g_dbus_connection_call (c,
"org.freedesktop.DBus", /* bus_name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface name */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetId", /* method name */
NULL, NULL,
G_DBUS_CALL_FLAGS_NONE,
@ -457,9 +458,9 @@ test_connection_send (void)
* Check that we get an error reply to the NonExistantMethod() method call.
*/
g_dbus_connection_call (c,
"org.freedesktop.DBus", /* bus_name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface name */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"NonExistantMethod", /* method name */
NULL, NULL,
G_DBUS_CALL_FLAGS_NONE,
@ -474,9 +475,9 @@ test_connection_send (void)
*/
ca = g_cancellable_new ();
g_dbus_connection_call (c,
"org.freedesktop.DBus", /* bus_name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface name */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetId", /* method name */
NULL, NULL,
G_DBUS_CALL_FLAGS_NONE,
@ -497,9 +498,9 @@ test_connection_send (void)
g_assert_true (g_dbus_connection_is_closed (c));
g_dbus_connection_call (c,
"org.freedesktop.DBus", /* bus_name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface name */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetId", /* method name */
NULL, NULL,
G_DBUS_CALL_FLAGS_NONE,
@ -687,9 +688,9 @@ test_connection_signals (void)
* To ensure this is not the case, do a synchronous call on c1.
*/
result = g_dbus_connection_call_sync (c1,
"org.freedesktop.DBus", /* bus name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface name */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetId", /* method name */
NULL, /* parameters */
NULL, /* return type */
@ -1047,9 +1048,9 @@ test_connection_filter (void)
&data,
NULL);
m = g_dbus_message_new_method_call ("org.freedesktop.DBus", /* name */
"/org/freedesktop/DBus", /* path */
"org.freedesktop.DBus", /* interface */
m = g_dbus_message_new_method_call (DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetNameOwner");
g_dbus_message_set_body (m, g_variant_new ("(s)", "org.freedesktop.DBus"));
error = NULL;
@ -1197,9 +1198,9 @@ send_bogus_message (GDBusConnection *c, guint32 *out_serial)
GDBusMessage *m;
GError *error;
m = g_dbus_message_new_method_call ("org.freedesktop.DBus", /* name */
"/org/freedesktop/DBus", /* path */
"org.freedesktop.DBus", /* interface */
m = g_dbus_message_new_method_call (DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetNameOwner");
g_dbus_message_set_body (m, g_variant_new ("(s)", "org.freedesktop.DBus"));
error = NULL;

View File

@ -25,6 +25,7 @@
#include <unistd.h>
#include <string.h>
#include "gdbusprivate.h"
#include "gdbus-tests.h"
/* all tests rely on a shared mainloop */
@ -137,9 +138,9 @@ test_exit_on_close_subprocess (gconstpointer test_data)
GVariant *v;
GError *error = NULL;
v = g_dbus_connection_call_sync (c, "org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
v = g_dbus_connection_call_sync (c, DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"ListNames",
NULL,
G_VARIANT_TYPE ("(as)"),

View File

@ -25,6 +25,7 @@
#include <gio/gio.h>
#include <unistd.h>
#include "gdbusprivate.h"
#include "gdbus-tests.h"
/* ---------------------------------------------------------------------------------------------------- */
@ -181,9 +182,9 @@ test_bus_own_name (void)
g_assert (c != NULL);
g_assert (!g_dbus_connection_is_closed (c));
result = g_dbus_connection_call_sync (c,
"org.freedesktop.DBus", /* bus name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface name */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"NameHasOwner", /* method name */
g_variant_new ("(s)", name),
G_VARIANT_TYPE ("(b)"),
@ -209,9 +210,9 @@ test_bus_own_name (void)
* Check that the name was actually released.
*/
result = g_dbus_connection_call_sync (c,
"org.freedesktop.DBus", /* bus name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface name */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"NameHasOwner", /* method name */
g_variant_new ("(s)", name),
G_VARIANT_TYPE ("(b)"),

View File

@ -24,6 +24,7 @@
#include <unistd.h>
#include <string.h>
#include "gdbusprivate.h"
#include "gdbus-tests.h"
/* all tests rely on a shared mainloop */
@ -757,9 +758,9 @@ kill_test_service (GDBusConnection *connection)
gboolean name_disappeared = FALSE;
ret = g_dbus_connection_call_sync (connection,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetConnectionUnixProcessID",
g_variant_new ("(s)", name),
NULL,
@ -977,9 +978,9 @@ add_or_remove_match_rule (GDBusConnection *connection,
GDBusMessage *message = NULL;
GError *error = NULL;
message = g_dbus_message_new_method_call ("org.freedesktop.DBus", /* name */
"/org/freedesktop/DBus", /* path */
"org.freedesktop.DBus", /* interface */
message = g_dbus_message_new_method_call (DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
(add_or_remove == ADD_MATCH) ? "AddMatch" : "RemoveMatch");
g_dbus_message_set_body (message, match_rule);
g_dbus_connection_send_message (connection,

View File

@ -24,6 +24,7 @@
#include <unistd.h>
#include <string.h>
#include "gdbusprivate.h"
#include "gdbus-tests.h"
/* all tests rely on a global connection */
@ -185,9 +186,9 @@ test_delivery_in_thread_func (gpointer _data)
* Check that we get a reply to the GetId() method call.
*/
g_dbus_connection_call (c,
"org.freedesktop.DBus", /* bus_name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface name */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetId", /* method name */
NULL, NULL,
G_DBUS_CALL_FLAGS_NONE,
@ -212,9 +213,9 @@ test_delivery_in_thread_func (gpointer _data)
ca = g_cancellable_new ();
g_cancellable_cancel (ca);
g_dbus_connection_call (c,
"org.freedesktop.DBus", /* bus_name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface name */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetId", /* method name */
NULL, NULL,
G_DBUS_CALL_FLAGS_NONE,
@ -239,9 +240,9 @@ test_delivery_in_thread_func (gpointer _data)
*/
ca = g_cancellable_new ();
g_dbus_connection_call (c,
"org.freedesktop.DBus", /* bus_name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface name */
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetId", /* method name */
NULL, NULL,
G_DBUS_CALL_FLAGS_NONE,
@ -563,8 +564,8 @@ ensure_connection_works (GDBusConnection *conn)
GVariant *v;
GError *error = NULL;
v = g_dbus_connection_call_sync (conn, "org.freedesktop.DBus",
"/org/freedesktop/DBus", "org.freedesktop.DBus", "GetId", NULL, NULL, 0, -1,
v = g_dbus_connection_call_sync (conn, DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "GetId", NULL, NULL, 0, -1,
NULL, &error);
g_assert_no_error (error);
g_assert_nonnull (v);