123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863 |
- #pragma once
- #include "SpHelper.h"
- #include "SpFSM.h"
- #include "SpIni.h"
- #include "Event.h"
- #ifdef _WIN32
- #include "resource.h"
- #else
- #endif
- #include "../mod_assistantchannel/VideoDesc.h"
- #include "../mod_sipphone/SIPPhone_client_g.h"
- using namespace SIPPhone;
- #include "../mod_assistantchannel/AssistantChannel_client_g.h"
- using namespace AssistantChannel;
- #include "../mod_mediacontroller/MediaController_client_g.h"
- using namespace MediaController;
- #include "../mod_assistantchannel/chan_protocol.h"
- #include "CallType.h"
- #include "CounterConnector_def_g.h"
- #include "CounterConnector_msg_g.h"
- using namespace CounterConnector;
- #include "../mod_interactioncontext/InteractionContext_client_g.h"
- #include "../mod_interactioncontext/InteractionContext_def_g.h"
- using namespace InteractionContext;
- #include "../mod_livenessdetection/LivenessDetection_client_g.h"
- #include "../mod_livenessdetection/LivenessDetection_msg_g.h"
- using namespace LivenessDetection;
- #define USER_EVT_PICKUP_CALL EVT_USER+1
- #define USER_EVT_HANDFREE_CALL EVT_USER+2
- #define USER_EVT_HANGUP EVT_USER+3
- #define USER_EVT_COMMAND_CALL EVT_USER+4
- #define USER_EVT_DOUBLE_RECORD_CALL EVT_USER+5
- #define USER_EVT_JMP_FAIL EVT_USER+11
- #define USER_EVT_JMP_HANDFREE EVT_USER+12
- #define USER_EVT_JMP_PICKUP EVT_USER+13
- #define USER_EVT_TO_HANDFREE EVT_USER+14
- #define USER_EVT_TO_PICKUP EVT_USER+15
- #define USER_EVT_SIP_STATE_CONNECTED EVT_USER+21
- #define USER_EVT_SIP_STATE_IDLE EVT_USER+22
- #define USER_EVT_CHAN_STATE_CONNECTED EVT_USER+31
- #define USER_EVT_CHAN_STATE_IDLE EVT_USER+33
- #define USER_EVT_RECONNECT EVT_USER+40
- #define USER_EVT_AGENT_WRITABLE EVT_USER+41
- #define USER_EVT_ERROR EVT_USER+10
- #define USER_EVT_EXIT EVT_USER+50
- #define USER_EVT_STOP_RECORD_BROADCAST EVT_USER+55
- #define USER_EVT_ASSISTCHAN_IDEL EVT_USER+60
- #define USER_EVT_SIPPHONE_IDEL EVT_USER+61
- #define USER_EVT_STARTVIDEODISPLAY EVT_USER+70
- #define USER_EVT_STOPVIDEODISPLAY EVT_USER+71
- #define USER_EVT_SHOWLOACALVIDEO EVT_USER+72
- #define USER_EVT_STOPLOCALVIDEO EVT_USER+73
- #define USER_EVT_SHOWLOACALREMOTEVIDEO EVT_USER+74
- #define USER_EVT_STOPLOACALREMOTEVIDEO EVT_USER+75
- enum CurServerNum
- {
- Error_Server = -1,
- MAIN_SERVER = 0,
- BACK_SERVER = 1,
- };
- struct ChanStateConnectedEvent : public FSMEvent
- {
- ChanStateConnectedEvent(const char *param) : FSMEvent(USER_EVT_CHAN_STATE_CONNECTED), m_param(param) {}
- CSimpleStringA m_param;
- };
- struct StartVideoDisplayEvent : public FSMEvent
- {
- StartVideoDisplayEvent(const char *param) : FSMEvent(USER_EVT_STARTVIDEODISPLAY), m_param(param) {}
- CSimpleStringA m_param;
- };
- struct ShowLocalVideoEvent : public FSMEvent
- {
- ShowLocalVideoEvent(const char *param) : FSMEvent(USER_EVT_SHOWLOACALVIDEO), m_param(param) {}
- CSimpleStringA m_param;
- };
- struct ShowLocalAndRemoteVideoEvent : public FSMEvent
- {
- ShowLocalAndRemoteVideoEvent(const char *param) : FSMEvent(USER_EVT_SHOWLOACALREMOTEVIDEO), m_param(param) {}
- CSimpleStringA m_param;
- };
- struct CallingParam
- {
- //呼叫模式,0:可视柜台正常呼叫,1:PAD主动外呼,2:PAD被动呼叫,来源PAD,3:PAD被动呼叫,来源手机端,4:双录连线
- CallingTypeEnum nCallType;
- //<!--会场ession,用于手机与PAD,或者pad与pad交互的会场号-->
- CSimpleStringA connect_session;
- CSimpleStringA connect_ip;
- int connect_port;
- CSimpleStringA subid;
- int assistant_port;
- };
- //<!--会话相关参数,用于主动拒接的场景 -->
- struct SessionParam
- {
- CSimpleStringA connect_session; //会话标识
- CSimpleStringA connect_ip; //分行网关服务器ip
- int event_port; //分行网关挂断事件监听端口
- };
- #ifndef MAX_LENGTH_OF_BRANCHNO
- #define MAX_LENGTH_OF_BRANCHNO 4
- #endif
- #ifndef MAX_LENGTH_OF_SESSIONID
- #define MAX_LENGTH_OF_SESSIONID 16
- #endif
- #ifndef MAX_LENGTH_OF_CONNECTIP
- #define MAX_LENGTH_OF_CONNECTIP 16
- #endif
- #ifndef MAX_LENGTH_OF_SUBID
- #define MAX_LENGTH_OF_SUBID 16
- #endif
- #ifndef SUBID_LENGTH
- #define SUBID_LENGTH 8
- #endif
- //被动呼叫模式参数
- struct RVCCallingParam
- {
- //呼叫模式,0:可视柜台正常呼叫,1:PAD主动外呼,2:PAD被动呼叫,来源PAD,3:PAD被动呼叫,来源手机端
- int nCallType;
- //分行编号
- char strBranNo[MAX_LENGTH_OF_BRANCHNO];
- //会话标识16位
- char strConnectSession[MAX_LENGTH_OF_SESSIONID];
- //连接IP 16位
- char strConnectIp[MAX_LENGTH_OF_CONNECTIP];
- //SIP端口
- int nSipPort;
- //协助通道端口
- int nAsisstPort;
- //客户经理subid
- char strSubid[MAX_LENGTH_OF_SUBID];
- //分行网关指令服务端口
- int nInstructPort;
- };
- class ACMCallFSM : public FSMImpl<ACMCallFSM>, public IFSMStateHooker
- {
- public:
- enum {s0,s7,s8,s9,s10,s11,s12,s13,s14,s20,s21,s22,s23,s24,s3,s4,s50,s51,s52,s53,s60,s61,s62,s63};
- BEGIN_FSM_STATE(ACMCallFSM)
- FSM_STATE_ENTRY(s0,"Offline",s0_on_entry,s0_on_exit,s0_on_event)
- FSM_STATE_ENTRY(s7,"ShowLocalVideo",s7_on_entry,s7_on_exit,s7_on_event)
- FSM_STATE_ENTRY(s9,"Livedetect",s9_on_entry,s9_on_exit,s9_on_event)
- FSM_STATE_ENTRY(s8,"Delay",s8_on_entry,s8_on_exit,s8_on_event)
- FSM_STATE_ENTRY(s10,"Calling_Start",s10_on_entry,s10_on_exit,s10_on_event)
- FSM_STATE_ENTRY(s11,"Calling_SipConnect",s11_on_entry,s11_on_exit,s11_on_event)
- FSM_STATE_ENTRY(s12,"Calling_ChanConnect",s12_on_entry,s12_on_exit,s12_on_event)
- FSM_STATE_ENTRY(s13,"Calling_AllReady",s13_on_entry,s13_on_exit,s13_on_event)
- FSM_STATE_ENTRY(s14,"ShowLocalRemoteVideo",s14_on_entry,s14_on_exit,s14_on_event)
- FSM_STATE_ENTRY(s20, "ExitCall_Start",s20_on_entry,s20_on_exit,s20_on_event)
- FSM_STATE_ENTRY(s21, "ExitChan_Finished",s21_on_entry,s21_on_exit,s21_on_event)
- FSM_STATE_ENTRY(s22, "ExitSip_Finished",s22_on_entry,s22_on_exit,s22_on_event)
- FSM_STATE_ENTRY(s23, "ExitCall_AllFinished",s23_on_entry,s23_on_exit,s23_on_event)
- FSM_STATE_ENTRY(s24, "ExitCall_Delay",s24_on_entry,s24_on_exit,s24_on_event)
- FSM_STATE_ENTRY(s3, "HandFree",s3_on_entry,s3_on_exit,s3_on_event)
- FSM_STATE_ENTRY(s4, "Pickup",s4_on_entry,s4_on_exit,s4_on_event)
- FSM_STATE_ENTRY(s50, "Broken0",s50_on_entry,s50_on_exit,s50_on_event)
- FSM_STATE_ENTRY(s51, "Broken_SipFinished",s51_on_entry,s51_on_exit,s51_on_event)
- FSM_STATE_ENTRY(s52, "Broken_ChanFinished",s52_on_entry,s52_on_exit,s52_on_event)
- FSM_STATE_ENTRY(s53, "Broken_AllFinished",s53_on_entry,s53_on_exit,s53_on_event)
- FSM_STATE_ENTRY(s60, "Hangup_Start",s60_on_entry,s60_on_exit,s60_on_event)
- FSM_STATE_ENTRY(s61, "Hangup_SipFinished",s61_on_entry,s61_on_exit,s61_on_event)
- FSM_STATE_ENTRY(s62, "Hangup_ChanFinished",s62_on_entry,s62_on_exit,s62_on_event)
- FSM_STATE_ENTRY(s63, "Hangup_AllFinished",s63_on_entry,s63_on_exit,s63_on_event)
- END_FSM_STATE()
- BEGIN_FSM_RULE(ACMCallFSM,s0)
- FSM_RULE_ENTRY_ANY(s0, s8, USER_EVT_PICKUP_CALL)
- FSM_RULE_ENTRY_ANY(s0, s9, USER_EVT_STARTVIDEODISPLAY)
- FSM_RULE_ENTRY_ANY(s0, s7, USER_EVT_SHOWLOACALVIDEO)
- FSM_RULE_ENTRY_ANY(s0, s14, USER_EVT_SHOWLOACALREMOTEVIDEO)
- FSM_RULE_ENTRY_ANY(s7, s0, USER_EVT_STOPLOCALVIDEO)
- FSM_RULE_ENTRY_ANY(s9, s0, USER_EVT_STOPVIDEODISPLAY)
- FSM_RULE_ENTRY_ANY(s14, s0, USER_EVT_STOPLOACALREMOTEVIDEO)
- FSM_RULE_ENTRY_ANY(s0, FSM_STATE_EXIT, USER_EVT_EXIT)
- FSM_RULE_ENTRY_ANY(s0, s8, USER_EVT_HANDFREE_CALL)
- FSM_RULE_ENTRY_ANY(s0, s8, USER_EVT_COMMAND_CALL)
- FSM_RULE_ENTRY_ANY(s0, s8, USER_EVT_DOUBLE_RECORD_CALL)
- FSM_RULE_ENTRY_ANY(s14, s0, USER_EVT_STOP_RECORD_BROADCAST)
- FSM_RULE_ENTRY_ANY(s8, s11, EVT_TIMER)
- FSM_RULE_ENTRY_ANY(s11, s12, USER_EVT_SIP_STATE_CONNECTED)
- FSM_RULE_ENTRY_ANY(s11, s23, USER_EVT_JMP_FAIL)
- FSM_RULE_ENTRY_ANY(s11, s21, EVT_TIMER)
- FSM_RULE_ENTRY_ANY(s11, s23, USER_EVT_SIP_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s11, s21, USER_EVT_HANGUP)
- FSM_RULE_ENTRY_ANY(s21, s23, USER_EVT_SIP_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s21, s23, USER_EVT_JMP_FAIL)
- FSM_RULE_ENTRY_ANY(s12, s13, USER_EVT_CHAN_STATE_CONNECTED)
- FSM_RULE_ENTRY_ANY(s12, s21, USER_EVT_CHAN_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s12, s22, USER_EVT_SIP_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s12, s21, USER_EVT_JMP_FAIL)
- FSM_RULE_ENTRY_ANY(s22, s23, USER_EVT_CHAN_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s12, s20, USER_EVT_HANGUP)
- FSM_RULE_ENTRY_ANY(s20, s21, USER_EVT_CHAN_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s20, s22, USER_EVT_SIP_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s13, s3, USER_EVT_JMP_HANDFREE)
- FSM_RULE_ENTRY_ANY(s13, s4, USER_EVT_JMP_PICKUP)
- FSM_RULE_ENTRY_ANY(s23, s0, EVT_TIMER)
- FSM_RULE_ENTRY_ANY(s23, s24, USER_EVT_RECONNECT)
- FSM_RULE_ENTRY_ANY(s24, s11, EVT_TIMER)
- FSM_RULE_ENTRY_ANY(s3, s4, USER_EVT_TO_PICKUP)
- FSM_RULE_ENTRY_ANY(s3, s51, USER_EVT_SIP_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s3, s52, USER_EVT_CHAN_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s3, s60, USER_EVT_HANGUP)
- FSM_RULE_ENTRY_ANY(s4, s3, USER_EVT_TO_HANDFREE)
- FSM_RULE_ENTRY_ANY(s4, s51, USER_EVT_SIP_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s4, s52, USER_EVT_CHAN_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s4, s60, USER_EVT_HANGUP)
- FSM_RULE_ENTRY_ANY(s50, s51, USER_EVT_SIP_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s50, s52, USER_EVT_CHAN_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s51, s53, USER_EVT_CHAN_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s52, s53, USER_EVT_SIP_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s52, s53, USER_EVT_JMP_FAIL)
- FSM_RULE_ENTRY_ANY(s53, s0, EVT_TIMER)
- FSM_RULE_ENTRY_ANY(s60, s61, USER_EVT_SIP_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s60, s62, USER_EVT_CHAN_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s61, s63, USER_EVT_CHAN_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s62, s63, USER_EVT_SIP_STATE_IDLE)
- FSM_RULE_ENTRY_ANY(s62, s63, USER_EVT_JMP_FAIL)
- FSM_RULE_ENTRY_ANY(s63, s0, EVT_TIMER)
- //sipphone重启后,所有状态跳转到Offline
- FSM_RULE_ENTRY_ANY(s8, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s10, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s11, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s12, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s13, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s20, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s21, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s22, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s23, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s24, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s3, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s4, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s50, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s51, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s52, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s53, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s60, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s61, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s62, s0, USER_EVT_SIPPHONE_IDEL)
- FSM_RULE_ENTRY_ANY(s63, s0, USER_EVT_SIPPHONE_IDEL)
- //sipphone重启后,所有状态跳转到Offline
- //分布式呼叫场景,拒接主动挂断
- FSM_RULE_ENTRY_ANY(s0, s60, USER_EVT_HANGUP)
- //分布式呼叫场景,拒接主动挂断
- END_FSM_RULE()
- ACMCallFSM();
- ~ACMCallFSM();
- virtual void OnStateTrans(int iSrcState, int iDstState);
- virtual ErrorCodeEnum OnInit();
- virtual ErrorCodeEnum OnExit();
- void s0_on_entry();
- void s0_on_exit();
- unsigned int s0_on_event(FSMEvent* event);
- void s7_on_entry();
- void s7_on_exit();
- unsigned int s7_on_event(FSMEvent* event);
- void s8_on_entry();
- void s8_on_exit();
- unsigned int s8_on_event(FSMEvent* event);
- void s9_on_entry();
- void s9_on_exit();
- unsigned int s9_on_event(FSMEvent* event);
- void s10_on_entry();
- void s10_on_exit();
- unsigned int s10_on_event(FSMEvent* event);
- void s11_on_entry();
- void s11_on_exit();
- unsigned int s11_on_event(FSMEvent* event);
- void s12_on_entry();
- void s12_on_exit();
- unsigned int s12_on_event(FSMEvent* event);
- void s13_on_entry();
- void s13_on_exit();
- unsigned int s13_on_event(FSMEvent* event);
- void s14_on_entry();
- void s14_on_exit();
- unsigned int s14_on_event(FSMEvent* event);
-
- void s20_on_entry();
- void s20_on_exit();
- unsigned int s20_on_event(FSMEvent* event);
- void s21_on_entry();
- void s21_on_exit();
- unsigned int s21_on_event(FSMEvent* event);
- void s22_on_entry();
- void s22_on_exit();
- unsigned int s22_on_event(FSMEvent* event);
- void s23_on_entry();
- void s23_on_exit();
- unsigned int s23_on_event(FSMEvent* event);
- void s24_on_entry();
- void s24_on_exit();
- unsigned int s24_on_event(FSMEvent* event);
- void s3_on_entry();
- void s3_on_exit();
- unsigned int s3_on_event(FSMEvent* event);
- void s4_on_entry();
- void s4_on_exit();
- unsigned int s4_on_event(FSMEvent* event);
- void s50_on_entry();
- void s50_on_exit();
- unsigned int s50_on_event(FSMEvent* event);
- void s51_on_entry();
- void s51_on_exit();
- unsigned int s51_on_event(FSMEvent* event);
- void s52_on_entry();
- void s52_on_exit();
- unsigned int s52_on_event(FSMEvent* event);
- void s53_on_entry();
- void s53_on_exit();
- unsigned int s53_on_event(FSMEvent* event);
- void s60_on_entry();
- void s60_on_exit();
- unsigned int s60_on_event(FSMEvent* event);
- void s61_on_entry();
- void s61_on_exit();
- unsigned int s61_on_event(FSMEvent* event);
- void s62_on_entry();
- void s62_on_exit();
- unsigned int s62_on_event(FSMEvent* event);
- void s63_on_entry();
- void s63_on_exit();
- unsigned int s63_on_event(FSMEvent* event);
- BOOL m_bHangup;
- //sip呼叫失败次数,连续10次SIP呼叫失败触发自检重启SIPPHONE
- unsigned int m_nSipErrorNum;
- unsigned int m_nLiveDetctionTime;
- ErrorCodeEnum StartVideo(const char *param)
- {
- Dbg("Start Video");
- if (!m_pPhoneClient)
- return Error_NetBroken;
- PhoneService_StartVideo_Info Info;
- ErrorCodeEnum Error = ParseVideoDesc(param, Info.remote_ip, Info.remote_port,
- Info.remote_width, Info.remote_height, Info.remote_fps,
- Info.local_view_x, Info.local_view_y, Info.local_view_cx, Info.local_view_cy,
- Info.remote_view_x, Info.remote_view_y, Info.remote_view_cx, Info.remote_view_cy);
- Info.local_hwd_move = 0;
- Info.remote_hwd_move = 1;
- Dbg("start video, remote width:%d, remote height:%d, local(%d,%d,%d,%d),remote(%d,%d,%d,%d), remote_fps:%d",
- Info.remote_width, Info.remote_height,
- Info.local_view_x, Info.local_view_y, Info.local_view_cx, Info.local_view_cy,
- Info.remote_view_x, Info.remote_view_y, Info.remote_view_cx, Info.remote_view_cy,Info.remote_fps);
- if (Error == Error_Succeed)
- {
- Error = m_pPhoneClient->StartVideo(Info);
- } else {
- Dbg("parse video desc failed!");
- }
- return Error;
- }
- ErrorCodeEnum StopVideo()
- {
- Dbg("Stop Video");
- if (!m_pPhoneClient)
- return Error_NetBroken;
- return m_pPhoneClient->StopVideo();
- }
- ErrorCodeEnum RealSipErrorCheck()
- {
- Dbg("Sip connect Fail 6 times,RealSipErrorCheck!");
- if (!m_pPhoneClient)
- return Error_NetBroken;
- return m_pPhoneClient->RealErrorCheck();
- }
- ErrorCodeEnum SetCallingType(CallingTypeEnum eType)
- {
- if (!m_pPhoneClient)
- return Error_NetBroken;
- Dbg("SetCallingType = %d.", eType);
- PhoneService_SetCallingParam_Info info;
- info.CallType = eType;
- return m_pPhoneClient->SetCallingParam(info);
- }
- ErrorCodeEnum StopSpeakerAudioCapture()
- {
- ErrorCodeEnum rc = Error_NotImpl;
- MediaService_ClientBase* pMSClient = new MediaService_ClientBase(m_pEntity);
- if(pMSClient->Connect() != Error_Succeed)
- {
- pMSClient->SafeDelete();
- pMSClient = NULL;
- }
- else
- {
- Dbg("MSClient connected success!");
- rc = pMSClient->StopSpeakerRender();
- Dbg("pMSClient->StopSpeakerRender rc:0x%x",rc);
- if(rc != Error_Succeed){
- Dbg("Stop Speaker Render failed return 0x%08x", rc);
- }
- pMSClient->GetFunction()->CloseSession();
- pMSClient->SafeDelete();
- pMSClient = NULL;
- }
- return rc;
- }
- ErrorCodeEnum GetLivenessDetectionStatus()
- {
- ErrorCodeEnum rc = Error_InvalidState;
- LivenessDetectionService_ClientBase* pLDClient = new LivenessDetectionService_ClientBase(m_pEntity);
- if(pLDClient->Connect() != Error_Succeed)
- {
- pLDClient->SafeDelete();
- pLDClient = NULL;
- }
- else{
- rc = Error_Succeed;
- Dbg("connect liveness detection entity success!");
- pLDClient->GetFunction()->CloseSession();
- pLDClient->SafeDelete();
- pLDClient = NULL;
- }
- return rc;
- }
- ErrorCodeEnum StopLivenessDetection()
- {
- Dbg("stop liveness detection.");
- LogEvent(Severity_Middle,LOG_EVT_STOPLIVEDETECTNOTICEDISPLAY,"stop live detection notice display.");
- LogEvent(Severity_Middle,LOG_EVT_STOPLIVEDETECTDISPLAY,"stop live detection");
- PostEventFIFO(new FSMEvent(USER_EVT_STOPVIDEODISPLAY));
- return Error_Succeed;
- }
- private:
- int TranslateState(int innerState);
- ErrorCodeEnum SetCallState(int state);
- ErrorCodeEnum MakeCall(int nSipServer,CallingParam callingparam)
- {
- if (!m_pPhoneClient)
- return Error_NetBroken;
- CSimpleStringA strCode;
- PhoneService_MakeCall_Req Req;
- PhoneService_MakeCall_Ans Ans;
- if ((NULL != callingparam.connect_ip)&&(0 != callingparam.connect_port))
- {
- if (callingparam.nCallType == PADRINGUP_CALLTYPE)
- {
- CSimpleStringA session = "80";
- session+=callingparam.connect_session;
- Req.call_uri = MakeCallUri(session,callingparam.connect_ip,callingparam.connect_port);
- }
- else if((callingparam.nCallType == PADTOPAD_CALLTYPE)||(callingparam.nCallType == MOBILETOPAD_CALLTYPE))
- {
- CSimpleStringA session = "90";
- session+=callingparam.connect_session;
- Req.call_uri = MakeCallUri(session,callingparam.connect_ip,callingparam.connect_port);
- }
- else
- {
- Req.call_uri = MakeCallUri(callingparam.connect_session,callingparam.connect_ip,callingparam.connect_port);
- }
- }
- else
- {
- if((m_strSIPCallNum[nSipServer]=="")&&(m_strSIPProxyIP[nSipServer]=="")&&(m_iSIPProxyPort[nSipServer]==0))
- {
- return Error_Param;
- }
- else
- {
- if (callingparam.nCallType == PADRINGUP_CALLTYPE)
- {
- CSimpleStringA session = "80";
- session+=callingparam.connect_session;
- Req.call_uri = MakeCallUri(session,nSipServer);
- }
- else if((callingparam.nCallType == PADTOPAD_CALLTYPE)||(callingparam.nCallType == MOBILETOPAD_CALLTYPE))
- {
- CSimpleStringA session = "90";
- session+=callingparam.connect_session;
- Req.call_uri = MakeCallUri(session,nSipServer);
- }
- else
- {
- Req.call_uri = MakeCallUri(callingparam.connect_session,nSipServer);
- }
- }
- }
- //设置呼叫参数
- PhoneService_SetCallingParam_Info info;
- info.CallType = callingparam.nCallType;
- info.connect_session = callingparam.connect_session;
- info.connect_ip = callingparam.connect_ip;
- info.connect_port = callingparam.connect_port;
- m_pPhoneClient->SetCallingParam(info);
- Dbg("Make Distribute Call CallType = %d", info.CallType);
- ErrorCodeEnum Error = m_pPhoneClient->MakeCall(Req, Ans, 10000);
- return Error;
- }
- ErrorCodeEnum MakeCall(const char *hint_callnum,int nSipServer)
- {
- if (!m_pPhoneClient)
- return Error_NetBroken;
- if((m_strSIPCallNum[nSipServer]=="")&&(m_strSIPProxyIP[nSipServer]=="")&&(m_iSIPProxyPort[nSipServer]==0))
- {
- return Error_Param;
- }
- CSimpleStringA strCode;
- PhoneService_MakeCall_Req Req;
- PhoneService_MakeCall_Ans Ans;
- Req.call_uri = MakeCallUri(hint_callnum,nSipServer);
- PhoneService_SetCallingParam_Info info;
- info.CallType = NORMAL_CALLTYPE;
- if (DOUBLERECORD_CALLTYPE == m_CallingParam.nCallType)
- {
- info.CallType = DOUBLERECORD_CALLTYPE;
- }
- m_pPhoneClient->SetCallingParam(info);
- Dbg("before make call, call type is %d", info.CallType);
- ErrorCodeEnum Error = m_pPhoneClient->MakeCall(Req, Ans, 10000);
- return Error;
- }
- ErrorCodeEnum HangupCall()
- {
- Dbg("Hangup Call!");
- if (!m_pPhoneClient)
- return Error_NetBroken;
- PhoneService_HangupCall_Req Req;
- PhoneService_HangupCall_Ans Ans;
- if (!m_SessionParam.connect_session.IsNullOrEmpty())
- {
- Req.session_num = m_SessionParam.connect_session;
- Dbg("Hangup Call connect_session = %s", m_SessionParam.connect_session.GetData());
- }
- if (!m_SessionParam.connect_ip.IsNullOrEmpty())
- {
- Req.branch_server_ip = m_SessionParam.connect_ip;
- Dbg("Hangup Call connect_ip = %s", m_SessionParam.connect_ip.GetData());
- }
- if (m_SessionParam.event_port)
- {
- Req.branch_server_port = m_SessionParam.event_port;
- }
-
- return m_pPhoneClient->HangupCall(Req, Ans, 10000);
- }
- ErrorCodeEnum ReleaseCall(int type)
- {
- if (!m_pPhoneClient)
- return Error_NetBroken;
- PhoneService_ReleaseCall_Req Req;
- Req.type = type;
- PhoneService_ReleaseCall_Ans Ans;
- return m_pPhoneClient->ReleaseCall(Req, Ans, 10000);
- }
- ErrorCodeEnum StartChannel(int nChanServer)
- {
- if (!m_pChannelClient)
- return Error_NetBroken;
- if ((m_strChanProxyIP[nChanServer]=="")&&(m_strChanCallNum[nChanServer]=="")&&(m_iChanProxyPort[nChanServer]==0))
- {
- return Error_Param;
- }
- ChannelService_Connect_Req Req;
- ChannelService_Connect_Ans Ans;
- Req.callno = m_strChanCallNum[nChanServer];
- Req.ip = m_strChanProxyIP[nChanServer];
- Req.port = m_iChanProxyPort[nChanServer];
- return m_pChannelClient->Connect(Req, Ans, 10000);
- }
- CSimpleStringA MakeSubid(CSimpleStringA subid)
- {
- int idlen = subid.GetLength();
- if (idlen > SUBID_LENGTH)
- {
- return subid.SubString(idlen - SUBID_LENGTH, SUBID_LENGTH);
- }
- else
- {
- return subid;
- }
- }
- ErrorCodeEnum StartChannel(int nChanServer,CallingParam callparam)
- {
- if (!m_pChannelClient)
- return Error_NetBroken;
- ChannelService_Connect_Req Req;
- ChannelService_Connect_Ans Ans;
- if(NULL != callparam.connect_ip){
- if (callparam.nCallType == PADRINGUP_CALLTYPE) //如果是主叫
- {
- Req.callno = m_strChanCallNum[nChanServer];
- Req.ip =callparam.connect_ip;
- Req.port = m_iChanProxyPort[nChanServer];
- Req.etype = callparam.nCallType;
- return m_pChannelClient->Connect(Req, Ans, 10000);
- }
- else if((callparam.nCallType == PADTOPAD_CALLTYPE)||(callparam.nCallType == MOBILETOPAD_CALLTYPE)) //如果是被叫
- {
- //Req.callno = m_strChanCallNum[nChanServer];
- CSimpleStringA strsession = callparam.connect_session;
- Req.callno = strsession;
- Req.ip = callparam.connect_ip;
- Req.port = callparam.assistant_port;
- Req.etype = callparam.nCallType;
- //发起被动连接协助通道,连接proxy_b
- return m_pChannelClient->Connect(Req, Ans, 10000);
- }
- else{
- return Error_Param;
- }
- }
- else{
- if ((m_strChanProxyIP[nChanServer]=="")&&(m_strChanCallNum[nChanServer]=="")&&(m_iChanProxyPort[nChanServer]==0)){
- return Error_Param;
- }
- else{
- Req.callno = m_strChanCallNum[nChanServer];
- Req.ip = m_strChanProxyIP[nChanServer];
- Req.port = m_iChanProxyPort[nChanServer];
- Req.etype = NORMAL_CALLTYPE;
- return m_pChannelClient->Connect(Req, Ans, 10000);
- }
- }
- }
- ErrorCodeEnum StopChannel()
- {
- Dbg("stop channel");
- if (!m_pPhoneClient)
- return Error_NetBroken;
- ChannelService_Close_Req Req;
- ChannelService_Close_Ans Ans;
- return m_pChannelClient->Close(Req, Ans, 10000);
- }
- CSimpleStringA MakeCallUri(const char *callnum,const char *serverip,int serverport)
- {
- return CSimpleStringA::Format("sip:%s@%s:%d;transport=UDP",
- callnum, (LPCSTR)serverip,serverport);
- }
- CSimpleStringA MakeCallUri(const char *hint_callnum,int nServer)
- {
- if (m_iSIPProxyPort[nServer] == 5060)
- {
- return CSimpleStringA::Format("sip:%s@%s;transport=UDP",
- hint_callnum, (LPCSTR)m_strSIPProxyIP[nServer]);
- }
- else
- {
- return CSimpleStringA::Format("sip:%s@%s:%d;transport=UDP",
- hint_callnum, (LPCSTR)m_strSIPProxyIP[nServer], m_iSIPProxyPort[nServer]);
- }
- }
- ErrorCodeEnum LoadConfig()
- {
- SpIniMappingTable table;
- table.AddEntryString("CounterConnector", "sip_proxy_ip", m_strSIPProxyIP[0], NULL);
- table.AddEntryInt("CounterConnector", "sip_proxy_port", m_iSIPProxyPort[0], 0);
- table.AddEntryString("CounterConnector", "sip_default_call_no", m_strSIPCallNum[0], NULL);
- table.AddEntryString("CounterConnector", "chan_proxy_ip", m_strChanProxyIP[0], NULL);
- table.AddEntryInt("CounterConnector", "chan_proxy_port", m_iChanProxyPort[0], 0);
- table.AddEntryString("CounterConnector", "chan_default_call_no", m_strChanCallNum[0], NULL);
- table.AddEntryString("CounterConnector", "sip_proxy_ip_backup", m_strSIPProxyIP[1], NULL);
- table.AddEntryInt("CounterConnector", "sip_proxy_port_backup", m_iSIPProxyPort[1], 0);
- table.AddEntryString("CounterConnector", "sip_default_call_no_backup", m_strSIPCallNum[1], NULL);
- table.AddEntryString("CounterConnector", "chan_proxy_ip_backup", m_strChanProxyIP[1], NULL);
- table.AddEntryInt("CounterConnector", "chan_proxy_port_backup", m_iChanProxyPort[1], 0);
- table.AddEntryString("CounterConnector", "chan_default_call_no_backup", m_strChanCallNum[1], NULL);
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum Error = m_pEntity->GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
- if (Error == Error_Succeed) {
- Error = table.Load(spConfig);
- }
- return Error;
- }
- ErrorCodeEnum LoadTerminalId()
- {
- CSystemStaticInfo Info;
- ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSystemStaticInfo(Info);
- if (Error == Error_Succeed) {
- m_strTerminalId = Info.strTerminalID;
- }
- return Error;
- }
- ErrorCodeEnum AllowAgentWrite()
- {
- if (!m_pChannelClient)
- return Error_NetBroken;
- ChannelService_Send_Info Info;
- Info.compress = false;
- Info.encrypt = false;
- Info.id = 0;
- Info.sub_type = 0;
- Info.type = ACM_TYPE_MODE;
- return m_pChannelClient->Send(Info);
- }
- ErrorCodeEnum StartRing()
- {
- #ifdef _WIN32
- BOOL bRet = FALSE;// ::PlaySoundA(MAKEINTRESOURCEA(IDR_RINGOUT), ModuleBase::GetModuleBase()->GetInstance(), SND_ASYNC | SND_RESOURCE | SND_LOOP);
- if (bRet) {
- m_bRing = TRUE;
- return Error_Succeed;
- }
- else {
- Dbg("play sound failed!%d", GetLastError());
- return Error_Unexpect;
- }
- #else
- m_bRing = TRUE;
- return Error_Succeed;
- #endif
- }
- void StopRing()
- {
- #ifdef _WIN32
- if (m_bRing) {
- BOOL bRet = FALSE;
- int tries = 0;
- //do {
- // bRet = ::PlaySoundA(NULL, NULL, SND_ASYNC | SND_LOOP);
- //} while (bRet == FALSE && (Sleep(100), tries < 3));
- m_bRing = FALSE;
- }
- #else
- if (m_bRing) {
- m_bRing = FALSE;
- }
- #endif
- }
- BOOL CheckBeginRing(int iSrcState, int iDstState)
- {
- if (iSrcState == ACMCallFSM::s0 && iDstState == ACMCallFSM::s10)
- return TRUE;
- return FALSE;
- }
- BOOL CheckEndRing(int iSrcState, int iDstState)
- {
- if (m_bRing) {
- if (iSrcState == ACMCallFSM::s10 || iSrcState == ACMCallFSM::s12) {
- if (iDstState != ACMCallFSM::s10 && iDstState != ACMCallFSM::s12)
- return TRUE;
- }
- }
- return FALSE;
- }
- BOOL ReConnectionAssistchan();
- BOOL ReConnectionSipphone();
- int GetDelayTime();
- void SetDelayTime();
- public:
- BOOL m_bHandFree;
- //坐席控制话筒的当前状态
- BOOL m_bAgentHandFree;
- BOOL m_bIsAgentControl;
- //流程拨号,带技能号
- CSimpleStringA m_strHintCallNum;
- BOOL m_bAssistchanIdel;
- CurServerNum m_nCurSipServer;
- CurServerNum m_nCurChanServer;
- //呼叫类型,用于区分是分布式呼叫还是常规呼叫,由业务中台设置或者指令模块设置
- CallingParam m_CallingParam;
- SessionParam m_SessionParam;
- int m_nSysCallType;//0:普通模式,1:p2p模式
- private:
- DWORD m_nStarttime;
- PhoneService_ClientBase *m_pPhoneClient;
- ChannelService_ClientBase *m_pChannelClient;
- SyncService_ClientBase*m_pSyncServiceClient;
- CSimpleStringA m_strTerminalId;
- CSimpleStringA m_strSIPProxyIP[2];
- int m_iSIPProxyPort[2];
- CSimpleStringA m_strSIPCallNum[2];
- CSimpleStringA m_strChanProxyIP[2];
- int m_iChanProxyPort[2];
- CSimpleStringA m_strChanCallNum[2];
- BOOL m_bRing;
- };
|