4 python example-signal-emitter.py &
5 python example-signal-recipient.py
6 python example-signal-recipient.py --exit-service
15 import dbus
.mainloop
.glib
17 def handle_reply(msg
):
24 #call the emitHelloSignal method
25 object.emitHelloSignal(dbus_interface
="com.example.TestService")
26 #reply_handler = handle_reply, error_handler = handle_error)
27 # exit after waiting a short time for the signal
28 gobject
.timeout_add(2000, loop
.quit
)
30 if sys
.argv
[1:] == ['--exit-service']:
31 object.Exit(dbus_interface
='com.example.TestService')
35 def hello_signal_handler(hello_string
):
36 print ("Received signal (by connecting using remote object) and it says: "
39 def catchall_signal_handler(*args
, **kwargs
):
40 print ("Caught signal (in catchall handler) "
41 + kwargs
['dbus_interface'] + "." + kwargs
['member'])
45 def catchall_hello_signals_handler(hello_string
):
46 print "Received a hello signal and it says " + hello_string
48 def catchall_testservice_interface_handler(hello_string
, dbus_message
):
49 print "com.example.TestService interface says " + hello_string
+ " when it sent signal " + dbus_message
.get_member()
52 if __name__
== '__main__':
53 dbus
.mainloop
.glib
.DBusGMainLoop(set_as_default
=True)
55 bus
= dbus
.SessionBus()
57 object = bus
.get_object("com.example.TestService","/com/example/TestService/object")
59 object.connect_to_signal("HelloSignal", hello_signal_handler
, dbus_interface
="com.example.TestService", arg0
="Hello")
60 except dbus
.DBusException
:
66 bus
.add_signal_receiver(catchall_signal_handler
, interface_keyword
='dbus_interface', member_keyword
='member')
68 bus
.add_signal_receiver(catchall_hello_signals_handler
, dbus_interface
= "com.example.TestService", signal_name
= "HelloSignal")
70 bus
.add_signal_receiver(catchall_testservice_interface_handler
, dbus_interface
= "com.example.TestService", message_keyword
='dbus_message')
72 # Tell the remote object to emit the signal after a short delay
73 gobject
.timeout_add(2000, emit_signal
)
75 loop
= gobject
.MainLoop()