fso-auth.py: quit the loop after network registration
[fso-scripts.git] / fso-listen-for-calls.py
1 #!/usr/bin/env python
2
3 import dbus
4 import gobject
5
6 from dbus.mainloop.glib import DBusGMainLoop
7 DBusGMainLoop(set_as_default=True)
8
9 def onCallStatus(sender = "", *args, **kwargs):
10     status = str(args[0])
11     if (args[1].has_key("peer")):
12         caller = str(args[1]["peer"])
13     else:
14         caller = "unknown"
15
16     print "onCallStatus"
17     print sender
18     print status
19     print caller
20     print
21
22 def fso_listen_for_calls():
23     bus = dbus.SystemBus()
24
25     usage_obj = bus.get_object("org.freesmartphone.ousaged", "/org/freesmartphone/Usage")
26     usage_iface = dbus.Interface(usage_obj, "org.freesmartphone.Usage")
27     usage_iface.RequestResource("GSM")
28
29     gsm_device_obj = bus.get_object("org.freesmartphone.ogsmd", "/org/freesmartphone/GSM/Device")
30     gsm_device_iface = dbus.Interface(gsm_device_obj, "org.freesmartphone.GSM.Device")
31     gsm_call_iface = dbus.Interface(gsm_device_obj, "org.freesmartphone.GSM.Call")
32
33     print "Set Functionality: full"
34     gsm_device_iface.SetFunctionality("full", True, "")
35
36     gsm_call_iface.connect_to_signal('CallStatus', onCallStatus)
37
38     print "starting the main loop"
39     loop = gobject.MainLoop()
40     try:
41         loop.run()
42     except KeyboardInterrupt:
43         print "Interrupted"
44         loop.quit()
45
46     gsm_device_iface.SetFunctionality("minimal", True, "")
47     usage_iface.ReleaseResource("GSM")
48
49 if __name__ == "__main__":
50     fso_listen_for_calls()