All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Nunes <philippe.nunes@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH 2/2] test-ussd: new script more generic
Date: Mon, 02 Jul 2012 17:45:24 +0200	[thread overview]
Message-ID: <1341243924-9257-2-git-send-email-philippe.nunes@linux.intel.com> (raw)
In-Reply-To: <1341243924-9257-1-git-send-email-philippe.nunes@linux.intel.com>

[-- Attachment #1: Type: text/plain, Size: 2775 bytes --]

This script can be used to handle network initiated USSD without
preliminary USSD request.
---
 test/test-ussd |   97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100755 test/test-ussd

diff --git a/test/test-ussd b/test/test-ussd
new file mode 100755
index 0000000..f1d8215
--- /dev/null
+++ b/test/test-ussd
@@ -0,0 +1,97 @@
+#!/usr/bin/python
+
+import sys
+import gobject
+import os
+
+import dbus
+import dbus.mainloop.glib
+
+state = None
+
+def clear_screen(numlines=100):
+	import os
+	if os.name == "posix":
+		os.system('clear')
+
+	elif os.name in ("nt", "dos", "ce"):
+		os.system('CLS')
+
+	else:
+		print '\n' * numlines
+
+def print_menu():
+	if state == "user-response":
+		print "\n\nEnter response (c for cancel - x for exit):"
+	elif state == "idle":
+		print "\n\nEnter USSD request (x for exit):"
+
+def ussd_notification_received(content):
+	clear_screen()
+	print("Network sent a Notification: " + content)
+	print_menu()
+
+def ussd_request_received(content):
+	clear_screen()
+	print("Network sent a Request: " + content)
+
+def ussd_property_changed(name, value):
+	global state
+	if name != "State":
+		return
+	print("USSD session state is " + value)
+	state = str(value)
+
+	print_menu()
+
+def stdin_handler(fd, condition):
+	s = os.read(fd.fileno(), 182).rstrip()
+
+	if s == 'c':
+		if state == "user-response" or state == 'active':
+			ss.Cancel()
+	elif s == 'x':
+		sys.exit()
+	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
+
+if __name__ == "__main__":
+	if (len(sys.argv) >2 or (len(sys.argv) == 2 and
+			sys.argv[1] in ("-h", "--help"))):
+		print "Usage: %s [-h] [modem]" % (sys.argv[0])
+		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')
+
+	modems = manager.GetModems()
+
+	if (len(sys.argv) == 2):
+		modem = sys.argv[1]
+	else:
+		modem = modems[0][0]
+
+	ss = dbus.Interface(bus.get_object('org.ofono', modem),
+					'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)
+
+	gobject.io_add_watch(sys.stdin, gobject.IO_IN, stdin_handler)
+
+	mainloop = gobject.MainLoop()
+	mainloop.run()
-- 
1.7.9.5


  reply	other threads:[~2012-07-02 15:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-02 15:45 [PATCH 1/2] test-ussd becomes send-ussd Philippe Nunes
2012-07-02 15:45 ` Philippe Nunes [this message]
2012-07-09 16:26 ` Denis Kenzior
2012-07-09 16:39   ` Marcel Holtmann
2012-07-09 16:52     ` Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1341243924-9257-2-git-send-email-philippe.nunes@linux.intel.com \
    --to=philippe.nunes@linux.intel.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.