fso-auth.py: make the auth event based
authorAntonio Ospite <ospite@studenti.unina.it>
Wed, 15 Sep 2010 11:15:26 +0000 (13:15 +0200)
committerAntonio Ospite <ospite@studenti.unina.it>
Wed, 15 Sep 2010 11:15:26 +0000 (13:15 +0200)
This is more robust against slow initialization of some modems.

fso-auth.py

index 0fc26f9..3b755e7 100755 (executable)
@@ -2,22 +2,46 @@
 
 import sys
 import dbus
 
 import sys
 import dbus
+import gobject
+
+from dbus.mainloop.glib import DBusGMainLoop
+DBusGMainLoop(set_as_default=True)
+
+pin = ''
+gsm_device_iface = None
+loop = gobject.MainLoop()
+
+def onDeviceStatus(status):
+    print "DeviceStatus:", status
+    if status == "alive-sim-locked":
+        gsm_device_iface.SetFunctionality("full", True, pin)
+    elif status == "alive-sim-ready":
+        loop.quit()
+        
+def fso_auth():
+    global gsm_device_iface
+    global gsm_sim_iface
 
 
-def fso_auth(pin):
     bus = dbus.SystemBus()
 
     usage_obj = bus.get_object("org.freesmartphone.ousaged", "/org/freesmartphone/Usage")
     usage_iface = dbus.Interface(usage_obj, "org.freesmartphone.Usage")
     bus = dbus.SystemBus()
 
     usage_obj = bus.get_object("org.freesmartphone.ousaged", "/org/freesmartphone/Usage")
     usage_iface = dbus.Interface(usage_obj, "org.freesmartphone.Usage")
-    usage_iface.RequestResource("GSM")
 
     gsm_device_obj = bus.get_object("org.freesmartphone.ogsmd", "/org/freesmartphone/GSM/Device")
 
     gsm_device_obj = bus.get_object("org.freesmartphone.ogsmd", "/org/freesmartphone/GSM/Device")
-    gsm_sim_iface = dbus.Interface(gsm_device_obj, "org.freesmartphone.GSM.SIM")
+    gsm_device_iface = dbus.Interface(gsm_device_obj, "org.freesmartphone.GSM.Device")
+
+    gsm_device_iface.connect_to_signal('DeviceStatus', onDeviceStatus)
+
+    usage_iface.RequestResource("GSM")
 
 
-    if gsm_sim_iface.GetAuthStatus()  == 'SIM PIN':
-        gsm_sim_iface.SendAuthCode(pin)
-        if gsm_sim_iface.GetAuthStatus() == 'READY':
-            print "OK"
+    print "starting the main loop"
+    try:
+        loop.run()
+    except KeyboardInterrupt:
+        print "Interrupted"
+        loop.quit()
 
 
+    gsm_device_iface.SetFunctionality("minimal", True, "")
     usage_iface.ReleaseResource("GSM")
 
 if __name__ == "__main__":
     usage_iface.ReleaseResource("GSM")
 
 if __name__ == "__main__":
@@ -27,4 +51,4 @@ if __name__ == "__main__":
         sys.exit(1)
 
     pin = sys.argv[1]
         sys.exit(1)
 
     pin = sys.argv[1]
-    fso_auth(pin)
+    fso_auth()