mod_initiativetransfer.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #include "stdafx.h"
  2. #include "SpBase.h"
  3. #include "FlowControlFSM.h"
  4. #include "InitiativeTransfer_server_g.h"
  5. #include "InitiativeTransfer_msg_g.h"
  6. using namespace InitiativeTransfer;
  7. #define LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE 0x50500001 //协助通道重启
  8. #define LOG_EVT_ENTER_ACM_FLOW 0x30500001 //进入坐席控制流程
  9. #define LOG_EVT_UI_RETURNMENU 0x30B00006 //退出到主菜单
  10. class CFlowControlEntity;
  11. class FlowControlServiceSession : public FlowService_ServerSessionBase
  12. {
  13. public:
  14. FlowControlServiceSession(CFlowControlEntity *pEntity) : m_pEntity(pEntity) {}
  15. virtual void Handle_SwitchToAgentFlow(SpOnewayCallContext<FlowService_SwitchToAgentFlow_Info>::Pointer ctx);
  16. virtual void Handle_DisallowControl(SpOnewayCallContext<FlowService_DisallowControl_Info>::Pointer ctx);
  17. virtual void Handle_ReturnAgent(SpOnewayCallContext<FlowService_ReturnAgent_Info>::Pointer ctx);
  18. private:
  19. CFlowControlEntity *m_pEntity;
  20. };
  21. class CFlowControlEntity : public CEntityBase, public ILogListener
  22. {
  23. public:
  24. CFlowControlEntity() {}
  25. virtual ~CFlowControlEntity() {}
  26. virtual const char *GetEntityName() const { return "InitiativeTransfer"; }
  27. virtual bool IsService()const{return true;}
  28. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  29. {
  30. //MessageBoxA(0, 0, 0, 0);
  31. m_bIsPadType = FALSE;
  32. m_fsm = new CFlowControlFSM();
  33. ErrorCodeEnum Error = m_fsm->Init(this);
  34. int i = 0;
  35. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  36. m_arrListener.Init(2);
  37. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE,NULL,false);
  38. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU,NULL,false);
  39. //is Pad Version
  40. CSystemStaticInfo stStaticinfo;
  41. spFunction->GetSystemStaticInfo(stStaticinfo);
  42. if (stricmp(stStaticinfo.strMachineType,"RVC.PAD")==0)
  43. {
  44. m_bIsPadType = TRUE;
  45. m_fsm->m_bIspad = TRUE;
  46. }
  47. else
  48. {
  49. m_bIsPadType = FALSE;
  50. m_fsm->m_bIspad = FALSE;
  51. }
  52. pTransactionContext->SendAnswer(Error);
  53. }
  54. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  55. {
  56. m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_EXIT));
  57. m_pTransactionContext = pTransactionContext; // save for later use
  58. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  59. for (int i = 0; i < m_arrListener.GetCount(); ++i)
  60. {
  61. spFunction->UnsubscribeLog(m_arrListener[i]);
  62. }
  63. m_arrListener.Clear();
  64. }
  65. CSmartPointer<ITransactionContext> m_pTransactionContext;
  66. void FinishClose(ErrorCodeEnum Error)
  67. {
  68. if (m_pTransactionContext != NULL)
  69. {
  70. m_pTransactionContext->SendAnswer(Error);
  71. }
  72. }
  73. virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  74. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  75. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage)
  76. {
  77. if (dwUserCode == LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE)
  78. {
  79. Dbg("recv LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE");
  80. m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_ASSIS_IDEL));
  81. }
  82. else if (dwUserCode == LOG_EVT_UI_RETURNMENU)
  83. {
  84. Dbg("return main menu");
  85. m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_MENU_RETURN));
  86. }
  87. }
  88. virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/)
  89. {
  90. LOG_FUNCTION();
  91. return new FlowControlServiceSession(this);
  92. }
  93. void SwitchToAgentFlow(CSimpleStringW req_context)
  94. {
  95. ReqAgentFlowEvent *e = new ReqAgentFlowEvent();
  96. e->req_context = req_context;
  97. e->m_pEntityBase = this;
  98. m_fsm->PostEventFIFO(e);
  99. if (m_bIsPadType)
  100. {
  101. //only pad vervison use
  102. LogEvent(Severity_Middle,LOG_EVT_ENTER_ACM_FLOW,"enter acm flow");
  103. }
  104. }
  105. void DisallowControl()
  106. {
  107. m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_DISCTRL));
  108. }
  109. void ReturnAgent(CSimpleStringW ans_ctx)
  110. {
  111. AnsACMFlowEvent *e = new AnsACMFlowEvent();
  112. e->ans_context = ans_ctx;
  113. m_fsm->PostEventFIFO(e);
  114. }
  115. public:
  116. BOOL m_bIsPadType;
  117. private:
  118. CFlowControlFSM *m_fsm;
  119. CAutoArray<CUUID> m_arrListener;
  120. };
  121. void FlowControlServiceSession::Handle_SwitchToAgentFlow( SpOnewayCallContext<FlowService_SwitchToAgentFlow_Info>::Pointer ctx )
  122. {
  123. LOG_FUNCTION();
  124. m_pEntity->SwitchToAgentFlow(ctx->Info.req_context);
  125. }
  126. void FlowControlServiceSession::Handle_DisallowControl( SpOnewayCallContext<FlowService_DisallowControl_Info>::Pointer ctx )
  127. {
  128. LOG_FUNCTION();
  129. m_pEntity->DisallowControl();
  130. }
  131. void FlowControlServiceSession::Handle_ReturnAgent( SpOnewayCallContext<FlowService_ReturnAgent_Info>::Pointer ctx )
  132. {
  133. LOG_FUNCTION();
  134. m_pEntity->ReturnAgent(ctx->Info.ans_context);
  135. }
  136. void FinishClose(CEntityBase *pEntity, ErrorCodeEnum Error = Error_Succeed)
  137. {
  138. if (pEntity) {
  139. CFlowControlEntity *pFlowControlEntity = static_cast<CFlowControlEntity *>(pEntity);
  140. pFlowControlEntity->FinishClose(Error);
  141. }
  142. }
  143. SP_BEGIN_ENTITY_MAP()
  144. SP_ENTITY(CFlowControlEntity)
  145. SP_END_ENTITY_MAP()