test: simple-agent support for ReportError method call
[platform/upstream/connman.git] / test / simple-agent
1 #!/usr/bin/python
2
3 import gobject
4
5 import dbus
6 import dbus.service
7 import dbus.mainloop.glib
8 import sys
9
10 class Canceled(dbus.DBusException):
11         _dbus_error_name = "net.connman.Error.Canceled"
12
13 class Agent(dbus.service.Object):
14         passphrase = ""
15
16         @dbus.service.method("net.connman.Agent",
17                                         in_signature='', out_signature='')
18         def Release(self):
19                 print("Release")
20                 mainloop.quit()
21
22         @dbus.service.method("net.connman.Agent",
23                                         in_signature='oa{sv}',
24                                         out_signature='a{sv}')
25         def RequestInput(self, path, fields):
26                 print "RequestInput (%s,%s)" % (path, fields)
27
28                 response = {}
29                 response["Passphrase"] = self.passphrase
30
31                 print "returning (%s)" % (response)
32
33                 return response
34
35         @dbus.service.method("net.connman.Agent",
36                                         in_signature='os',
37                                         out_signature='')
38         def ReportError(self, path, error):
39                 print "ReportError %s, %s" % (path, error)
40                 retry = raw_input("Retry service (yes/no): ")
41                 if (retry == "yes"):
42                         class Retry(dbus.DBusException):
43                                 _dbus_error_name = "net.connman.Agent.Error.Retry"
44
45                         raise Retry("retry service")
46                 else:
47                         return
48
49
50         @dbus.service.method("net.connman.Agent",
51                                         in_signature='', out_signature='')
52         def Cancel(self):
53                 print "Cancel"
54
55
56
57 if __name__ == '__main__':
58         if len(sys.argv) < 2:
59                 print "Usage: %s <passphrase>" % (sys.argv[0])
60                 sys.exit(1)
61
62         dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
63
64         bus = dbus.SystemBus()
65         manager = dbus.Interface(bus.get_object('net.connman', "/"),
66                                         'net.connman.Manager')
67
68         path = "/test/agent"
69         object = Agent(bus, path)
70         object.passphrase = sys.argv[1]
71
72         manager.RegisterAgent(path)
73
74         mainloop = gobject.MainLoop()
75         mainloop.run()
76
77         #manager.UnregisterAgent(path)