ofono/test/test-ussd

68 lines
1.6 KiB
Plaintext
Raw Normal View History

2009-10-16 22:44:11 +00:00
#!/usr/bin/python
import sys
import gobject
2010-09-16 17:32:47 +00:00
import os
2009-10-16 22:44:11 +00:00
import dbus
import dbus.mainloop.glib
2010-09-16 17:32:47 +00:00
state = None
def ussd_notification_received(content):
print("Network sent a Notification: " + content)
def ussd_request_received(content):
print("Network sent a Request: " + content)
ss.Cancel()
def ussd_property_changed(name, value):
2010-09-16 17:32:47 +00:00
global state
2010-03-31 04:56:45 +00:00
if name != "State":
return
print("USSD session state is " + value)
2010-09-16 17:32:47 +00:00
state = str(value)
def stdin_handler(fd, condition):
s = os.read(fd.fileno(), 160).rstrip()
if not s:
ss.Cancel()
elif state == "user-response":
print ss.Respond(s, timeout = 100)
elif state == "idle":
print ss.Initiate(s, timeout = 100)
else:
print "Invalid state", state
return True
2009-10-16 22:44:11 +00:00
if __name__ == "__main__":
if (len(sys.argv) < 2):
2010-06-03 17:12:34 +00:00
print "Usage: %s <ussd-string>" % (sys.argv[0])
2009-10-16 22:44:11 +00:00
sys.exit(1)
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object('org.ofono', '/'),
'org.ofono.Manager')
2010-09-09 19:37:37 +00:00
modems = manager.GetModems()
ss = dbus.Interface(bus.get_object('org.ofono', modems[0][0]),
2009-10-16 22:44:11 +00:00
'org.ofono.SupplementaryServices')
props = ss.GetProperties()
for p in props:
ussd_property_changed(p, props[p])
ss.connect_to_signal("NotificationReceived", ussd_notification_received)
ss.connect_to_signal("RequestReceived", ussd_request_received)
ss.connect_to_signal("PropertyChanged", ussd_property_changed)
2009-10-16 22:44:11 +00:00
print ss.Initiate(sys.argv[1], timeout=100)
2010-09-16 17:32:47 +00:00
gobject.io_add_watch(sys.stdin, gobject.IO_IN, stdin_handler)
2009-10-16 22:44:11 +00:00
mainloop = gobject.MainLoop()
mainloop.run()