Skip to content

gdbus: Make more use of symbolic constants for various aspects of the D-Bus protocol

Simon McVittie requested to merge wip/smcv/more-gdbus-constants into main

Follow-up from 1e648b67, which was a minimal version of this change as part of the fix for #3268 (closed). Using symbolic constants for this stuff makes it more obvious that we're using them correctly, and avoids hard-to-spot typos making some copies of these strings incorrect.

While writing this, I found one (thankfully harmless) typo, which is fixed in the first commit.

No functional changes are intended by this MR, except for fixing the typo (which doesn't affect the success or the failure of the test, so arguably it isn't a functional change either).

Any prefix of this MR can be split into a smaller MR if reviewers would prefer that.


  • gdbus tests: Fix a typo

    This test was subscribing to the NameOwnerChanged signal with an incorrect object path, so the callback would never be called. In this particular case it doesn't actually matter, because the callback does nothing anyway (the purpose of this particular test was to test that the user-data is freed on unsubscription).

  • 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).

  • 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.

  • gdbus: Use symbolic constants for various references to the message bus

  • gdbusdaemon: Use shared constants for message bus name, path, interface

  • gdbus: Move protocol constants from gdbusdaemon into gdbusprivate.h

    These well-known flags and replies are part of the D-Bus Specification, and also exist with the same names in libdbus header files. Moving them into a private header means that unit tests like gdbus-proxy-threads and gdbus-subscribe don't have to reinvent them.

  • gdbus: Use symbolic constants for the reserved Local path and interface

    These are reserved by the D-Bus Specification.

  • gdbus: Use symbolic constants for interfaces from dbus-specification

    Most D-Bus interfaces are domain-specific, but these interfaces from the D-Bus Specification are intended to be commonly used in any context for which they are found to be appropriate.

    Most of these use gdbusprivate.h. One exception is that gio/tests/gdbus-example-* redefine the constants locally: due to these files' dual role as part of the unit tests and as sample code, it seems desirable to ensure that they can still be compiled outside GLib.

  • gdbus: Use symbolic constants for the most common D-Bus error names

    To avoid adding a large block of macros to gdbusprivate.h, I've only added a subset of the well-known error names. I chose to draw the line by adding constants for the errors emitted via their string names in GDBusConnection, but not for error names that are only mentioned in gdbuserror.c or in tests.

Edited by Simon McVittie

Merge request reports