#include "stdafx.h" #include "SpBase.h" #include "FlowControlFSM.h" #include "InitiativeTransfer_server_g.h" #include "InitiativeTransfer_msg_g.h" using namespace InitiativeTransfer; #define LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE 0x50500001 //协助通道重启 #define LOG_EVT_ENTER_ACM_FLOW 0x30500001 //进入坐席控制流程 #define LOG_EVT_UI_RETURNMENU 0x30B00006 //退出到主菜单 class CFlowControlEntity; class FlowControlServiceSession : public FlowService_ServerSessionBase { public: FlowControlServiceSession(CFlowControlEntity *pEntity) : m_pEntity(pEntity) {} virtual void Handle_SwitchToAgentFlow(SpOnewayCallContext::Pointer ctx); virtual void Handle_DisallowControl(SpOnewayCallContext::Pointer ctx); virtual void Handle_ReturnAgent(SpOnewayCallContext::Pointer ctx); private: CFlowControlEntity *m_pEntity; }; class CFlowControlEntity : public CEntityBase, public ILogListener { public: CFlowControlEntity() {} virtual ~CFlowControlEntity() {} virtual const char *GetEntityName() const { return "InitiativeTransfer"; } virtual bool IsService()const{return true;} virtual void OnPreStart(CAutoArray strArgs,CSmartPointer pTransactionContext) { //MessageBoxA(0, 0, 0, 0); m_bIsPadType = FALSE; m_fsm = new CFlowControlFSM(); ErrorCodeEnum Error = m_fsm->Init(this); int i = 0; CSmartPointer spFunction = GetFunction(); m_arrListener.Init(2); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE,NULL,false); spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU,NULL,false); //is Pad Version CSystemStaticInfo stStaticinfo; spFunction->GetSystemStaticInfo(stStaticinfo); if (stricmp(stStaticinfo.strMachineType,"RVC.PAD")==0) { m_bIsPadType = TRUE; m_fsm->m_bIspad = TRUE; } else { m_bIsPadType = FALSE; m_fsm->m_bIspad = FALSE; } pTransactionContext->SendAnswer(Error); } virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer pTransactionContext) { m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_EXIT)); m_pTransactionContext = pTransactionContext; // save for later use CSmartPointer spFunction = GetFunction(); for (int i = 0; i < m_arrListener.GetCount(); ++i) { spFunction->UnsubscribeLog(m_arrListener[i]); } m_arrListener.Clear(); } CSmartPointer m_pTransactionContext; void FinishClose(ErrorCodeEnum Error) { if (m_pTransactionContext != NULL) { m_pTransactionContext->SendAnswer(Error); } } virtual void 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) { if (dwUserCode == LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE) { Dbg("recv LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE"); m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_ASSIS_IDEL)); } else if (dwUserCode == LOG_EVT_UI_RETURNMENU) { Dbg("return main menu"); m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_MENU_RETURN)); } } virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/) { LOG_FUNCTION(); return new FlowControlServiceSession(this); } void SwitchToAgentFlow(CSimpleStringW req_context) { CSimpleStringA str_req = CSimpleStringW2A(req_context); Dbg("SwitchToAgentFlow, req_context:%s", str_req.GetData()); ReqAgentFlowEvent *e = new ReqAgentFlowEvent(); e->req_context = req_context; e->m_pEntityBase = this; m_fsm->PostEventFIFO(e); if (m_bIsPadType) { //only pad vervison use LogEvent(Severity_Middle,LOG_EVT_ENTER_ACM_FLOW,"enter acm flow"); } } void DisallowControl() { m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_DISCTRL)); } void ReturnAgent(CSimpleStringW ans_ctx) { AnsACMFlowEvent *e = new AnsACMFlowEvent(); e->ans_context = ans_ctx; m_fsm->PostEventFIFO(e); } public: BOOL m_bIsPadType; private: CFlowControlFSM *m_fsm; CAutoArray m_arrListener; }; void FlowControlServiceSession::Handle_SwitchToAgentFlow( SpOnewayCallContext::Pointer ctx ) { LOG_FUNCTION(); m_pEntity->SwitchToAgentFlow(ctx->Info.req_context); } void FlowControlServiceSession::Handle_DisallowControl( SpOnewayCallContext::Pointer ctx ) { LOG_FUNCTION(); m_pEntity->DisallowControl(); } void FlowControlServiceSession::Handle_ReturnAgent( SpOnewayCallContext::Pointer ctx ) { LOG_FUNCTION(); m_pEntity->ReturnAgent(ctx->Info.ans_context); } void FinishClose(CEntityBase *pEntity, ErrorCodeEnum Error = Error_Succeed) { if (pEntity) { CFlowControlEntity *pFlowControlEntity = static_cast(pEntity); pFlowControlEntity->FinishClose(Error); } } SP_BEGIN_ENTITY_MAP() SP_ENTITY(CFlowControlEntity) SP_END_ENTITY_MAP()