Query using D-bus

Simon McVittie simon.mcvittie at collabora.co.uk
Thu Dec 6 04:01:55 PST 2012


On 06/12/12 10:53, Keyur wrote:
> I am using Qt Application for creating D-bus service on session bus.

This application will be given a unique bus name by the bus daemon
(let's assume for the example below that it's ":1.42"), and it probably
also claims one or more well-known bus names (like
"com.einfochips.keyur.MyService" or something).

> when Qt application killed at that time i want to notify my c++ client
> application about this thing using dbus, that Qt application has killed.

If it adds appropriate match rules, the client will get a
NameOwnerChanged signal from the dbus-daemon, for each of the bus names
that were owned by the Qt application, telling it that the bus name's
owner has changed to "". Something like this:

    NameOwnerChanged("com.einfochips.keyur.MyService", ":1.42", "")
    NameOwnerChanged(":1.42",                          ":1.42", "")

(The parameters are the name being owned, the old owner and the new
owner, in that order. Every unique bus name is considered to be its own
owner.)

The library you're using in your client application (which one are you
using?) should hopefully give you a high-level way to subscribe to
NameOwnerChanged, whose name will probably be something involving
"watching names". In GDBus it's g_bus_watch_name(),
g_bus_watch_name_on_connection() etc.

If it doesn't have that, the next best thing is if it gives you a way to
subscribe to signals. In GDBus this is g_dbus_connection_signal_subscribe().

In libdbus, the low-level library used by dbus-daemon, you would have to
use a combination of dbus_bus_add_match() and
dbus_connection_add_filter(). Don't use libdbus directly if you can
avoid it: it's low-level and requires you to understand quite a lot of
the details of D-Bus, like how to construct match rules.

If you're using one of several "pure C++" libdbus bindings (dbus-c++,
dbus-cxx, dbus-cpp) I have no idea how this works; look through the
documentation for something similar. If there is no documentation,
choose a better binding. None of these bindings appear to be actively
maintained, so if you choose one of these, you will probably have to
maintain it yourself.

In C/C++ code, I recommend using either GDBus (part of GLib) or QtDBus.

    S


More information about the dbus mailing list