///////////////////////////////// ///// 连线服务 ///////////////////////////////// #include "stdafx.h" #include "ListEntry.h" #include "Event.h" #include "mod_counterconnector.h" #include "CounterConnector_msg_g.h" using namespace CounterConnector; #define EVT_CONVERTER "EventConverter" void CCounterConnectorEntity ::OnPreStart(CAutoArray strArgs,CSmartPointer pTransactionContext) { ErrorCodeEnum Error = __OnStart(Error_Succeed); CSmartPointer spFunction = GetFunction(); Error = spFunction->SubscribeBroadcast("LivenessDetection", NULL, this, m_uidlivenessListener); if (Error != Error_Succeed) { LOG_TRACE("subscribe LivenessDetection evt failed!"); pTransactionContext->SendAnswer(Error); return; } pTransactionContext->SendAnswer(Error); } void CCounterConnectorEntity ::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer pTransactionContext) { ErrorCodeEnum Error = __OnClose(Error_Succeed); pTransactionContext->SendAnswer(Error); } void CCounterConnectorEntity ::OnSelfTest(EntityTestEnum eTestType,CSmartPointer pTransactionContext) { if (Test_ShakeHand == eTestType) { pTransactionContext->SendAnswer(Error_Succeed); } } ErrorCodeEnum CCounterConnectorEntity ::__OnStart(ErrorCodeEnum preOperationError) { if (preOperationError != Error_Succeed) return preOperationError; //MessageBoxA(0, 0, 0, 0); //is Pad Version m_pCurrentSession = NULL; m_bIsSalesRecord = FALSE; m_bIsRemoteRecord = FALSE; m_bIsRemoteRecordBroadCast = FALSE; CSmartPointer spFunction = GetFunction(); CSystemStaticInfo stStaticinfo; spFunction->GetSystemStaticInfo(stStaticinfo); if (stricmp(stStaticinfo.strMachineType,"RVC.PAD")==0) { m_bIsPadType = TRUE; } else { m_bIsPadType = FALSE; } m_IsStand2SType = TRUE; if (stricmp(stStaticinfo.strMachineType,"RVC.Stand2S")!=0){ m_IsStand2SType = FALSE; } ErrorCodeEnum Error; m_pCounterConnectorChannel = new ChannelCounterConnectorClient(this); Error = m_pCounterConnectorChannel->Connect(); if (Error != Error_Succeed) { m_pCounterConnectorChannel->SafeDelete(); Dbg("ChannelCounterConnectorClient connect fail!"); return Error; } { ChannelService_BeginState_Sub Sub; Error = m_pCounterConnectorChannel->BeginState(Sub); if (Error != Error_Succeed) { LOG_TRACE("BeginState biz channel failed!"); m_pCounterConnectorChannel->GetFunction()->CloseSession(); m_pCounterConnectorChannel->SafeDelete(); m_pCounterConnectorChannel = NULL; return Error; } } { ChannelService_BeginRecv_Sub Sub; Sub.type = ACM_TYPE_DEVICE; Error = m_pCounterConnectorChannel->BeginRecv(Sub); if (Error != Error_Succeed) { Dbg("Begin BeginRecv ACM_TYPE_DEVICE failed!"); m_pCounterConnectorChannel->GetFunction()->CloseSession(); m_pCounterConnectorChannel->SafeDelete(); m_pCounterConnectorChannel = NULL; return Error; } } { ChannelService_BeginRecv_Sub Sub; Sub.type = ACM_TYPE_AGENTVIDEOTYPE; Error = m_pCounterConnectorChannel->BeginRecv(Sub); if (Error != Error_Succeed) { Dbg("Begin BeginRecv ACM_TYPE_AGENTVIDEOTYPE failed!"); m_pCounterConnectorChannel->GetFunction()->CloseSession(); m_pCounterConnectorChannel->SafeDelete(); m_pCounterConnectorChannel = NULL; return Error; } } { ChannelService_BeginRecv_Sub Sub; Sub.type = ACM_TYPE_CALLTRANS; Error = m_pCounterConnectorChannel->BeginRecv(Sub); if (Error != Error_Succeed) { Dbg("Begin BeginRecv ACM_TYPE_CALLTRANS failed!"); m_pCounterConnectorChannel->GetFunction()->CloseSession(); m_pCounterConnectorChannel->SafeDelete(); m_pCounterConnectorChannel = NULL; return Error; } } m_fsm.Init(this); int i = 0; m_arrListener.Init(24); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_CALL,NULL,false); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANDFREE_CALL,NULL,false); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANNUP); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANNUP_BY_CONNECTING); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANNUP_BY_AGENT); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_GPIO_PICKUP); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_GPIO_HANDFREE); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_SIPPHONE_IDLE); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD,NULL,false); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD,NULL,false); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU,NULL,false); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTPHOTOGRAPH,NULL,false); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_DISTRIBUTE_ASSISTANTCHANNEL_IDLE); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_DISTRIBUTE_SIPPHONE_IDLE); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST,NULL,false); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_BEGAIN_RECORD_CALL,NULL,false); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD,NULL,false); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD,NULL,false); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORDPREVIEW,NULL,false); return Error_Succeed; } ErrorCodeEnum CCounterConnectorEntity ::__OnClose(ErrorCodeEnum preOperationError) { if (preOperationError != Error_Succeed) return preOperationError; int i; CSmartPointer spFunction = GetFunction(); for (i = 0; i < m_arrListener.GetCount(); ++i) { spFunction->UnsubscribeLog(m_arrListener[i]); } m_arrListener.Clear(); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_EXIT)); return Error_Succeed; } void CCounterConnectorEntity ::OnLog(const CAutoArray &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel, const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID, const CAutoArray &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage) { LOG_TRACE("user_code = %08x", dwUserCode); switch (dwUserCode) { case EVENT_MOD_CONNECT_GPIO_PICKUP: { m_fsm.m_bHandFree = FALSE; if (!m_fsm.m_bIsAgentControl) { m_fsm.m_bAgentHandFree = FALSE; } CSimpleStringA strValue; GetFunction()->GetSysVar("CallState", strValue); Dbg("摘机,and CallState is %s.", strValue); } break; case EVENT_MOD_CONNECT_GPIO_HANDFREE: { m_fsm.m_bHandFree = TRUE; if (!m_fsm.m_bIsAgentControl) { m_fsm.m_bAgentHandFree = TRUE; } CSimpleStringA strValue; GetFunction()->GetSysVar("CallState", strValue); Dbg("挂机,and CallState is %s.", strValue); } break; case EVENT_MOD_CONNECT_PICKUP_CALL: // 提机呼叫 if (!m_bIsRemoteRecordBroadCast){ Dbg("提机呼叫"); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_PICKUP_CALL)); } else{ Dbg("remote recording broadcast time, ignore mod connect pickup call event, and hand free flag is %s.",m_fsm.m_bHandFree?"true": "false"); } break; case EVENT_MOD_CONNECT_HANDFREE_CALL: // 免提呼叫 if (m_fsm.m_bHandFree) { LogEvent(Severity_Middle,EVENT_MOD_CONNECT_SLV_HANDFREECALL,"handfree call"); Dbg("界面拨号,免提呼叫"); if (pszMessage && strlen(pszMessage) > 0 && isdigit(pszMessage[0])) { char tmp[32]; int i = 0; const char *p = pszMessage; while (isdigit(*p) && i < 30) { tmp[i++] = *p++; } tmp[i] = 0; m_fsm.m_strHintCallNum = tmp; } else { m_fsm.m_strHintCallNum = ""; } Dbg("recv UI call num = %s",m_fsm.m_strHintCallNum); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANDFREE_CALL)); } else { LogEvent(Severity_Middle,EVENT_MOD_CONNECT_SLV_PICKUPCALL,"from handfree to pickup call because pickup"); Dbg("界面拨号,话筒呼叫"); if (pszMessage && strlen(pszMessage) > 0 && isdigit(pszMessage[0])) { char tmp[32]; int i = 0; const char *p = pszMessage; while (isdigit(*p) && i < 30) { tmp[i++] = *p++; } tmp[i] = 0; m_fsm.m_strHintCallNum = tmp; } else { m_fsm.m_strHintCallNum = ""; } Dbg("recv call num = %s",m_fsm.m_strHintCallNum); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_PICKUP_CALL)); } break; case EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP: // 免提->提机 if (!m_bIsRemoteRecordBroadCast){ Dbg("免提->提机"); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_TO_PICKUP)); if (strcmp(m_fsm.GetCurrStateName(),"HandFree")==0){ m_fsm.m_bAgentHandFree = FALSE; } SendCurAudioDevice(); } else{ Dbg("remote recording broadcast time, ignore mod connect hand free to pickup event,and hand free flag is %s.",m_fsm.m_bHandFree?"true": "false"); } break; case EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE: // 提机->免提 if (!m_bIsRemoteRecordBroadCast){ Dbg("提机->免提"); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_TO_HANDFREE)); if (strcmp(m_fsm.GetCurrStateName(),"Pickup")==0){ m_fsm.m_bAgentHandFree = TRUE; } SendCurAudioDevice(); } else{ Dbg("remote recording broadcast time, ignore mod connect pickup to hand free event,and hand free flag is %s.",m_fsm.m_bHandFree?"true": "false"); } break; case EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP: // 坐席控制免提->提机 Dbg("免提->提机"); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_TO_PICKUP)); SendCurAudioDevice(); break; case EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE: // 坐席控制提机->免提 Dbg("提机->免提"); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_TO_HANDFREE)); SendCurAudioDevice(); break; case EVENT_MOD_CONNECT_BEGAIN_RECORD_CALL: { Dbg("开始远程双录呼叫."); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_DOUBLE_RECORD_CALL)); if (TRUE == m_fsm.m_bHandFree){ LogEvent(Severity_Middle,LOG_EVT_HANDFREE_MODE_REMOTE_CALL,"remote double call start with hand free mode."); } else{ LogEvent(Severity_Middle,LOG_EVT_PICKUP_MODE_REMOTE_CALL,"remote double call start with pick up mode."); } } break; case EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST: Dbg("双录播报完结束,重置电话状态"); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOP_RECORD_BROADCAST)); m_bIsRemoteRecordBroadCast = FALSE; break; case EVENT_MOD_CONNECT_HANNUP: // 挂机 { Dbg("断开呼叫"); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANGUP)); m_fsm.m_bHangup=TRUE; } break; case EVENT_MOD_CONNECT_HANNUP_BY_CONNECTING: // 话筒未接通时挂机 Dbg("话筒未接通时断开呼叫"); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANGUP)); //m_fsm.m_bHandFree = TRUE; m_fsm.m_bHangup=TRUE; break; case EVENT_MOD_CONNECT_HANNUP_BY_AGENT: // 授权操作 m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_AGENT_WRITABLE)); case LOG_EVT_DISTRIBUTE_ASSISTANTCHANNEL_IDLE: case LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE: //若assistchannel重启 Dbg("user_code = %08x", dwUserCode); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_ASSISTCHAN_IDEL)); if(m_pCounterConnectorChannel != NULL) { m_pCounterConnectorChannel->GetFunction()->CloseSession(); m_pCounterConnectorChannel->SafeDelete(); m_pCounterConnectorChannel = NULL; Dbg("Close AssistChannel Session "); } if(m_pCounterConnectorChannel == NULL) { Dbg("ReConnection AssistChannel Session"); ErrorCodeEnum Error; m_pCounterConnectorChannel = new ChannelCounterConnectorClient(this); Error = m_pCounterConnectorChannel->Connect(); if (Error != Error_Succeed) { m_pCounterConnectorChannel->SafeDelete(); m_pCounterConnectorChannel = NULL; Dbg("ChannelCounterConnectorClient connect fail!"); } if (Error == Error_Succeed) { ChannelService_BeginState_Sub Sub; Error = m_pCounterConnectorChannel->BeginState(Sub); if (Error != Error_Succeed) { Dbg("BeginState biz channel failed!"); m_pCounterConnectorChannel->GetFunction()->CloseSession(); m_pCounterConnectorChannel->SafeDelete(); m_pCounterConnectorChannel = NULL; } } if (Error == Error_Succeed) { ChannelService_BeginRecv_Sub Sub; Sub.type = ACM_TYPE_DEVICE; Error = m_pCounterConnectorChannel->BeginRecv(Sub); if (Error != Error_Succeed) { Dbg("Begin BeginRecv ACM_TYPE_DEVICE failed!"); m_pCounterConnectorChannel->GetFunction()->CloseSession(); m_pCounterConnectorChannel->SafeDelete(); m_pCounterConnectorChannel = NULL; } } if (Error == Error_Succeed) { ChannelService_BeginRecv_Sub Sub; Sub.type = ACM_TYPE_CALLTRANS; Error = m_pCounterConnectorChannel->BeginRecv(Sub); if (Error != Error_Succeed) { Dbg("Begin BeginRecv ACM_TYPE_CALLTRANS failed!"); m_pCounterConnectorChannel->GetFunction()->CloseSession(); m_pCounterConnectorChannel->SafeDelete(); m_pCounterConnectorChannel = NULL; } } } break; case LOG_EVT_SELFCHECK_SIPPHONE_IDLE: //sip话机重启 Dbg("recv LOG_EVT_SELFCHECK_SIPPHONE_IDLE"); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_SIPPHONE_IDEL)); break; case LOG_EVT_UI_STARTRECORD: case LOG_EVT_UI_STARTRECORDPREVIEW: Dbg("start sales record video,get pos = %s",pszMessage); Handle_StartRecord(pszMessage); break; case LOG_EVT_UI_STARTREMOTERECORD: { Dbg("start sales remote record video,get pos = %s",pszMessage); Handle_StartRemoteRecord(pszMessage); } break; case LOG_EVT_UI_STOPRECORD: Dbg("begin stop sales record video."); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOPLOCALVIDEO)); m_bIsSalesRecord = FALSE; break; case LOG_EVT_UI_STOPREMOTERECORD: Dbg("begin stop double record video,and cur state name is %s.",m_fsm.GetCurrStateName()); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOPLOACALREMOTEVIDEO)); m_bIsRemoteRecord = FALSE; m_bIsRemoteRecordBroadCast = FALSE; break; case LOG_EVT_UI_RETURNMENU: if (m_bIsSalesRecord) { Dbg("stop sales record video by return menu"); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOPLOCALVIDEO)); m_bIsSalesRecord = FALSE; } if (m_bIsRemoteRecord) { Dbg("stop remote record video by return menu."); if (m_fsm.m_CallingParam.nCallType != DOUBLERECORD_CALLTYPE){ m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOPLOACALREMOTEVIDEO)); } else{ Dbg("hangup call by return menu, CurrStateName is %s.", m_fsm.GetCurrStateName()); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANGUP)); m_fsm.m_bHangup=TRUE; } m_bIsRemoteRecord = FALSE; } break; case LOG_EVT_UI_STARTPHOTOGRAPH: if (stricmp(m_fsm.GetCurrStateName(),"Offline")!=0) { LogEvent(Severity_Middle,EVENT_MOD_CONNECT_HANNUP,"UI start photograrh, hangup!"); } else { Dbg("offline state,ignore UI_STARTPHOTOGRAPH hangup event"); } break; case LOG_EVT_DISTRIBUTE_SIPPHONE_IDLE: //sip话机状态重置 Dbg("recv LOG_EVT_DISTRIBUTE_SIPPHONE_IDLE"); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_SIPPHONE_IDEL)); break; default: break; } } CServerSessionBase*CCounterConnectorEntity::OnNewSession(const char* /*pszRemoteEntityName*/, const char* /*pszClass*/) { LOG_FUNCTION(); m_pCurrentSession = new CCounterConnectorSession(this); return m_pCurrentSession; } bool CCounterConnectorEntity ::IsService() const { return true; } //change audio device message void CCounterConnectorEntity ::OnReceivePkt(int type, int sub_type, const char *buffer, int size) { Dbg("recv pkt type=%d,subtype=%d",type,sub_type); if ((type == ACM_TYPE_DEVICE)&&!m_bIsPadType) { switch (sub_type) { //设备切换 //change to handfree case ACM_CHANGE_HANDFREE: Dbg("recv change audiodevice to handfree"); if (!m_fsm.m_bAgentHandFree) { LogEvent(Severity_Middle,EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE,"agent change audio device to handfree"); m_fsm.m_bAgentHandFree = TRUE; } else { Dbg("agent want change audiodevice to handfree,but the device is handfree now"); } break; //change to pickup case ACM_CHANGE_PICKUP: Dbg("recv change audiodevice to pickup"); if (m_fsm.m_bAgentHandFree) { LogEvent(Severity_Middle,EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP,"agent change audio device to pickup"); m_fsm.m_bAgentHandFree = FALSE; } else { Dbg("agent want change audiodevice to pickup,but the device is pickup now"); } break; default: LOG_TRACE("unknown sub_type %d from agent!", sub_type); break; } } else if (type == ACM_TYPE_CALLTRANS) { Dbg("recv ACM_TYPE_CALLTRANS"); if (sub_type == ACM_CALLTRANS_NUM) { //CALL transfer CallTransferInfo Callnum; SpBuffer buf; buf.OpenRead(buffer,size); Callnum.Serialize(buf); Dbg("recv ACM_CALLTRANS_NUM = %s",Callnum.CallNum); //广播,业务中台接收 SpSendBroadcast(GetFunction(), SP_MSG_OF(CallTransferInfo), SP_MSG_SIG_OF(CallTransferInfo), Callnum); } } else if (type == ACM_TYPE_AGENTVIDEOTYPE) { if (sub_type == ACM_AGENTVIDEOTYPE_ONEWAY) { //广播单向视频 AgentVideoType agentvideotype; agentvideotype.VideoType = 0; Dbg("Broadcast Oneway video"); SpSendBroadcast(GetFunction(), SP_MSG_OF(AgentVideoType), SP_MSG_SIG_OF(AgentVideoType), agentvideotype); } else if (sub_type == ACM_AGENTVIDEOTYPE_TWOWAY) { //广播双向视频 AgentVideoType agentvideotype; agentvideotype.VideoType = 1; Dbg("Broadcast Twoway Video"); SpSendBroadcast(GetFunction(), SP_MSG_OF(AgentVideoType), SP_MSG_SIG_OF(AgentVideoType), agentvideotype); } } } CSimpleStringA CCounterConnectorEntity ::BuildVideoDesc(int local_view_x, int local_view_y, int local_view_cx, int local_view_cy) { char param[512]; sprintf(param, "remote_ip:0\r\n" "remote_video_rtp:0\r\n" "remote_video_width:0\r\n" "remote_video_height:0\r\n" "remote_video_fps:0\r\n" "local_view_x:%d\r\n" "local_view_y:%d\r\n" "local_view_cx:%d\r\n" "local_view_cy:%d\r\n" "remote_view_x:0\r\n" "remote_view_y:0\r\n" "remote_view_cx:0\r\n" "remote_view_cy:0\r\n\r\n", local_view_x, local_view_y, local_view_cx, local_view_cy); return CSimpleStringA(param); } CSimpleStringA CCounterConnectorEntity ::BuildDoubleVideoDesc(int local_view_x, int local_view_y, int local_view_cx, int local_view_cy, int remote_view_x, int remote_view_y, int remote_view_cx, int remote_view_cy) { char param[512]; sprintf(param, "remote_ip:0\r\n" "remote_video_rtp:0\r\n" "remote_video_width:0\r\n" "remote_video_height:0\r\n" "remote_video_fps:0\r\n" "local_view_x:%d\r\n" "local_view_y:%d\r\n" "local_view_cx:%d\r\n" "local_view_cy:%d\r\n" "remote_view_x:%d\r\n" "remote_view_y:%d\r\n" "remote_view_cx:%d\r\n" "remote_view_cy:%d\r\n\r\n", local_view_x, local_view_y, local_view_cx, local_view_cy, remote_view_x, remote_view_y, remote_view_cx, remote_view_cy); return CSimpleStringA(param); } CSimpleStringA CCounterConnectorEntity ::ConstructVideoParam(CSimpleStringA strMsg, bool bDoubleVideo) { int lxPos,lyPos,lwidth,lheight,rxPos,ryPos,rwidth,rheight; CSimpleStringA strVideoParam; CSimpleStringA str; if (false == bDoubleVideo){ sscanf(strMsg.GetData(), "%d@%d@%d@%d@%d@%s", &lxPos, &lyPos, &lwidth, &lheight, &str); Dbg("local video param : (x=%d,y=%d,width=%d,height=%d).",lxPos,lyPos,lwidth,lheight); strVideoParam = BuildVideoDesc(lxPos,lyPos,lwidth,lheight); } else{ int iPostionArr[4][2] = {0}; if (strMsg.GetLength() >0) { CAutoArray arrstr = strMsg.Split('@'); if (arrstr.GetCount() >= 4) { for(int i=0; i<4; i++) { sscanf(arrstr[i].GetData(), "%d|%d", &iPostionArr[i][0], &iPostionArr[i][1]); } } } Dbg("remote record local video param : (x=%d,y=%d,width=%d,height=%d), remote video param : (x=%d,y=%d,width=%d,height=%d)", iPostionArr[0][0], iPostionArr[1][0],iPostionArr[2][0], iPostionArr[3][0],iPostionArr[0][1], iPostionArr[1][1],iPostionArr[2][1], iPostionArr[3][1]); strVideoParam = BuildDoubleVideoDesc(iPostionArr[0][0], iPostionArr[1][0],iPostionArr[2][0], iPostionArr[3][0],iPostionArr[0][1], iPostionArr[1][1],iPostionArr[2][1], iPostionArr[3][1]); } return strVideoParam; } void CCounterConnectorEntity::Handle_StartRecord(const char* pszMessage) { // edit by ly@2019/04/18 CSimpleStringA strMsg = pszMessage; if (strMsg.IsStartWith("ews|",true)){ strMsg = strMsg.SubString(4,strMsg.GetLength()-4); } CSimpleStringA strVideo; strVideo = ConstructVideoParam(strMsg, false); m_fsm.PostEventFIFO(new ShowLocalVideoEvent(strVideo)); // 非连坐席双录 m_bIsSalesRecord = TRUE; } void CCounterConnectorEntity::Handle_StartRemoteRecord(const char* pszMessage) { // edit by ly@2019/04/18 CSimpleStringA strMsg = pszMessage; CSimpleStringA strVideo = ConstructVideoParam(strMsg, true); m_fsm.PostEventFIFO(new ShowLocalAndRemoteVideoEvent(strVideo)); // 连坐席双录 m_bIsRemoteRecord = TRUE; m_bIsRemoteRecordBroadCast = TRUE; m_bIsRemoteRecordStopSpeakerCapture = FALSE; } void CCounterConnectorEntity::StopRemoteRecordSpeakerAudioCapture() { if(DOUBLERECORD_CALLTYPE == m_fsm.m_CallingParam.nCallType){ if (TRUE == m_IsStand2SType){ if (FALSE == m_bIsRemoteRecordStopSpeakerCapture){ if (Error_Succeed == m_fsm.StopSpeakerAudioCapture()){ m_bIsRemoteRecordStopSpeakerCapture = TRUE; } } else{ Dbg("remote record has stop speaker capture."); } } } } void CCounterConnectorEntity::Handle_StartRecordPreview(const char* pszMessage) { CSimpleStringA strMsg = pszMessage; if (strMsg.IsStartWith("ews|",true)){ strMsg = strMsg.SubString(4,strMsg.GetLength()-4); } CSimpleStringA strVideo; strVideo = ConstructVideoParam(strMsg, false); m_fsm.PostEventFIFO(new ShowLocalVideoEvent(strVideo)); // 非连坐席双录 m_bIsSalesRecord = TRUE; } //send cur audio device to agent void CCounterConnectorEntity ::SendCurAudioDevice() { if (m_fsm.m_nSysCallType == 0) { ChannelService_Send_Info Info; Info.compress = false; Info.encrypt = false; Info.type = ACM_TYPE_DEVICE; Info.id = 0; Info.sub_type = ACM_AUDIO_DEVICE; Info.data.Alloc(sizeof(int)); SpBuffer buf; buf.OpenWrite(); int nDevice = 0; if (m_fsm.m_bIsAgentControl) { if (m_fsm.m_bAgentHandFree) { nDevice = 0; } else { nDevice = 1; } } else { if (m_fsm.m_bHandFree) { nDevice = 0; } else { nDevice = 1; } } buf & nDevice; Info.data = buf.ToBlob(); m_pCounterConnectorChannel->Send(Info); Dbg("send cur Audio device = %d",nDevice); } else { Dbg("cur call type cannot send pkt"); } } void CCounterConnectorEntity::SetCallType(CallingTypeEnum eType) { m_fsm.SetCallingType(eType); } void CCounterConnectorEntity::OnLivenessDetectionStarted(const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, LivenessDetection::ActiveDetectionStarted &evt) { Dbg("LiveDetectionStarted %s", (LPCTSTR)evt.Param); LogEvent(Severity_Middle,LOG_EVT_STARTLIVEDETECTDISPLAY,"start live detection"); Sleep(400); int rxPos,ryPos,rwidth,rheight,xPos,yPos,width,height; CSimpleStringA str; sscanf((LPCTSTR)evt.Param, "%d@%d@%d@%d@%d@%d@%d@%d", &rxPos, &ryPos, &rwidth, &rheight,&xPos, &yPos, &width, &height); Dbg("live detection display window x=%d,y=%d,width=%d,height=%d",xPos,yPos,width,height); CSimpleStringA strVideo = BuildVideoDesc(xPos,yPos,width,height); m_fsm.PostEventFIFO(new StartVideoDisplayEvent(strVideo)); } void CCounterConnectorEntity::OnLivenessDetectionStopped(const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, LivenessDetection::ActiveDetectionStopped &evt) { Dbg("LiveDetectionStopped %s", (LPCTSTR)evt.Param); LogEvent(Severity_Middle,LOG_EVT_STOPLIVEDETECTDISPLAY,"stop live detection"); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOPVIDEODISPLAY)); } void CCounterConnectorEntity::OnActiveDetectionDone(const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, LivenessDetection::ActiveDetectionDone &evt) { } void CCounterConnectorEntity::OnAutoSnapshotRemind(const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, LivenessDetection::AutoSnapshotRemind &evt) { } void CCounterConnectorEntity::OnLivenessDetectionHeartBeat(const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, LivenessDetection::LivenessDetectionHeartBeat &evt) { } void CCounterConnectorEntity::OnDetectionStopUnExpected(const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, LivenessDetection::DetectionStopUnExpected &evt) { } ChannelCounterConnectorClient::ChannelCounterConnectorClient( CCounterConnectorEntity *pEntity ) : ChannelService_ClientBase(pEntity) { } void ChannelCounterConnectorClient::OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer pData) { if (Error == Error_Succeed) { CCounterConnectorEntity *pEntity = static_cast(m_pEntityBase); if (Msg.state == eChannelState_Idle) { pEntity->m_fsm.m_bIsAgentControl = FALSE; } else if (Msg.state == eChannelState_Connected) { pEntity->m_fsm.m_bIsAgentControl = TRUE; pEntity->SendCurAudioDevice(); } } } void ChannelCounterConnectorClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer pData ) { LOG_FUNCTION(); if (Error == Error_Succeed) { CCounterConnectorEntity *pEntity = static_cast(m_pEntityBase); pEntity->OnReceivePkt(Msg.type, Msg.sub_type, (const char*)Msg.data.m_pData, Msg.data.m_iLength); } } void CCounterConnectorSession::Handle_StartCall(SpReqAnsContext::Pointer ctx) { LOG_FUNCTION(); ErrorCodeEnum rc = Error_Succeed; m_pEntity->m_fsm.m_CallingParam.connect_ip = ctx->Req.connect_ip; m_pEntity->m_fsm.m_CallingParam.connect_port = ctx->Req.connect_port; m_pEntity->m_fsm.m_CallingParam.nCallType = (CallingTypeEnum)ctx->Req.callingtype; m_pEntity->m_fsm.m_CallingParam.connect_session = ctx->Req.connect_session; m_pEntity->m_fsm.m_CallingParam.assistant_port = ctx->Req.assistant_port; m_pEntity->m_fsm.m_CallingParam.subid = ctx->Req.subid; m_pEntity->m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_COMMAND_CALL)); ctx->Answer((ErrorCodeEnum)rc); } void CCounterConnectorSession::Handle_StartCallExternal(SpReqAnsContext::Pointer ctx) { LOG_FUNCTION(); ErrorCodeEnum rc = Error_Succeed; RVCCallingParam* callparam = (RVCCallingParam*)ctx->Req.CommandParam.m_pData; if (callparam) { m_pEntity->m_fsm.m_CallingParam.connect_ip = callparam->strConnectIp ; m_pEntity->m_fsm.m_CallingParam.connect_port = callparam->nSipPort; m_pEntity->m_fsm.m_CallingParam.nCallType = (CallingTypeEnum)callparam->nCallType; m_pEntity->m_fsm.m_CallingParam.connect_session = callparam->strConnectSession; m_pEntity->m_fsm.m_CallingParam.subid = callparam->strSubid; m_pEntity->m_fsm.m_CallingParam.assistant_port = callparam->nAsisstPort; Dbg("Handle_StartCallExternal strConnectIp=%s, nSipPort=%d, nCallType=%d, strConnectSession=%s, strSubid=%s, nAsisstPort=%d", callparam->strConnectIp, callparam->nSipPort, callparam->nCallType, callparam->strConnectSession, callparam->strSubid, callparam->nAsisstPort); } else { Dbg("Get RVCCallingParam Failed!\n"); } m_pEntity->m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_COMMAND_CALL)); ctx->Answer((ErrorCodeEnum)rc); } void CCounterConnectorSession::Handle_StopCall(SpReqAnsContext::Pointer ctx) { LOG_FUNCTION(); ErrorCodeEnum rc = Error_Succeed; RVCCallingParam* callparam = (RVCCallingParam*)ctx->Req.SessionParam.m_pData; if (callparam){ m_pEntity->m_fsm.m_SessionParam.connect_ip = callparam->strConnectIp ; m_pEntity->m_fsm.m_SessionParam.connect_session = callparam->strConnectSession; m_pEntity->m_fsm.m_SessionParam.event_port = callparam->nInstructPort; Dbg("Handle_StopCall strConnectIp=%s, strConnectSession=%s,event_port=%d", m_pEntity->m_fsm.m_SessionParam.connect_ip.GetData(), m_pEntity->m_fsm.m_SessionParam.connect_session.GetData(), m_pEntity->m_fsm.m_SessionParam.event_port); } else { Dbg("Get SessionParam Failed!\n"); } Dbg("holder hangup call!"); m_pEntity->m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANGUP)); ctx->Answer((ErrorCodeEnum)rc); } void CCounterConnectorSession::OnClose( ErrorCodeEnum eErrorCode ) { LOG_FUNCTION(); } SP_BEGIN_ENTITY_MAP() SP_ENTITY(CCounterConnectorEntity) SP_END_ENTITY_MAP()