4 python example-signal-emitter.py &
5 python example-signal-recipient.py
6 python example-signal-recipient.py --exit-service
15 import dbus
.decorators
16 import dbus
.mainloop
.glib
18 def handle_reply(msg
):
25 #call the emitHelloSignal method
26 object.emitHelloSignal(dbus_interface
="com.example.TestService")
27 #reply_handler = handle_reply, error_handler = handle_error)
28 # exit after waiting a short time for the signal
29 gobject
.timeout_add(2000, loop
.quit
)
31 if sys
.argv
[1:] == ['--exit-service']:
32 object.Exit(dbus_interface
='com.example.TestService')
36 def hello_signal_handler(hello_string
):
37 print ("Received signal (by connecting using remote object) and it says: "
40 def catchall_signal_handler(*args
, **kwargs
):
41 print ("Caught signal (in catchall handler) "
42 + kwargs
['dbus_interface'] + "." + kwargs
['member'])
46 def catchall_hello_signals_handler(hello_string
):
47 print "Received a hello signal and it says " + hello_string
49 def catchall_testservice_interface_handler(hello_string
, dbus_message
):
50 print "com.example.TestService interface says " + hello_string
+ " when it sent signal " + dbus_message
.get_member()
53 if __name__
== '__main__':
54 dbus
.mainloop
.glib
.DBusGMainLoop(set_as_default
=True)
56 bus
= dbus
.SessionBus()
58 object = bus
.get_object("com.example.TestService","/com/example/TestService/object")
60 object.connect_to_signal("HelloSignal", hello_signal_handler
, dbus_interface
="com.example.TestService", arg0
="Hello")
61 except dbus
.DBusException
:
67 bus
.add_signal_receiver(catchall_signal_handler
, interface_keyword
='dbus_interface', member_keyword
='member')
69 bus
.add_signal_receiver(catchall_hello_signals_handler
, dbus_interface
= "com.example.TestService", signal_name
= "HelloSignal")
71 bus
.add_signal_receiver(catchall_testservice_interface_handler
, dbus_interface
= "com.example.TestService", message_keyword
='dbus_message')
73 # Tell the remote object to emit the signal after a short delay
74 gobject
.timeout_add(2000, emit_signal
)
76 loop
= gobject
.MainLoop()