From 6a5a688bd26704a1de1288c5c635fa418d39e1ca Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Wed, 15 Sep 2010 13:15:26 +0200 Subject: [PATCH] fso-auth.py: make the auth event based This is more robust against slow initialization of some modems. --- fso-auth.py | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) 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() -- 2.1.4