Fix network selection and add network disconnect scripts
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 30 Jul 2008 20:15:54 +0000 (22:15 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 30 Jul 2008 20:15:54 +0000 (22:15 +0200)
test/disable-network [new file with mode: 0755]
test/select-network

diff --git a/test/disable-network b/test/disable-network
new file mode 100755 (executable)
index 0000000..645fa5d
--- /dev/null
@@ -0,0 +1,22 @@
+#!/usr/bin/python
+
+import dbus
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("org.moblin.connman", "/"),
+                                       "org.moblin.connman.Manager")
+
+elements = manager.ListElements()
+
+for path in elements:
+       element = dbus.Interface(bus.get_object("org.moblin.connman", path),
+                                               "org.moblin.connman.Element")
+
+       properties = element.GetProperties()
+       if (properties["Type"] != "network"):
+               continue
+
+       if (properties["Connected"] == dbus.Boolean(1)):
+               print "Disconnecting %s" % (path)
+               element.Disconnect()
index 7de8d65..2d5b2b1 100755 (executable)
@@ -1,32 +1,30 @@
 #!/usr/bin/python
 
+import sys
 import dbus
 
-bus = dbus.SystemBus()
-
-manager = dbus.Interface(bus.get_object('org.moblin.connman', "/"),
-                                       'org.moblin.connman.Manager')
+if (len(sys.argv) < 2):
+       print "Usage: %s <network>" % (sys.argv[0])
+       sys.exit(1)
 
-interfaces = manager.ListInterfaces()
+bus = dbus.SystemBus()
 
-for path in interfaces:
-       print "[ %s ]" % (path)
+manager = dbus.Interface(bus.get_object("org.moblin.connman", "/"),
+                                       "org.moblin.connman.Manager")
 
-       interface = dbus.Interface(bus.get_object('org.moblin.connman', path),
-                                       'org.moblin.connman.Interface')
+elements = manager.ListElements()
 
-       properties = interface.GetProperties()
+for path in elements:
+       element = dbus.Interface(bus.get_object("org.moblin.connman", path),
+                                               "org.moblin.connman.Element")
 
-       if (properties["Type"] == "80211"):
-               networks = interface.ListNetworks()
-               for i in networks:
-                       network = dbus.Interface(bus.get_object('org.moblin.connman', i),
-                                               'org.moblin.connman.Network')
+       properties = element.GetProperties()
+       if (properties["Type"] != "network"):
+               continue
 
-                       if (network.GetIdentifier() == "ConnMan Testing"):
-                               print "   Selecting network %s" % (i)
-                               interface.SelectNetwork(i)
-       else:
-               print "   No networks"
+       if (properties["Connected"] == dbus.Boolean(1)):
+               continue
 
-       print
+       if (properties["Identifier"] == sys.argv[1]):
+               print "Connecting %s" % (path)
+               element.Connect()