4 python example-service.py &
5 python example-async-client.py
6 python example-client.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 # Callbacks for asynchronous calls
42 def handle_hello_reply(r
):
48 if hello_replied
and raise_replied
:
51 def handle_hello_error(e
):
57 print "HelloWorld raised an exception! That's not meant to happen..."
60 if hello_replied
and raise_replied
:
63 def handle_hello_error(e
):
69 print "HelloWorld raised an exception! That's not meant to happen..."
72 if hello_replied
and raise_replied
:
75 def handle_raise_reply():
81 print "RaiseException returned normally! That's not meant to happen..."
83 if hello_replied
and raise_replied
:
86 def handle_raise_error(e
):
90 print "RaiseException raised an exception as expected:"
93 if hello_replied
and raise_replied
:
97 # To make an async call, use the reply_handler and error_handler kwargs
98 remote_object
.HelloWorld("Hello from example-async-client.py!",
99 dbus_interface
='com.example.SampleInterface',
100 reply_handler
=handle_hello_reply
,
101 error_handler
=handle_hello_error
)
103 # Interface objects also support async calls
104 iface
= dbus
.Interface(remote_object
, 'com.example.SampleInterface')
106 iface
.RaiseException(reply_handler
=handle_raise_reply
,
107 error_handler
=handle_raise_error
)
111 if __name__
== '__main__':
112 dbus
.mainloop
.glib
.DBusGMainLoop(set_as_default
=True)
114 bus
= dbus
.SessionBus()
116 remote_object
= bus
.get_object("com.example.SampleService","/SomeObject")
117 except dbus
.DBusException
:
118 traceback
.print_exc()
122 # Make the method call after a short delay
123 gobject
.timeout_add(1000, make_calls
)
126 hello_replied
= False
127 raise_replied
= False
129 loop
= gobject
.MainLoop()
132 raise SystemExit("Example async client failed!")