[DBUS] Observer pattern design

Julien PUYDT julien.puydt at laposte.net
Mon May 23 11:51:45 PDT 2005

David Eriksson a écrit :
> 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 

Take what I write below with a grain of salt, because (1) also applies 
to me.

> 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.

What you do looks terribly complicated: you basically implement a 
registration system in your subject! And I guess observers have to make 
sure they unregister cleanly from the subject... which makes much code 
on either end.

If you do the same with signals, the dbus will take care of all 
registering and unregistering for you. That makes both the subject and 
the observers simpler to code.

Snark on #gnomemeeting

More information about the dbus mailing list