Revert "Make sure extensions are built before docs; get rid of strange inter-director...
[dbus-python-phuang.git] / examples / example-client.py
blob796f2620db8f1ba2d7ac67b74966f5b377b5b3b6
1 #!/usr/bin/env python
3 usage = """Usage:
4 python example-service.py &
5 python example-client.py
6 python example-client.py --exit-service
7 """
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.
32 import sys
33 from traceback import print_exc
35 import dbus
37 def main():
38 bus = dbus.SessionBus()
40 try:
41 remote_object = bus.get_object("com.example.SampleService",
42 "/SomeObject")
44 # you can either specify the dbus_interface in each call...
45 hello_reply_list = remote_object.HelloWorld("Hello from example-client.py!",
46 dbus_interface = "com.example.SampleInterface")
47 except dbus.DBusException:
48 print_exc()
49 print usage
50 sys.exit(1)
52 print (hello_reply_list)
54 # ... or create an Interface wrapper for the remote object
55 iface = dbus.Interface(remote_object, "com.example.SampleInterface")
57 hello_reply_tuple = iface.GetTuple()
59 print hello_reply_tuple
61 hello_reply_dict = iface.GetDict()
63 print hello_reply_dict
65 # D-Bus exceptions are mapped to Python exceptions
66 try:
67 iface.RaiseException()
68 except dbus.DBusException, e:
69 print str(e)
71 # introspection is automatically supported
72 print remote_object.Introspect(dbus_interface="org.freedesktop.DBus.Introspectable")
74 if sys.argv[1:] == ['--exit-service']:
75 iface.Exit()
77 if __name__ == '__main__':
78 main()