[DBUS] Observer pattern design
twogood at users.sourceforge.net
Mon May 23 11:37:05 PDT 2005
On Mon, 2005-05-23 at 15:06 -0300, Claudio Takahasi wrote:
> Hi folks,
> What is the correct design for a observer* pattern application using D-BUS?
> Suppose a wireless connection manager, when the signal is weak or
> the link is down, the connection manager must notify all connected clients.
> Implement the other side(clients requiresting services) is trivial. There
> are a lot of sample addressing this context. However, for a observer
> pattern I was not able to figure out how implement it. I think use polling
> is NOT a interesting approach.
> What are the possible implementations for this kind of D-BUS application?
First a disclaimer:
1. I'm just a humble (ab)user of D-BUS and a Python newbie
2. I have currently only (ab)used D-BUS 0.2x
Now I can share what I've done for an observer-like pattern:
I have an interface with a Subscribe method in a C++ daemon. In order to
know who subscribed, I save the value of dbus_message_get_sender() for
the message containing the Subscribe call. The Subscribe method returns
an object path.
When I have an event I want to share with my subscribers, I create and
send a method call for each subscriber with the same path as returned to
the subscriber from the Subscribe method.
In the Python client I created a special class for the base service:
def __init__(self, bus):
self._service_name = bus.get_connection().get_base_service()
self._bus = bus
An instance of this class is used as a parameter to
dbus.Object.__init__(), something like this:
def __init__(self, name, type, path, base_service):
def SomeEventISubscribeTo(self, message, param1, param2):
print "event received!"
-\- David Eriksson -/-
SynCE - http://synce.sourceforge.net
ScummVM - http://scummvm.sourceforge.net
Desquirr - http://desquirr.sourceforge.net
More information about the dbus