123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903 |
- /////////////////////////////////
- ///// 连线服务
- /////////////////////////////////
- #include "stdafx.h"
- #include "ListEntry.h"
- #include "Event.h"
- #include "mod_counterconnector.h"
- #include "CounterConnector_msg_g.h"
- #include "../include/EventCode.h"
- #include "y2k_time.h"
- using namespace CounterConnector;
- #define EVT_CONVERTER "EventConverter"
- void CCounterConnectorEntity ::OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum Error = __OnStart(Error_Succeed);
- CSmartPointer<IEntityFunction> 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<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum Error = __OnClose(Error_Succeed);
- pTransactionContext->SendAnswer(Error);
- }
- void CCounterConnectorEntity ::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> 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<IEntityFunction> 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) {
- LogError(Severity_Middle, Error_Hardware, EVENT_MOD_CONNECT_ASSIST_ERROR, "connect assistant channel error");
- m_pCounterConnectorChannel->SafeDelete();
- 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 = 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 = 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 = 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 = 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<IEntityFunction> 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<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
- const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
- const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage)
- {
- LOG_TRACE("user_code = 0x%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.GetData());
- }
- 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.GetData());
- }
- 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) {
- LogWarn(Severity_Middle, Error_Unexpect, EVENT_MOD_CONNECT_SLV_PICKUPCALL_HAS_CMD, pszMessage);
- }
- 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.GetData());
- 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 = 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 = 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 = 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 = 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<CSimpleStringA> 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)
- {
- m_eLastState = eChannelState_Idle;
- m_uConnectTime = 0;
- }
- void ChannelCounterConnectorClient::OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData)
- {
- if (Error == Error_Succeed)
- {
- CCounterConnectorEntity *pEntity = static_cast<CCounterConnectorEntity*>(m_pEntityBase);
- if (Msg.state == eChannelState_Idle)
- {
- pEntity->m_fsm.m_bIsAgentControl = FALSE;
- Dbg("ChannelState is eChannelState_Idle");
- if (eChannelState_Connected == m_eLastState){
- char strmsg[MAX_PATH] = {0};
- _snprintf(strmsg, MAX_PATH, "call connected time is %us.", y2k_time_now() - m_uConnectTime);
- LogWarn(Severity_Middle, Error_Debug, LOG_WARN_COUNTERCONNECT_CALL_CONNECT_TIME, strmsg);
- }
- if (eChannelState_Connecting == m_eLastState){
- LogWarn(Severity_Middle, Error_Debug, LOG_WARN_COUNTERCONNECT_ASSIST_CONNECT_FAILED,"make call failed for assistant channel connect failed!");
- }
- }
- else if (Msg.state == eChannelState_Connected)
- {
- pEntity->m_fsm.m_bIsAgentControl = TRUE;
- pEntity->SendCurAudioDevice();
- Dbg("ChannelState is eChannelState_Connected");
- m_uConnectTime = y2k_time_now();
- }
- else if (eChannelState_Connecting == Msg.state){
- Dbg("ChannelState is eChannelState_Connecting");
- }
- else if(eChannelState_Closing == Msg.state){
- Dbg("ChannelState is eChannelState_Closing");
- if (eChannelState_Connecting == m_eLastState){
- LogWarn(Severity_Middle, Error_Debug, LOG_WARN_COUNTERCONNECT_ASSIST_CONNECT_FAILED,"make call failed for assistant channel closed.");
- }
- }
- m_eLastState = Msg.state;
- }
- }
- void ChannelCounterConnectorClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData )
- {
- LOG_FUNCTION();
- if (Error == Error_Succeed)
- {
- CCounterConnectorEntity *pEntity = static_cast<CCounterConnectorEntity*>(m_pEntityBase);
- pEntity->OnReceivePkt(Msg.type, Msg.sub_type, (const char*)Msg.data.m_pData, Msg.data.m_iLength);
- }
- }
- void CCounterConnectorSession::Handle_StartCall(SpReqAnsContext<ConnectService_StartCall_Req, ConnectService_StartCall_Ans>::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<ConnectService_StartCallExternal_Req, ConnectService_StartCallExternal_Ans>::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<ConnectService_StopCall_Req, ConnectService_StopCall_Ans>::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()
|