Service discovery on message bus

Simon McVittie smcv at collabora.com
Fri Mar 23 14:33:13 UTC 2018


On Fri, 23 Mar 2018 at 14:18:30 +0000, Simon McVittie wrote:
> On Fri, 23 Mar 2018 at 13:47:07 +0100, Umut Tezduyar Lindskog wrote:
> > introspection of
> > each objects in the service or relaying on the fact that services are
> > implementing org.freedesktop.DBus.ObjectManager interface

If the service guarantees to implement org.freedesktop.DBus.ObjectManager
at a particular object path, then that is part of the definition of how
that service works. In that case, making use of that interface is not a
bug or a design flaw, it's just part of how you use that service.

If you are doing something useful with all the objects exported by a
service, you'll likely have to list those objects one way or another
*anyway*, so that might as well be your starting point. If you are only
operating on a subset of the objects, you presumably found out the object
paths of those objects somehow, in which case introspecting the rest of
the objects is unnecessary: you can proceed by inspecting the objects
of interest and ignoring the rest.

> Finally, the recommended pattern for discovering services that your
> application wishes to use does not actually involve ListNames. To avoid
> time-of-check/time-of-use errors, if your application wishes to make
> use of a service, the recommended way to proceed is to try to
> communicate with that service by its well-known name (the "leap before
> you look" or "better to ask forgiveness than permission" model).

A very common pattern is that this initial communication is precisely
to call the method that tells you which objects are available, for
example the GetManagedObjects() method call for an ObjectManager,
the GetAll() method call that lists the AccountManager properties for a
Telepathy AccountManager (which includes the list of accounts), or the
GetAllDevices() method call for NetworkManager.

If you have not set the flag that prevents auto-starting, this method
call will even start the service for you, removing the need to find out
whether the service is currently running or not: by the time you get
a successful reply, you know the answer is "yes".

    smcv


More information about the dbus mailing list