How to check if sender of message still exists?

Ryan Lortie desrt at desrt.ca
Thu Jun 9 07:04:00 PDT 2011


hi,

Just a few more clarifications on what Simon said.

On Thu, 2011-06-09 at 11:41 +0100, Simon McVittie wrote: 
> If you're listening for the NameOwnerChanged signal you will see the ownership
> of the plugin's unique name change from itself to the empty string:
> 
>     NameOwnerChanged(":1.407", ":1.407", "")

It's best to do this using the 'arg0' signal matching parameter.  This
prevents you from receiving *all* NameOwnerChanged signals needlessly.

Also, be sure to verify that the name actually exists *after* you
subscribe to the NameOwnerChanged signal.  You can do this with the
NameHasOwner call.  If you don't do this, it's possible to subject
yourself to a race whereby the client exits immediately after sending a
message and you subscribe to NameOwnerChanged after it is already gone.

> See the D-Bus Specification for more about NameOwnerChanged, or (for instance)
> tp_dbus_daemon_watch_name_owner() in telepathy-glib for example.code.

In GDBus, g_bus_watch_name().

In general, you are advised to attempt to use one of these high-level
facilities as provided by a D-Bus client library instead of rolling your
own.  It's very easy to make a couple of common mistakes when
implementing this pattern, and the authors of these libraries have spent
more time understanding the problem than you probably care to.

Cheers



More information about the dbus mailing list