|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Receiving signals the easy way?Hi
I am trying to receive a signal in my dbus-glib based program. I found a good example on the net to listen to dbus signals itself but am currently failing to implement it for my own purposes. the code looks pretty much like this (the real code can be fetched from ( http://github.com/keesj/dbus_glib_pthread/raw/master/notification_test.c ) /* get a system bus create a proxy object register a known signal called Notify with no parameters register a callback runt the main loop */ connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); proxy = dbus_g_proxy_new_for_name(connection, "com.test.Notification", "/com/test/Notification", "com.test.Notification"); dbus_g_proxy_add_signal(proxy, "Notify",G_TYPE_INVALID); dbus_g_proxy_connect_signal(proxy, "Notify", test_callback, NULL, NULL); ================= After that I call dbus-send \ --system \ /com/test/Notification \ com.test.Notification.Notify but don't receive anything in my callback so I must be missing something. I implemented the same signal listener in java (http://github.com/keesj/dbus_glib_pthread/java) and that one works like a charm. This leave me with the following questions 1) what am I doing wrong? 2) in this situation there is no object registered on the bus called Notification, who owns the signal interface? 3) Is there any form of security that I might be missing (can everybody send signals to everybody and can everybody listen?) Greetings _______________________________________________ dbus mailing list dbus@... http://lists.freedesktop.org/mailman/listinfo/dbus |
|
|
Re: Receiving signals the easy way?On 01/11/09 12:38, Kees Jongenburger wrote:
> proxy = dbus_g_proxy_new_for_name(connection, "com.test.Notification", > "/com/test/Notification", > "com.test.Notification"); You've constructed a proxy for an object on the bus name "com.test.Notification"... > dbus_g_proxy_add_signal(proxy, "Notify",G_TYPE_INVALID); > dbus_g_proxy_connect_signal(proxy, "Notify", test_callback, NULL, NULL); and bound to the Notify signal. Then: > 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. -- Will _______________________________________________ dbus mailing list dbus@... http://lists.freedesktop.org/mailman/listinfo/dbus |
|
|
Re: Receiving signals the easy way?Hi Will
On Sun, Nov 1, 2009 at 1:44 PM, Will Thompson <will.thompson@...> 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! _______________________________________________ dbus mailing list dbus@... http://lists.freedesktop.org/mailman/listinfo/dbus |
| Free embeddable forum powered by Nabble | Forum Help |