test: test-sms - input and signals outputs together
authorKonrad Slowinski <konrad.slowinski@tieto.com>
Fri, 4 Feb 2011 08:38:42 +0000 (10:38 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Fri, 4 Feb 2011 13:00:17 +0000 (14:00 +0100)
test/test-sms

index 7bc6fbc..7d02066 100755 (executable)
@@ -3,11 +3,13 @@
 
 import gobject
 import sys
+import os
 
 import dbus
 import dbus.mainloop.glib
 
 SCA = ""
+lock = "off"
 
 def clear_screen(numlines=100):
        import os
@@ -71,6 +73,7 @@ def message_send(sms, number, value):
 
 def property_changed(property, value):
        print "[1]:Message Manager property %s changed to %s" % (property, value)
+       print "[1]:press ENTER"
 
 def immediate_message(property, value):
        print "[2]:Message Manager immediate message"
@@ -79,6 +82,8 @@ def immediate_message(property, value):
                val = str(value[key])
                print "[2]:%s = %s" % (key, val)
 
+       print "[2]:press ENTER"
+
 def incoming_message(property, value):
        print "[3]:Message Manager incoming message"
        print "[3]:Text::%s" % (property)
@@ -86,6 +91,8 @@ def incoming_message(property, value):
                val = str(value[key])
                print "[3]:%s = %s" % (key, val)
 
+       print "[3]:press ENTER"
+
 def message_added(property, value):
        print "[4]:Message Manager[Added]"
        print "[4]:%s"% (property)
@@ -94,9 +101,12 @@ def message_added(property, value):
                val = str(value[key])
                print "[4]:%s = %s" % (key, val)
 
+       print "[4]:press ENTER"
+
 def message_removed(property):
        print "[5]:Message Manager [removed]"
        print "[5]: %s" % (property)
+       print "[5]:press ENTER"
 
 def print_sms_properties(sms):
        global SCA
@@ -111,40 +121,12 @@ def print_sms_properties(sms):
                else:
                        print "%s Message Manager rule disabled" % (p)
 
+def stdin_handler(fd, condition, sms, value, number):
+       global lock
+       in_key = os.read(fd.fileno(), 160).rstrip()
 
-
-if __name__ == "__main__":
-       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()
-       path = modems[0][0]
-       sms = dbus.Interface(bus.get_object('org.ofono', path),
-                               'org.ofono.MessageManager')
-
-       sms.connect_to_signal("PropertyChanged", property_changed)
-       sms.connect_to_signal("ImmediateMessage", immediate_message)
-       sms.connect_to_signal("IncomingMessage", incoming_message)
-       sms.connect_to_signal("MessageAdded", message_added)
-       sms.connect_to_signal("MessageRemoved", message_removed)
-
-       if (len(sys.argv) < 3):
-               print "Usage: %s <phone_number> <test_message>" % (sys.argv[0])
-               sys.exit(1)
-
-       number = sys.argv[1]
-       value  = sys.argv[2]
-
-       clear_screen()
-       print_sms_properties(sms)
-       print_menu()
-       in_key = 'ok'
-
-       while in_key != 'x':
-               in_key = raw_input('Select any option: ')
-
+       if lock == "off":
+               lock = "on"
                if in_key == '0':
                        print_send_sms_menu()
                        sms_type = raw_input('Select SMS type: ')
@@ -152,62 +134,98 @@ if __name__ == "__main__":
                        if sms_type == '1':
                                message_send(sms, number, value)
 
-                       if sms_type == '2':
+                       elif sms_type == '2':
                                val = "abcde12345"
                                for i in range(30):
                                        value = value + val
 
                                message_send(sms, number, value)
 
-                       if sms_type == '3':
+                       elif sms_type == '3':
                                value = "ÖÄÅöäåµʒ×cvcvbŋ"
                                message_send(sms, number, value)
 
-               if in_key == '1':
+               elif in_key == '1':
                        message_delivery_report(sms, 1)
                        send_msg = raw_input('Send test message[y/n]?: ')
                        if send_msg == 'y':
                                message_send(sms, number, ("(1)"+value+": UseDeliveryReports[TRUE]"))
 
-               if in_key == '2':
+               elif in_key == '2':
                        message_delivery_report(sms, 0)
                        send_msg = raw_input('Send test message[y/n]?: ')
                        if send_msg == 'y':
                                message_send(sms, number, ("(2) "+value+": UseDeliveryReports[FALSE]"))
 
-               if in_key == '3':
+               elif in_key == '3':
                        message_service_center_address(sms, SCA)
                        send_msg = raw_input('Send test message[y/n]?: ')
                        if send_msg == 'y':
                                message_send(sms, number, ("(3) "+value+": ServiceCenterAddress"))
 
-               if in_key == '4':
+               elif in_key == '4':
                        message_bearer(sms, "ps-only")
                        send_msg = raw_input('Send test message[y/n]?: ')
                        if send_msg == 'y':
                                message_send(sms, number, ("(4) "+value+": Bearer[ps-only]"))
 
-               if in_key == '5':
+               elif in_key == '5':
                        message_bearer(sms, "cs-only")
                        send_msg = raw_input('Send test message[y/n]?: ')
                        if send_msg == 'y':
                                message_send(sms, number, ("(5) "+value+": Bearer[cs-only]"))
 
-               if in_key == '6':
+               elif in_key == '6':
                        message_bearer(sms, "ps-preferred")
                        send_msg = raw_input('Send test message[y/n]?: ')
                        if send_msg == 'y':
                                message_send(sms, number, ("(6) "+value+": Bearer[ps-preferred]"))
 
-               if in_key == '7':
+               elif in_key == '7':
                        message_bearer(sms, "cs-preferred")
                        send_msg = raw_input('Send test message[y/n]?: ')
                        if send_msg == 'y':
                                message_send(sms,number, ("(7) "+value+": Bearer[cs-preferred]"))
 
+               elif in_key == 'x':
+                       sys.exit(1)
+
                clear_screen()
                print_sms_properties(sms)
                print_menu()
+               lock = "off"
+
+       return True
+
+if __name__ == "__main__":
+
+       if (len(sys.argv) < 3):
+               print "Usage: %s <phone_number> <test_message>" % (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()
+       path = modems[0][0]
+       sms = dbus.Interface(bus.get_object('org.ofono', path),
+                               'org.ofono.MessageManager')
+
+       sms.connect_to_signal("PropertyChanged", property_changed)
+       sms.connect_to_signal("ImmediateMessage", immediate_message)
+       sms.connect_to_signal("IncomingMessage", incoming_message)
+       sms.connect_to_signal("MessageAdded", message_added)
+       sms.connect_to_signal("MessageRemoved", message_removed)
+
+       number = sys.argv[1]
+       value  = sys.argv[2]
+
+       clear_screen()
+       print_sms_properties(sms)
+       print_menu()
 
+       gobject.io_add_watch(sys.stdin, gobject.IO_IN, stdin_handler, sms, value, number)
        mainloop = gobject.MainLoop()
        mainloop.run()