4 python example-signal-emitter.py &
5 python example-signal-recipient.py
6 python example-signal-recipient.py --exit-service
9 # Copyright (C) 2004-2006 Red Hat Inc. <http://www.redhat.com/>
10 # Copyright (C) 2005-2007 Collabora Ltd. <http://www.collabora.co.uk/>
12 # Permission is hereby granted, free of charge, to any person
13 # obtaining a copy of this software and associated documentation
14 # files (the "Software"), to deal in the Software without
15 # restriction, including without limitation the rights to use, copy,
16 # modify, merge, publish, distribute, sublicense, and/or sell copies
17 # of the Software, and to permit persons to whom the Software is
18 # furnished to do so, subject to the following conditions:
20 # The above copyright notice and this permission notice shall be
21 # included in all copies or substantial portions of the Software.
23 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 # DEALINGS IN THE SOFTWARE.
38 import dbus
.mainloop
.glib
40 def handle_reply(msg
):
47 #call the emitHelloSignal method
48 object.emitHelloSignal(dbus_interface
="com.example.TestService")
49 #reply_handler = handle_reply, error_handler = handle_error)
50 # exit after waiting a short time for the signal
51 gobject
.timeout_add(2000, loop
.quit
)
53 if sys
.argv
[1:] == ['--exit-service']:
54 object.Exit(dbus_interface
='com.example.TestService')
58 def hello_signal_handler(hello_string
):
59 print ("Received signal (by connecting using remote object) and it says: "
62 def catchall_signal_handler(*args
, **kwargs
):
63 print ("Caught signal (in catchall handler) "
64 + kwargs
['dbus_interface'] + "." + kwargs
['member'])
68 def catchall_hello_signals_handler(hello_string
):
69 print "Received a hello signal and it says " + hello_string
71 def catchall_testservice_interface_handler(hello_string
, dbus_message
):
72 print "com.example.TestService interface says " + hello_string
+ " when it sent signal " + dbus_message
.get_member()
75 if __name__
== '__main__':
76 dbus
.mainloop
.glib
.DBusGMainLoop(set_as_default
=True)
78 bus
= dbus
.SessionBus()
80 object = bus
.get_object("com.example.TestService","/com/example/TestService/object")
82 object.connect_to_signal("HelloSignal", hello_signal_handler
, dbus_interface
="com.example.TestService", arg0
="Hello")
83 except dbus
.DBusException
:
89 bus
.add_signal_receiver(catchall_signal_handler
, interface_keyword
='dbus_interface', member_keyword
='member')
91 bus
.add_signal_receiver(catchall_hello_signals_handler
, dbus_interface
= "com.example.TestService", signal_name
= "HelloSignal")
93 bus
.add_signal_receiver(catchall_testservice_interface_handler
, dbus_interface
= "com.example.TestService", message_keyword
='dbus_message')
95 # Tell the remote object to emit the signal after a short delay
96 gobject
.timeout_add(2000, emit_signal
)
98 loop
= gobject
.MainLoop()