summaryrefslogtreecommitdiffstats
path: root/Handler
diff options
context:
space:
mode:
authortriatmoko2011-07-13 16:50:31 +0200
committertriatmoko2011-07-13 16:50:31 +0200
commitcc501e23f3b45549d55dcedd623fde52537acba4 (patch)
treeb4ebe5548bb66b81c4b59a41162fdecbb9aaa2ce /Handler
parentinsert.php.insert test value to the test table. (diff)
downloadgsm-selftest-cc501e23f3b45549d55dcedd623fde52537acba4.tar.gz
gsm-selftest-cc501e23f3b45549d55dcedd623fde52537acba4.tar.xz
gsm-selftest-cc501e23f3b45549d55dcedd623fde52537acba4.zip
edit sip handler.
Diffstat (limited to 'Handler')
-rw-r--r--Handler/sipCall.py18
-rw-r--r--Handler/sipReceiver.py108
2 files changed, 52 insertions, 74 deletions
diff --git a/Handler/sipCall.py b/Handler/sipCall.py
index eb44b4a..dfbd7b3 100644
--- a/Handler/sipCall.py
+++ b/Handler/sipCall.py
@@ -33,9 +33,6 @@ class MyAccountCallback(pj.AccountCallback):
def __init__(self, account=None):
pj.AccountCallback.__init__(self, account)
- # Notification on incoming call##
-
-
# Callback to receive events from Call
class MyCallCallback(pj.CallCallback):
@@ -43,15 +40,15 @@ class MyCallCallback(pj.CallCallback):
def __init__(self, call=None):
pj.CallCallback.__init__(self, call)
- # Notification when call state has changed
+
def on_state(self):
global current_call
global success
- if self.call.info().state_text <> "DISCONNCTD":
+ if self.call.info().state <> pj.CallState.DISCONNECTED:
if self.call.info().state_text == "CONNECTING":
print "CONNECTING CALL"
- #print "isine opo:", self.call.info().state_text
+
print "CALL CONFIRMED and ESTABLISH", self.call.info().state_text
sleep(5)
current_call.hangup()
@@ -59,7 +56,7 @@ class MyCallCallback(pj.CallCallback):
server.sendData(success)
else:
sleep(1)
- #print ""
+
if self.call.info().last_reason <> "":
@@ -69,9 +66,6 @@ class MyCallCallback(pj.CallCallback):
print ""
success = "false"
server.sendData(success)
-
-
- #print self.call.info().state_text
if self.call.info().state == pj.CallState.DISCONNECTED:
current_call = None
@@ -122,8 +116,10 @@ while stop <> "true":
my_sip_uri = "sip:" + transport.info().host + ":" + str(transport.info().port)
print my_sip_uri
+
server.sendData('ready')#send message to controller
- print "here:", server.connected
+ print "Status: ", server.connected
+
while 1:
try:
data = server.receiveData() # waiting mode, until receiver start message or terminate message
diff --git a/Handler/sipReceiver.py b/Handler/sipReceiver.py
index 6404f10..ec26acc 100644
--- a/Handler/sipReceiver.py
+++ b/Handler/sipReceiver.py
@@ -16,88 +16,71 @@ password = "2mpselftest"
LOG_LEVEL=2
current_call = None
-success = ""
+success = None
global accept
accept = None
# Logging callback
def log_cb(level, str, len):
- print str, "I am here"
+ print str, "SIP Handler Receiver Log"
+
-# Callback to receive events from account
class MyAccountCallback(pj.AccountCallback):
+
+ global success
- def __init__(self, account=None):
- pj.AccountCallback.__init__(self, account)
+ def __init__(self, account=None):
+ pj.AccountCallback.__init__(self, account)
- # Notification on incoming call
- def on_incoming_call(self, call):
- global current_call
- global number
- if current_call:
- call.answer(486, "Busy")
- return
+ def on_incoming_call(self, call):
+ global current_call
+ global number
+
+ if current_call:
+ call.answer(486, "Busy")
+ return
- number = call.info().remote_uri
-
- current_call = call
-
- call_cb = MyCallCallback(current_call)
- current_call.set_callback(call_cb)
-
- current_call.answer(180)
- print "accept call"
- if current_call <> None:
- accept = True
- if accept == True:
- sleep(2)
- current_call.answer(200)
- sleep(3)
- current_call.hangup()
- accept = "true"
- server.sendData('success')
-
- #server.sendData(success)
-
-
+ number = call.info().remote_uri
+ current_call = call
-
-# Callback to receive events from Call
-class MyCallCallback(pj.CallCallback):
+ call_cb = MyCallCallback(current_call)
+ current_call.set_callback(call_cb)
- def __init__(self, call=None):
- pj.CallCallback.__init__(self, call)
+ current_call.answer(180)
+ print "accept call"
- # Notification when call state has changed
- def on_state(self):
- global current_call
-
- if self.call.info().state_text == "CONNECTING":
- print self.call.info().state_text
- success = "success"
+ if current_call <> None:
+ accept = True
- if self.call.info().state == pj.CallState.DISCONNECTED:
- current_call = None
- print 'Current call is', current_call
+ if accept == True:
+ sleep(0.5)
+ current_call.answer(200)
+ sleep(4)
+ current_call.hangup()
+ accept = True
+ success = True
+ server.sendData(success)
- # Notification when call's media state has changed.
- def on_media_state(self):
- if self.call.info().media_state == pj.MediaState.ACTIVE:
- # Connect the call to sound device
- call_slot = self.call.info().conf_slot
- pj.Lib.instance().conf_connect(call_slot, 0)
- pj.Lib.instance().conf_connect(0, call_slot)
- #server.sendData('establish connection')
+class MyCallCallback(pj.CallCallback):
- print "Media is now active"
-
+ def __init__(self, call=None):
+ pj.CallCallback.__init__(self, call)
- else:
- print "Media is inactive"
+
+ def on_state(self):
+ global current_call
+ global success
+
+ if self.call.info().state == pj.CallState.CONNECTING:
+ print self.call.info().state_text
+ success = True
+ if self.call.info().state == pj.CallState.DISCONNECTED:
+ current_call = None
+ print 'Current call is', current_call
lib = pj.Lib()
@@ -115,9 +98,8 @@ try:
server.closeConection()
lib.init(log_cfg = pj.LogConfig(level=LOG_LEVEL, callback=log_cb))
-
-
transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0))
+
print "\nListening on", transport.info().host,
print "port", transport.info().port, "\n"