aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2015-12-01 21:39:08 +0100
committerHarald Welte <laforge@gnumonks.org>2015-12-01 21:39:08 +0100
commit7a76ec60a8f02be338eb3f36f8729b9c953b75e2 (patch)
tree608f2e6192c6ffab75723ffde3061d2b1045868a
parentb3b64c0ce248cf86c6f7d8a5b903b7f6e93cc476 (diff)
add interactive shell to stat more calls from mncc_test2.py
-rwxr-xr-xmncc_test2.py33
1 files changed, 25 insertions, 8 deletions
diff --git a/mncc_test2.py b/mncc_test2.py
index 4dff6cd..ba5a460 100755
--- a/mncc_test2.py
+++ b/mncc_test2.py
@@ -2,11 +2,13 @@
from gsm_call_fsm import GsmCallFsm, GsmCallConnector
from mncc_sock import MnccSocket
+from thread import start_new_thread
import pykka
import logging
-import signal
-import sys
+import signal, sys
+import readline, code
+# MnccActor provides an interface for GsmCallFsm to send MNCC messages
class MnccActor(pykka.ThreadingActor):
def __init__(self, mncc_sock):
super(MnccActor, self).__init__()
@@ -17,7 +19,15 @@ class MnccActor(pykka.ThreadingActor):
if message['type'] == 'send':
mncc_sock.send(message['msg'])
+# MNCC receive thread, broadcasting received MNCC packets to GsmCallFsm
+def mncc_rx_thread(mncc_sock):
+ while 1:
+ msg = mncc_sock.recv()
+ print "Received %s from MNCC, broadcasting to Call FSMs" % msg
+ # we simply broadcast to all calls
+ pykka.ActorRegistry.broadcast({'type': 'mncc', 'msg': msg}, GsmCallFsm)
+# capture SIGINT (Ctrl+C) and stop all actors
def sigint_handler(signum, frame):
pykka.ActorRegistry.stop_all()
sys.exit(0)
@@ -26,15 +36,22 @@ logging.basicConfig(level=logging.DEBUG)
signal.signal(signal.SIGINT, sigint_handler)
+# start the MnccSocket and associated pykka actor + rx thread
mncc_sock = MnccSocket()
mncc_act = MnccActor.start(mncc_sock)
+start_new_thread(mncc_rx_thread, (mncc_sock,))
+# start a first bogus call
call_conn = GsmCallConnector.start(mncc_act).proxy()
call_conn.start_call_ab("1234", "6789")
-while 1:
- msg = mncc_sock.recv()
- print "Received %s from MNCC, broadcasting to Call FSMs" % msg
- # FIXME: we simply broadcast to all calls
- pykka.ActorRegistry.broadcast({'type': 'mncc', 'msg': msg}, GsmCallFsm)
- #pykka.ActorRegistry.broadcast({'type': 'mncc', 'msg': msg})
+# start a shell to enable the user to add more calls as needed
+vars = globals().copy()
+vars.update(locals())
+shell = code.InteractiveConsole(vars)
+try:
+ shell.interact()
+except SystemExit:
+ pass
+# clan up after user leaves interactive shell
+sigint_handler(signal.SIGINT, None)