4 python example-service.py &
5 python example-async-client.py
6 python example-client.py --exit-service
15 import dbus
.mainloop
.glib
17 # Callbacks for asynchronous calls
19 def handle_hello_reply(r
):
25 if hello_replied
and raise_replied
:
28 def handle_hello_error(e
):
34 print "HelloWorld raised an exception! That's not meant to happen..."
37 if hello_replied
and raise_replied
:
40 def handle_hello_error(e
):
46 print "HelloWorld raised an exception! That's not meant to happen..."
49 if hello_replied
and raise_replied
:
52 def handle_raise_reply():
58 print "RaiseException returned normally! That's not meant to happen..."
60 if hello_replied
and raise_replied
:
63 def handle_raise_error(e
):
67 print "RaiseException raised an exception as expected:"
70 if hello_replied
and raise_replied
:
74 # To make an async call, use the reply_handler and error_handler kwargs
75 remote_object
.HelloWorld("Hello from example-async-client.py!",
76 dbus_interface
='com.example.SampleInterface',
77 reply_handler
=handle_hello_reply
,
78 error_handler
=handle_hello_error
)
80 # Interface objects also support async calls
81 iface
= dbus
.Interface(remote_object
, 'com.example.SampleInterface')
83 iface
.RaiseException(reply_handler
=handle_raise_reply
,
84 error_handler
=handle_raise_error
)
88 if __name__
== '__main__':
89 dbus
.mainloop
.glib
.DBusGMainLoop(set_as_default
=True)
91 bus
= dbus
.SessionBus()
93 remote_object
= bus
.get_object("com.example.SampleService","/SomeObject")
94 except dbus
.DBusException
:
99 # Make the method call after a short delay
100 gobject
.timeout_add(1000, make_calls
)
103 hello_replied
= False
104 raise_replied
= False
106 loop
= gobject
.MainLoop()
109 raise SystemExit("Example async client failed!")