Multiple implementation of the same object
kalle.vahlman at gmail.com
Tue Dec 2 06:34:39 PST 2008
2008/12/2 Lionel Dricot <zeploum at gmail.com>:
> I want to use D-Bus to allow one "client" to get some information from a
> "service" object. But this service object could be implemented multiple
> times. I want to be able to just launch a new implementation of "service" in
> the pool without having to change the "client" implementation at all. Client
> should automatically use the the service with the highest priority.
> So, how would you do that ?
When D-Bus services register bus names they can determine with flags
how they react when someone else owns the name or tries to register
the same name. Also you get signals (NameOwnerChanged and NameLost)
from the Bus when such activity occurs.
So in your example, the local service (high priority) should request
the service name with the flag (names from the low-level lib)
DBUS_NAME_FLAG_REPLACE_EXISTING so it replaces any other service using
The website service then requests the same bus name with
DBUS_NAME_FLAG_ALLOW_REPLACEMENT so that the higher priority service
can always snatch it when it comes around again.
If you need more featureful priority handling than high/low, you'll
need to implement some sort of negotiation between the service
instances, but the client side still doesn't need to know about it.
More details about requesting names:
Kalle Vahlman, zuh at iki.fi
Powered by http://movial.fi
Interesting stuff at http://sandbox.movial.com
See also http://syslog.movial.fi
More information about the dbus