Receiving signals the easy way?

Kees Jongenburger kees.jongenburger at gmail.com
Sun Nov 1 06:34:25 PST 2009


Hi Will

On Sun, Nov 1, 2009 at 1:44 PM, Will Thompson
<will.thompson at collabora.co.uk> wrote:
> On 01/11/09 12:38, Kees Jongenburger wrote:
>> dbus-send \
>>         --system \
>>         /com/test/Notification \
>>         com.test.Notification.Notify
>
> a service connects to the bus, receives a unique name like :1.23, and
> emits the com.test.Notification.Notify signal from its
> /com/test/Notification object. But you bound to signal emissions by
> com.test.Notification, not :1.23.

Thanks for clarifying what is happening. I am apparently trying to use
signals to broadcast changes. This doesn't work
because signals are "sent" from object and not fired at.

Part of what I am trying to achieve is for a UI to be aware of what is
happening downstairs and part of that design is that I don't want the
lower processes to call upon a interface of a higher layer.

on IRC Will suggested the following and I think this might be the
proper way of doing this:

Make all the processes take a name of the form
com.your.domain.Service.* for some *. And have the UI watch
NameOwnerChanged for people taking such names. Then make each service
have an object /com/your/domain/Service/Foo implementing the
com.your.domain.Service interface, with a signal that the UI listens
to

pseudo code:
def name_owner_changed_cb( name, old owner, new owner):
     if name.starts_with("com.your.domain.Service.") and new_owner != "":
         proxy = ProxyObject(name=name, path=("/" +
name.replace_all(".", "/")), interface="com.your.domain.Service")
         proxy.connect_to_signal("Notify", notify_cb)
 and in the "foo" service:
 def main():
     connect to the bus
     bus.RequestName("com.your.domain.Service.foo")

For the moment I went for a different approach (less code) and I am
possibly misusing signals. I used, thanks for WIll's hint, a lower
level API to allow myself to register a dbus match rule.

so I copied the code from here
http://www.ibm.com/developerworks/linux/library/l-dbus.html and
modified it to
http://github.com/keesj/dbus_glib_pthread/raw/master/notification_test2.c

Thanks for the help!


More information about the dbus mailing list