| #!/usr/bin/python |
| |
| import gobject |
| |
| import dbus |
| import dbus.service |
| import dbus.mainloop.glib |
| import sys |
| |
| class Canceled(dbus.DBusException): |
| _dbus_error_name = "net.connman.Error.Canceled" |
| |
| class Agent(dbus.service.Object): |
| passphrase = "" |
| |
| @dbus.service.method("net.connman.Agent", |
| in_signature='', out_signature='') |
| def Release(self): |
| print("Release") |
| mainloop.quit() |
| |
| @dbus.service.method("net.connman.Agent", |
| in_signature='oa{sv}', |
| out_signature='a{sv}') |
| def RequestInput(self, path, fields): |
| print "RequestInput (%s,%s)" % (path, fields) |
| |
| response = {} |
| response["Passphrase"] = self.passphrase |
| |
| print "returning (%s)" % (response) |
| |
| return response |
| |
| @dbus.service.method("net.connman.Agent", |
| in_signature='os', |
| out_signature='') |
| def ReportError(self, path, error): |
| print "ReportError %s, %s" % (path, error) |
| retry = raw_input("Retry service (yes/no): ") |
| if (retry == "yes"): |
| class Retry(dbus.DBusException): |
| _dbus_error_name = "net.connman.Agent.Error.Retry" |
| |
| raise Retry("retry service") |
| else: |
| return |
| |
| |
| @dbus.service.method("net.connman.Agent", |
| in_signature='', out_signature='') |
| def Cancel(self): |
| print "Cancel" |
| |
| |
| |
| if __name__ == '__main__': |
| if len(sys.argv) < 2: |
| print "Usage: %s <passphrase>" % (sys.argv[0]) |
| sys.exit(1) |
| |
| dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| |
| bus = dbus.SystemBus() |
| manager = dbus.Interface(bus.get_object('net.connman', "/"), |
| 'net.connman.Manager') |
| |
| path = "/test/agent" |
| object = Agent(bus, path) |
| object.passphrase = sys.argv[1] |
| |
| manager.RegisterAgent(path) |
| |
| mainloop = gobject.MainLoop() |
| mainloop.run() |
| |
| #manager.UnregisterAgent(path) |