Is it possible that a service object gets a notification when a client closes dbus connection?

Simon McVittie simon.mcvittie at collabora.co.uk
Mon Mar 31 04:07:29 PDT 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, 31 Mar 2008 at 18:21:08 +0800, Huang Peng wrote:
> I want to develop a service object in the SessionBus. This object wants
> to track which clients are reference it. Is it possible that the service
> object get a notification when a client's connection is closed.

Yes. Keep track of the unique names of clients who are referencing the
service (unique names look like ":1.42"); you can get these from the
method call message when they call any of your methods. If you're using
this pattern, you might have to require that all clients call some sort
of IAmInterested() method on your service).

When the client falls off the bus for any reason (deliberate disconnection,
segfault, kill -9, whatever) you will receive a signal like this:

    org.freedesktop.DBus.NameOwnerChanged(":1.42", ":1.42", "")

from the bus daemon. The empty string as the "new owner" argument
indicates that the unique name is now unowned (the process has
disconnected from the bus).

You'll need to register with the bus daemon as being interested in that
signal - ideally, use argument-matching (e.g. 'arg0=":1.42"') to avoid
unnecessary wakeups.

    Simon
-----BEGIN PGP SIGNATURE-----

iD8DBQFH8MXxWSc8zVUw7HYRAixIAKDq7EbKvT4Ofw1FhxZR312ZpBPu+QCcCAJj
pDCLRYhXzkt6xruV/zaCFzA=
=xkJv
-----END PGP SIGNATURE-----


More information about the dbus mailing list