From: Antonio Ospite Date: Wed, 15 Sep 2010 11:15:26 +0000 (+0200) Subject: fso-auth.py: make the auth event based X-Git-Url: https://git.ao2.it/fso-scripts.git/commitdiff_plain/6a5a688bd26704a1de1288c5c635fa418d39e1ca fso-auth.py: make the auth event based This is more robust against slow initialization of some modems. --- diff --git a/fso-auth.py b/fso-auth.py index 0fc26f9..3b755e7 100755 --- a/fso-auth.py +++ b/fso-auth.py @@ -2,22 +2,46 @@ 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") - usage_iface.RequestResource("GSM") 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__": @@ -27,4 +51,4 @@ if __name__ == "__main__": sys.exit(1) pin = sys.argv[1] - fso_auth(pin) + fso_auth()