aboutsummaryrefslogtreecommitdiffstats
path: root/gsm_call_fsm.py
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2015-12-01 21:14:44 +0100
committerHarald Welte <laforge@gnumonks.org>2015-12-01 21:14:44 +0100
commitb3b64c0ce248cf86c6f7d8a5b903b7f6e93cc476 (patch)
tree030fa65a6a88356767602815d31ad13c080c2347 /gsm_call_fsm.py
parent56c63fe7f28b196310655b3a036fa4e3dd2aa1db (diff)
Introduce GsmCallConnector() to connect two call legs
Diffstat (limited to 'gsm_call_fsm.py')
-rw-r--r--gsm_call_fsm.py41
1 files changed, 38 insertions, 3 deletions
diff --git a/gsm_call_fsm.py b/gsm_call_fsm.py
index d559def..066a0ad 100644
--- a/gsm_call_fsm.py
+++ b/gsm_call_fsm.py
@@ -15,7 +15,9 @@ class GsmCallFsm(pykka.ThreadingActor):
return GsmCallFsm.last_callref;
def _printstatechange(self, e):
- print 'GsmCallFsm(%s, %u): event: %s, %s -> %s' % (self.name, self.callref, e.event, e.src, e.dst)
+ print 'GsmCallFsm(%u/%s): event: %s, %s -> %s' % (self.callref, self.called, e.event, e.src, e.dst)
+ if self.ctrl_ref != None:
+ self.ctrl_ref.tell({'type':'call_state_change', 'called':self.called, 'old_state':e.src, 'new_state':e.dst})
def _onmncc_setup_req(self, e):
msg = mncc_msg(msg_type = mncc.MNCC_SETUP_REQ, callref = self.callref,
@@ -34,11 +36,11 @@ class GsmCallFsm(pykka.ThreadingActor):
if e.event != 'startup':
self.stop()
- def __init__(self, name, mncc_ref):
+ def __init__(self, mncc_ref, ctrl_ref = None):
super(GsmCallFsm, self).__init__()
- self.name = name
self.mncc_ref = mncc_ref;
self.callref = self._get_next_callref()
+ self.ctrl_ref = ctrl_ref
self.fsm = Fysom(initial = 'NULL',
events = [
# MT call setup
@@ -144,9 +146,42 @@ class GsmCallFsm(pykka.ThreadingActor):
# pykka Actor message receiver
def on_receive(self, message):
+ print 'GsmCallFsm(%u):on_receive(%s)' % (self.callref, message)
if message['type'] == 'mncc':
msg = message['msg']
if msg.callref == self.callref:
return self._handle_mncc(msg)
+ elif message['type'] == 'start_mt_call':
+ self.start_mt_call(message['calling'], message['called'])
else:
raise Exception('mncc', 'Unknown message %s' % message)
+
+
+class GsmCallConnector(pykka.ThreadingActor):
+ def __init__(self, mncc_act):
+ super(GsmCallConnector, self).__init__()
+ self.mncc_act = mncc_act
+ print 'Starting Call A actor'
+ self.call_a = GsmCallFsm.start(self.mncc_act, self.actor_ref)
+ print 'Starting Call B actor'
+ self.call_b = GsmCallFsm.start(self.mncc_act, self.actor_ref)
+
+ def start_call_ab(self, msisdn_a, msisdn_b):
+ print 'Starting calls for A and B'
+ self.msisdn_a = msisdn_a
+ self.msisdn_b = msisdn_b
+
+ # start MT call A->B
+ print 'Starting Call A->B'
+ self.call_a.tell({'type':'start_mt_call', 'calling':self.msisdn_a, 'called':self.msisdn_b})
+
+ # start MT call B->A
+ print 'Starting Call B->A'
+ self.call_b.tell({'type':'start_mt_call', 'calling':self.msisdn_b, 'called':self.msisdn_a})
+
+ def call_state_change(self, msisdn, old_state, new_state):
+ print 'CallConnector:leg_state_change(%s) %s -> %s' % (msisdn, old_state, new_state)
+
+ def on_receive(self, message):
+ if message['type'] == 'call_state_change':
+ self.call_state_change(message['called'], message['old_state'], message['new_state'])