Reputation: 1498
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!
Upvotes: 1
Views: 1969
Reputation: 5768
To clarify some of the concepts here:
: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./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.)Upvotes: 0
Reputation: 14617
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.
Upvotes: 1