|
@@ -2,7 +2,8 @@
|
|
|
#include "ConnectorFSM.h"
|
|
|
#include "../include/ModuleMix.h"
|
|
|
#include "../include/EventCode.h"
|
|
|
-
|
|
|
+#include "json/json.h"
|
|
|
+#include <regex>
|
|
|
|
|
|
#define RELEASEING_TIMER_INTERVAL 1200
|
|
|
#define RELEASEING_SIP_TIMER 20000
|
|
@@ -26,6 +27,46 @@ unsigned long GetTickCount()
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
+static int iHttpLogCount = 0;
|
|
|
+
|
|
|
+struct GrayLaunchReq : CHTTPReq{
|
|
|
+ GrayLaunchReq(){m_timeOut = 5;}
|
|
|
+ CSimpleStringA m_terminal_no;
|
|
|
+ CSimpleStringA m_branch_no;
|
|
|
+ CSimpleStringA m_modular;
|
|
|
+ virtual string ToJson(){
|
|
|
+ char reqcontent[512];
|
|
|
+ //string reqcontent = "{\"terminal_no\":\"" + m_terminal_no.GetData() + "\",\"branch_no\":\"" + m_branch_no.GetData() +
|
|
|
+ // "\",\"m_modular\":\"" + m_modular.GetData() + "\"}";
|
|
|
+ sprintf(reqcontent, "{\"terminal_no\":\"%s\",\"branch_no\":\"%s\",\"modular\":\"%s\"}", m_terminal_no.GetData(),
|
|
|
+ m_branch_no.GetData(), m_modular.GetData());
|
|
|
+ return reqcontent;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+struct GrayLaunchResponse : CHTTPRet{
|
|
|
+ GrayLaunchResponse():m_result(false){}
|
|
|
+ bool m_result;
|
|
|
+ virtual bool Parse(string strData){
|
|
|
+ Dbg("GrayLaunchResponse: data = %s", strData.c_str());
|
|
|
+ Json::Value root;
|
|
|
+ Json::Reader reader;
|
|
|
+ reader.parse(strData, root, false);
|
|
|
+ if (root["data"].isBool()) {
|
|
|
+ m_result = root["data"].asBool();
|
|
|
+ }
|
|
|
+ return m_result;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+static void HTTPLogCallback(const char* msg){
|
|
|
+ if (0 == iHttpLogCount){
|
|
|
+ LogWarn(Severity_Low, Error_Unexpect, LOG_WARN_COUNTERCONNECT_GRAY_FAILED, msg);
|
|
|
+ iHttpLogCount++;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
class SyncServiceClient:public SyncService_ClientBase
|
|
|
{
|
|
|
public:
|
|
@@ -135,6 +176,14 @@ ErrorCodeEnum ACMCallFSM::OnInit()
|
|
|
memset(m_strChanCallNum,0,sizeof(m_strChanCallNum));
|
|
|
memset(m_strChanProxyIP,0,sizeof(m_strChanProxyIP));
|
|
|
memset(m_iSIPProxyPort,0,sizeof(m_iSIPProxyPort));
|
|
|
+ m_strCallRouteIP = NULL;
|
|
|
+ m_iCallRoutePort = 0;
|
|
|
+ m_strCallRouteBranchNo = NULL;
|
|
|
+ m_strCallRouteAccessNo = NULL;
|
|
|
+ m_pCallRouteList = NULL;
|
|
|
+ m_pHttpFunc = create_http(HTTPLogCallback);
|
|
|
+ m_bGrayLaunch = FALSE;
|
|
|
+ m_strDirectCenterPattern = NULL;
|
|
|
ErrorCodeEnum Error = LoadConfig();
|
|
|
if (Error != Error_Succeed)
|
|
|
goto on_error;
|
|
@@ -145,7 +194,10 @@ ErrorCodeEnum ACMCallFSM::OnInit()
|
|
|
goto on_error;
|
|
|
Dbg("sip proxy ip1:%s,num1:%s,port1:%d;ip2:%s,num2:%s,port2:%d", (LPCSTR)m_strSIPProxyIP[0],(LPCSTR)m_strSIPCallNum[0], m_iSIPProxyPort[0],(LPCSTR)m_strSIPProxyIP[1],(LPCSTR)m_strSIPCallNum[1], m_iSIPProxyPort[1]);
|
|
|
Dbg("chan proxy ip1:%s,num1:%s,port1:%d;ip2:%s,num2:%s,port2:%d", (LPCSTR)m_strChanProxyIP[0],(LPCSTR)m_strChanCallNum[0], m_iChanProxyPort[0],(LPCSTR)m_strChanProxyIP[1],(LPCSTR)m_strChanCallNum[1], m_iChanProxyPort[1]);
|
|
|
+ Dbg("CallRouteIP:%s,port:%d", (LPCSTR)m_strCallRouteIP,m_iCallRoutePort);
|
|
|
Dbg("TerminalId: %s", (LPCSTR)m_strTerminalId);
|
|
|
+ Dbg("DirectCenterPattern: %s", (LPCSTR)m_strDirectCenterPattern);
|
|
|
+ Dbg("GrayLaunchUrl: %s", (LPCSTR)m_strGrayLaunchUrl);
|
|
|
m_bHangup = FALSE;
|
|
|
m_bHandFree = TRUE;
|
|
|
m_bAgentHandFree = TRUE;
|
|
@@ -337,8 +389,11 @@ void ACMCallFSM::OnStateTrans(int iSrcState, int iDstState)
|
|
|
if (!((st2 == eState_Fail)&&(m_nCurChanServer != Error_Server)&&(m_nCurSipServer != Error_Server))||m_bHangup)
|
|
|
{
|
|
|
if (eState_Fail != st1 || eState_Connecting != st2){
|
|
|
- Dbg("Broadcast state from %d to %d", st1, st2);
|
|
|
+ char strmsg[MAX_PATH] = {0};
|
|
|
+ _snprintf(strmsg, MAX_PATH,"Broadcast state from %d to %d", st1, st2);
|
|
|
+ Dbg(strmsg);
|
|
|
SpSendBroadcast(GetEntityBase()->GetFunction(), SP_MSG_OF(PhoneState), SP_MSG_SIG_OF(PhoneState), evt);
|
|
|
+ LogWarn(Severity_Middle, Error_Debug, LOG_WARN_COUNTERCONNECT_BROADCAST_CALL_STATE, strmsg);
|
|
|
}
|
|
|
else{
|
|
|
char strinfo[MAX_PATH] = {0};
|
|
@@ -392,11 +447,16 @@ void ACMCallFSM::s0_on_entry()
|
|
|
memset(&m_CallingParam,0,sizeof(m_CallingParam));
|
|
|
GetEntityBase()->GetFunction()->SetSysVar("CallType", "N"); //进入初始状态时设置呼叫模式为常规呼叫
|
|
|
m_nSysCallType = 0;
|
|
|
+ if(m_pCallRouteList != NULL){
|
|
|
+ free_node_list(m_pCallRouteList);
|
|
|
+ m_pCallRouteList = NULL;
|
|
|
+ }
|
|
|
}
|
|
|
void ACMCallFSM::s0_on_exit()
|
|
|
{
|
|
|
m_bHangup = FALSE;
|
|
|
m_nStarttime = GetTickCount();
|
|
|
+ m_bGrayLaunch = FALSE;
|
|
|
}
|
|
|
|
|
|
unsigned int ACMCallFSM::s0_on_event(FSMEvent* event)
|
|
@@ -532,6 +592,31 @@ unsigned int ACMCallFSM::s9_on_event(FSMEvent* event)
|
|
|
|
|
|
void ACMCallFSM::s8_on_entry()
|
|
|
{
|
|
|
+ //get call route,采用直接总行方式
|
|
|
+ if ((m_strDirectCenterPattern.GetLength() != 0) && (m_strGrayLaunchUrl.GetLength() != 0)){
|
|
|
+ if (std::regex_match(m_strTerminalId.GetData(), std::regex(m_strDirectCenterPattern.GetData()))) {
|
|
|
+ GrayLaunchReq req;
|
|
|
+ req.m_url = m_strGrayLaunchUrl.GetData();
|
|
|
+ req.m_terminal_no = m_strTerminalId;
|
|
|
+ req.m_branch_no = m_strCallRouteBranchNo;
|
|
|
+ req.m_modular = "counterconnector";
|
|
|
+ GrayLaunchResponse response;
|
|
|
+ bool ret = m_pHttpFunc->Get(req, response);
|
|
|
+ if (ret) {
|
|
|
+ m_bGrayLaunch = response.m_result;
|
|
|
+ }
|
|
|
+ if (m_bGrayLaunch && (m_strCallRouteIP.GetLength() != 0)) {
|
|
|
+ call_info_t call_info;
|
|
|
+ call_info.callroute_server_ip = m_strCallRouteIP;
|
|
|
+ call_info.callroute_server_port = m_iCallRoutePort;
|
|
|
+ call_info.szbranchno = m_strCallRouteBranchNo;
|
|
|
+ call_info.szcaller_num = m_strTerminalId;
|
|
|
+ call_info.szdest_num = m_strCallRouteAccessNo;
|
|
|
+ m_pCallRouteList = get_callroute_list(&call_info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
int time = GetDelayTime();
|
|
|
Dbg("get Delay time = %d",time);
|
|
|
if (time > 0)
|
|
@@ -596,50 +681,73 @@ void ACMCallFSM::s11_on_entry()
|
|
|
if (m_nCurSipServer == Error_Server){
|
|
|
Error = Error_NetBroken;
|
|
|
}
|
|
|
- if (Error == Error_Succeed)
|
|
|
- {
|
|
|
- if (m_CallingParam.nCallType != NORMAL_CALLTYPE && m_CallingParam.nCallType != DOUBLERECORD_CALLTYPE)
|
|
|
- {
|
|
|
- Dbg("Begin Make Distribute Call!");
|
|
|
- Error = MakeCall(m_nCurSipServer,m_CallingParam);
|
|
|
- if (Error!=Error_Succeed)
|
|
|
- {
|
|
|
- m_nCurSipServer?(m_nCurSipServer=Error_Server):(m_nCurSipServer=BACK_SERVER);
|
|
|
- }
|
|
|
- Dbg("make call result:0x%08x", Error);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (NORMAL_CALLTYPE == m_CallingParam.nCallType){
|
|
|
- Dbg("Begin Make Normal Call!");
|
|
|
- }
|
|
|
+
|
|
|
+ if (Error == Error_Succeed){
|
|
|
+ bool center_connect = FALSE;
|
|
|
+ //get call route,采用直接总行方式
|
|
|
+ if (m_bGrayLaunch && (m_strCallRouteIP.GetLength() != 0)) {
|
|
|
+ callurl_node_t *node = get_no_used_node(m_pCallRouteList);
|
|
|
+ if (node != NULL){
|
|
|
+ Dbg("Begin Head Office Make Call!");
|
|
|
+ char ipstr[256] = {0};
|
|
|
+ char callid_str[64] = { 0 };
|
|
|
+ GetLocalIP(ipstr);
|
|
|
+ get_format_uuid(callid_str, 64);
|
|
|
+ Error = MakeCall(node->strcallurl, CSimpleStringA::Format("sip:%s@%s;transport=UDP", node->strnewcallernum, ipstr),
|
|
|
+ callid_str, m_CallingParam);
|
|
|
+ m_iChanProxyPort[0] = node->uassistport;
|
|
|
+ m_iChanProxyPort[1] = node->uassistport;
|
|
|
+ m_strChanProxyIP[0] = node->strassistip;
|
|
|
+ m_strChanProxyIP[1] = node->strassistip;
|
|
|
+ if (Error!=Error_Succeed){
|
|
|
+ m_nCurSipServer?(m_nCurSipServer=Error_Server):(m_nCurSipServer=BACK_SERVER);
|
|
|
+ }
|
|
|
+ m_nCurChanServer = BACK_SERVER;
|
|
|
+ node->bused = TRUE;
|
|
|
+ Dbg("head office make call result:0x%08x", Error);
|
|
|
+ center_connect = TRUE;
|
|
|
+ }
|
|
|
else{
|
|
|
- Dbg("Begin Make Record Call!");
|
|
|
- }
|
|
|
-
|
|
|
- Error = MakeCall(m_strHintCallNum.GetLength() > 0 ? (LPCSTR)m_strHintCallNum : (LPCSTR)m_strSIPCallNum[m_nCurSipServer],m_nCurSipServer);
|
|
|
- if (Error!=Error_Succeed)
|
|
|
- {
|
|
|
- m_nCurSipServer?(m_nCurSipServer=Error_Server):(m_nCurSipServer=BACK_SERVER);
|
|
|
- }
|
|
|
- Dbg("make call result:0x%08x", Error);
|
|
|
+ Dbg("head office mode no more call router, try to connect branch server.");
|
|
|
+ //m_nCurSipServer = MAIN_SERVER;
|
|
|
+ //m_nCurChanServer = MAIN_SERVER;
|
|
|
+ center_connect = FALSE;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (Error != Error_Succeed) {
|
|
|
- if (Error_NetBroken == Error || Error_Unexpect == Error){
|
|
|
- PostEventFIFO(new FSMEvent(USER_EVT_HANGUP));
|
|
|
- m_bHangup = TRUE;
|
|
|
- if (Error_Unexpect == Error){
|
|
|
- LogFatal(Severity_High, Error_Unexpect, 0, "获取IP失败,请检查机器网络!");
|
|
|
+ //old call branch server方式
|
|
|
+ if(!center_connect){
|
|
|
+ if (m_CallingParam.nCallType != NORMAL_CALLTYPE && m_CallingParam.nCallType != DOUBLERECORD_CALLTYPE)
|
|
|
+ {
|
|
|
+ Dbg("Begin Branch Make Distribute Call!");
|
|
|
+ Error = MakeCall(m_nCurSipServer,m_CallingParam);
|
|
|
+ if (Error!=Error_Succeed)
|
|
|
+ {
|
|
|
+ m_nCurSipServer?(m_nCurSipServer=Error_Server):(m_nCurSipServer=BACK_SERVER);
|
|
|
+ }
|
|
|
+ Dbg("branch make call result:0x%08x", Error);
|
|
|
}
|
|
|
- else{
|
|
|
- LogFatal(Severity_High, Error_NetBroken, 0, "系统故障,尝试恢复中(预计90s内),请稍等!");
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (NORMAL_CALLTYPE == m_CallingParam.nCallType){
|
|
|
+ Dbg("Begin Branch Make Normal Call!");
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ Dbg("Begin Branch Make Record Call!");
|
|
|
+ }
|
|
|
+
|
|
|
+ Error = MakeCall(m_strHintCallNum.GetLength() > 0 ? (LPCSTR)m_strHintCallNum : (LPCSTR)m_strSIPCallNum[m_nCurSipServer],m_nCurSipServer);
|
|
|
+ if (Error!=Error_Succeed)
|
|
|
+ {
|
|
|
+ m_nCurSipServer?(m_nCurSipServer=Error_Server):(m_nCurSipServer=BACK_SERVER);
|
|
|
+ }
|
|
|
+ Dbg("branch make call result:0x%08x", Error);
|
|
|
}
|
|
|
}
|
|
|
- else{
|
|
|
- PostEventFIFO(new FSMEvent(USER_EVT_JMP_FAIL));
|
|
|
- }
|
|
|
+ }
|
|
|
+ if (Error != Error_Succeed)
|
|
|
+ {
|
|
|
+ PostEventFIFO(new FSMEvent(USER_EVT_JMP_FAIL));
|
|
|
}
|
|
|
else
|
|
|
{
|