Browse Source

dbus: Fix example get-list-of-interfaces operation

Jouni Malinen 15 years ago
parent
commit
e7f7d231a4
1 changed files with 12 additions and 7 deletions
  1. 12 7
      wpa_supplicant/examples/wpas-dbus-new.py

+ 12 - 7
wpa_supplicant/examples/wpas-dbus-new.py

@@ -25,9 +25,13 @@ def byte_array_to_string(s):
 	return r
 	return r
 
 
 def list_interfaces(wpas_obj):
 def list_interfaces(wpas_obj):
-	ifaces = wpas_obj.Interfaces
-	for i in ifaces:
-		print "%s" (i)
+	ifaces = wpas_obj.Get(WPAS_DBUS_INTERFACE, 'Interfaces',
+			      dbus_interface=dbus.PROPERTIES_IFACE)
+	for path in ifaces:
+		if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
+		ifname = if_obj.Get(WPAS_DBUS_INTERFACES_INTERFACE, 'Ifname',
+			      dbus_interface=dbus.PROPERTIES_IFACE)
+		print ifname
 
 
 def stateChanged(newState, oldState):
 def stateChanged(newState, oldState):
 	print "StateChanged(%s -> %s)" % (oldState, newState)
 	print "StateChanged(%s -> %s)" % (oldState, newState)
@@ -91,6 +95,11 @@ def main():
 	global bus
 	global bus
 	bus = dbus.SystemBus()
 	bus = dbus.SystemBus()
 	wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
 	wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
+
+	if len(sys.argv) != 2:
+		list_interfaces(wpas_obj)
+		os._exit(1)
+
 	wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)
 	wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)
 	bus.add_signal_receiver(scanDone,
 	bus.add_signal_receiver(scanDone,
 				dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
 				dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
@@ -105,10 +114,6 @@ def main():
 				dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
 				dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
 				signal_name="StateChanged")
 				signal_name="StateChanged")
 
 
-	if len(sys.argv) != 2:
-		list_interfaces(wpas_obj)
-		os._exit(1)
-
 	ifname = sys.argv[1]
 	ifname = sys.argv[1]
 
 
 	# See if wpa_supplicant already knows about this interface
 	# See if wpa_supplicant already knows about this interface