1

I'm trying to find out the best way to acquire the unique D-Bus address of an object in the D-Bus system bus using the GDBus library on Linux.

Here are version numbers of the libraries I am using:

# ls /usr/lib |grep -e dbus -e glib -e gio
libdbus-1.so
libdbus-1.so.3
libdbus-1.so.3.14.11
libdbus-glib-1.so
libdbus-glib-1.so.2
libdbus-glib-1.so.2.3.3
libgio-2.0.so
libgio-2.0.so.0
libgio-2.0.so.0.5000.3
libglib-2.0.so
libglib-2.0.so.0
libglib-2.0.so.0.5000.3

Basically, I want to know the unique name/address of the object /org/bluez/hci0 located on the system bus using gdbus library. Does anyone have an example of how I would do this using the C library?

Right now I can use the command

# dbus-monitor --system

To figure out that the address I need is :1.22. I'm almost certain that there's a better way to find the address then parsing the text output of that command.

Thanks!

Philip Withnall
  • 5,293
  • 14
  • 28
zeus_masta_funk
  • 1,388
  • 2
  • 11
  • 34
  • Why not use the well-known name of the service (and if you want to keep track of the current unique owner, use g_bus_watch_name() to get it). In fact, I don't think there's ever a reason to find "/org/bluez/hci0" as you should be using D-Bus ObjectManager API to find the objects/interfaces that bluez exports – Jussi Kukkonen Jul 15 '17 at 09:19
  • 1
    @jku This is the correct answer. If I look here https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt?h=5.44 I can see the well known name (service name). As this is my first time working with DBus I didn't realize that service name and well known name were the same thing. Post your comment below and I'll mark it as the answer. – zeus_masta_funk Jul 15 '17 at 14:50

2 Answers2

1

Why not use the well-known name of the service to find it (and if you want to keep track of the current unique owner, use g_bus_watch_name() to get it).

In fact, in the case of bluez I don't think there's ever a reason to search for "/org/bluez/hci0" as you should be using D-Bus ObjectManager API to find the objects/interfaces that the bluez service exports.

Jussi Kukkonen
  • 13,857
  • 1
  • 37
  • 54
0

To clarify some of the concepts here:

  • D-Bus address: There is no such thing as an ‘address’ in D-Bus in the way you’re thinking. There are object paths, well-known names and unique names. The term ‘address’ is used to describe the socket path which clients use to connect to the dbus-daemon, but this is unrelated to what you’re asking.
  • Unique name: Like :1.22, this uniquely identifies a particular connection to the dbus-daemon. Typically, each application has one connection to the daemon, so this typically identifies a single application. (However, applications can have more than one connection to the bus if they want; if so, each connection would have a different unique address). A well-known name is a consistent name for a service’s connection to the dbus-daemon, which is used as an alias for its unique name. For example, org.bluez or org.freedesktop.FileManager1 are both well-known names.
  • Object address: Like /org/freedesktop/SomeService/blah, this is actually called an object path. Object paths are only unique within the context of a single D-Bus connection, so the path /a/b/c will typically refer to different objects for D-Bus connections :1.1 and :1.2. (Hence the question “how can I find the unique name of the object path /a/b/c?” is ill-formed, because there may be many unique names which export such an object.)
Philip Withnall
  • 5,293
  • 14
  • 28