X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=test%2Ftest-session;h=9784122ff690ed94a51f704427d8e9e5fbe0d7b3;hb=5d20c30a8e1f21d082f0f57b9367fc28dc2300d6;hp=1a425e3e0b2c2a9ede248e44585f48dadd57a1bb;hpb=262dcd410358c47099ff7015512e34626e0007d3;p=platform%2Fupstream%2Fconnman.git diff --git a/test/test-session b/test/test-session index 1a425e3..9784122 100755 --- a/test/test-session +++ b/test/test-session @@ -2,6 +2,7 @@ import sys import gobject +import string import dbus import dbus.service @@ -71,6 +72,7 @@ class SessionApplication(dbus.service.Object): self.session_path = None self.mainloop = mainloop self.session = None + self.settings = { } try: bus = dbus.SystemBus() @@ -107,6 +109,20 @@ class SessionApplication(dbus.service.Object): self.notify.remove_from_connection() self.notify = None + def type_convert(self, key, value): + if key in [ "AllowedBearers", "RoamingPolicy" ]: + return value + elif key in [ "Priority", "AvoidHandover", + "StayConnected", "EmergencyCall" ]: + flag = str(value[0]).strip().lower() + val = flag not in ['false', 'f', 'n', '0'] + return dbus.Boolean(val) + elif key in [ "PeriodicConnect", "IdleTimeout" ]: + val = value[0] + return dbus.UInt32(val) + + return value + @dbus.service.method("com.example.TestSession", in_signature='', out_signature='') def CreateSession(self): @@ -122,9 +138,7 @@ class SessionApplication(dbus.service.Object): self.notify = Notification(bus, self, self.notify_path) self.notify.add_to_connection(bus, self.notify_path) - #settings = { "AllowedBearers" : [ "ethernet", "*" ] } - settings = { "AllowedBearers" : [ "ethernet" ] } - self.session_path = self.manager.CreateSession(settings, self.notify_path) + self.session_path = self.manager.CreateSession(self.settings, self.notify_path) print "notify path %s" % (self.notify_path) print "session path %s" % (self.session_path) @@ -132,7 +146,10 @@ class SessionApplication(dbus.service.Object): self.session = dbus.Interface(bus.get_object("net.connman", self.session_path), "net.connman.Session") - except dbus.DBusException: + except dbus.DBusException, e: + if e.get_dbus_name() in ['net.connman.Error.Failed']: + print e.get_dbus_message() + return traceback.print_exc() exit(1) @@ -158,8 +175,7 @@ class SessionApplication(dbus.service.Object): try: self.session.Connect() except dbus.DBusException, e: - if e.get_dbus_name() in ['net.connman.Error.InProgress', - 'net.connman.Error.AlreadyConnected']: + if e.get_dbus_name() in ['net.connman.Error.Failed']: print e.get_dbus_message() return traceback.print_exc() @@ -172,13 +188,33 @@ class SessionApplication(dbus.service.Object): try: self.session.Disconnect() except dbus.DBusException, e: - if e.get_dbus_name() in ['net.connman.Error.AlreadyDisabled', - 'net.connman.Error.NotConnected']: + if e.get_dbus_name() in ['net.connman.Error.Failed']: print e.get_dbus_message() return traceback.print_exc() exit(1) + @dbus.service.method("com.example.TestSession", + in_signature='sv', out_signature='') + def Change(self, key, value): + print "Update session settings" + try: + val = self.type_convert(key, value) + self.session.Change(key, val) + except dbus.DBusException, e: + if e.get_dbus_name() in ['net.connman.Error.Failed']: + print e.get_dbus_message() + return + traceback.print_exc() + exit(1) + + @dbus.service.method("com.example.TestSession", + in_signature='sv', out_signature='') + def Configure(self, key, value): + print "Configure session settings" + val = self.type_convert(key, value) + self.settings[key] = val + def main(): if len(sys.argv) < 2: print "Usage: %s " % (sys.argv[0]) @@ -189,6 +225,8 @@ def main(): print " destroy " print " connect " print " disconnect " + print " change " + print " configure " print "" print " run " sys.exit(1) @@ -216,8 +254,10 @@ def main(): app_path = sys.argv[2] bus = dbus.SessionBus() + app_name = "com.example.SessionApplication.%s" % (string.strip(app_path, "/")) + if sys.argv[1] == "run": - name = dbus.service.BusName("com.example.SessionApplication", bus) + name = dbus.service.BusName(app_name, bus) mainloop = gobject.MainLoop() app = SessionApplication(bus, app_path, mainloop) @@ -225,7 +265,7 @@ def main(): mainloop.run() return - app = dbus.Interface(bus.get_object("com.example.SessionApplication", app_path), + app = dbus.Interface(bus.get_object(app_name, app_path), "com.example.TestSession") if sys.argv[1] == "create": @@ -240,5 +280,23 @@ def main(): elif sys.argv[1] == "disconnect": app.Disconnect() + elif sys.argv[1] == "change": + if len(sys.argv) < 4: + print "Arguments missing" + sys.exit(1) + + app.Change(sys.argv[3], sys.argv[4:]) + + elif sys.argv[1] == "configure": + if len(sys.argv) < 4: + print "Arguments missing" + sys.exit(1) + + app.Configure(sys.argv[3], sys.argv[4:]) + + else: + print "Unknown command '%s'" % sys.argv[1] + sys.exit(1) + if __name__ == '__main__': main()