mod_initiativetransfer.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. #include "EventCode.h"
  7. using namespace InitiativeTransfer;
  8. #ifndef RVC_CONNECT_ASSIST_ID
  9. #define RVC_CONNECT_ASSIST_ID 1
  10. #endif
  11. #define LOG_EVT_ENTER_ACM_FLOW 0x30500001 //进入坐席控制流程
  12. #define LOG_EVT_UI_RETURNMENU 0x30B00006 //退出到主菜单
  13. #define LOG_EVT_UI_EXIT_BACKRUN 0x30B00016 //前端主动退出后端模式
  14. class CFlowControlEntity;
  15. class FlowControlServiceSession : public FlowService_ServerSessionBase
  16. {
  17. public:
  18. FlowControlServiceSession(CFlowControlEntity *pEntity) : m_pEntity(pEntity) {}
  19. virtual void Handle_SwitchToAgentFlow(SpOnewayCallContext<FlowService_SwitchToAgentFlow_Info>::Pointer ctx);
  20. virtual void Handle_DisallowControl(SpOnewayCallContext<FlowService_DisallowControl_Info>::Pointer ctx);
  21. virtual void Handle_ReturnAgent(SpOnewayCallContext<FlowService_ReturnAgent_Info>::Pointer ctx);
  22. virtual void Handle_SwitchToFrontFlow(SpOnewayCallContext<FlowService_SwitchToFrontFlow_Info>::Pointer ctx);
  23. private:
  24. CFlowControlEntity *m_pEntity;
  25. };
  26. class CFlowControlEntity : public CEntityBase, public ILogListener, public ITimerListener
  27. {
  28. public:
  29. CFlowControlEntity() { }
  30. virtual ~CFlowControlEntity() {}
  31. virtual const char *GetEntityName() const { return "InitiativeTransfer"; }
  32. virtual bool IsService()const{return true;}
  33. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  34. {
  35. //MessageBoxA(0, 0, 0, 0);
  36. m_bIsPadType = FALSE;
  37. m_fsm = new CFlowControlFSM();
  38. ErrorCodeEnum Error = m_fsm->Init(this);
  39. int i = 0;
  40. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  41. m_arrListener.Init(3);
  42. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS,NULL,false);
  43. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU,NULL,false);
  44. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_EXIT_BACKRUN,NULL,false);
  45. //is Pad Version
  46. CSystemStaticInfo stStaticinfo;
  47. spFunction->GetSystemStaticInfo(stStaticinfo);
  48. if (stricmp(stStaticinfo.strMachineType,"RVC.PAD")==0){
  49. m_bIsPadType = TRUE;
  50. m_fsm->m_bIspad = TRUE;
  51. }
  52. else{
  53. m_bIsPadType = FALSE;
  54. m_fsm->m_bIspad = FALSE;
  55. }
  56. pTransactionContext->SendAnswer(Error);
  57. }
  58. void OnStarted()
  59. {
  60. if (Error_Succeed == m_fsm->ConnectToAssistchan(false)){
  61. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnStarted ConnectionAssistchan success!");
  62. m_fsm->m_bConnectAssit = true;
  63. }
  64. else{
  65. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnStarted ConnectionAssistchan failed, SetTimer.");
  66. GetFunction()->SetTimer(RVC_CONNECT_ASSIST_ID, this, 5000);
  67. }
  68. }
  69. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  70. {
  71. m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_EXIT));
  72. m_pTransactionContext = pTransactionContext; // save for later use
  73. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  74. for (int i = 0; i < m_arrListener.GetCount(); ++i)
  75. {
  76. spFunction->UnsubscribeLog(m_arrListener[i]);
  77. }
  78. m_arrListener.Clear();
  79. }
  80. CSmartPointer<ITransactionContext> m_pTransactionContext;
  81. void FinishClose(ErrorCodeEnum Error)
  82. {
  83. if (m_pTransactionContext != NULL)
  84. {
  85. m_pTransactionContext->SendAnswer(Error);
  86. }
  87. }
  88. virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  89. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  90. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext &pLinkInfo)
  91. {
  92. if (dwUserCode == LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS)
  93. {
  94. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recv LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS");
  95. GetFunction()->SetTimer(RVC_CONNECT_ASSIST_ID, this, 5000);
  96. m_fsm->m_bConnectAssit = false;
  97. Sleep(1000);
  98. m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_ASSIS_IDEL));
  99. }
  100. else if (dwUserCode == LOG_EVT_UI_RETURNMENU)
  101. {
  102. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("return main menu");
  103. m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_MENU_RETURN));
  104. }
  105. else if (dwUserCode == LOG_EVT_UI_EXIT_BACKRUN)
  106. {
  107. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ui exit back run");
  108. m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_EXIT_BACKRUN));
  109. }
  110. }
  111. virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/)
  112. {
  113. return new FlowControlServiceSession(this);
  114. }
  115. virtual void OnTimeout(DWORD dwTimerID)
  116. {
  117. if (RVC_CONNECT_ASSIST_ID == dwTimerID) {
  118. if (false == m_fsm->m_bConnectAssit) {
  119. if (Error_Succeed == m_fsm->ConnectToAssistchan(false)) {
  120. m_fsm->m_bConnectAssit = true;
  121. }
  122. }
  123. if (m_fsm->m_bConnectAssit) {
  124. GetFunction()->KillTimer(RVC_CONNECT_ASSIST_ID);
  125. }
  126. }
  127. }
  128. void SwitchToAgentFlow(CSimpleStringW req_context)
  129. {
  130. ReqAgentFlowEvent *e = new ReqAgentFlowEvent();
  131. e->req_context = req_context;
  132. e->m_pEntityBase = this;
  133. m_fsm->PostEventFIFO(e);
  134. if (m_bIsPadType)
  135. {
  136. //only pad version use
  137. LogEvent(Severity_Middle,LOG_EVT_ENTER_ACM_FLOW,"enter acm flow");
  138. }
  139. }
  140. void DisallowControl()
  141. {
  142. m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_DISCTRL));
  143. }
  144. void SwitchToFrontFlow()
  145. {
  146. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recv handle SwitchToFrontFlow function.");
  147. m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_EXIT_BACKRUN));
  148. }
  149. void ReturnAgent(CSimpleStringW ans_ctx)
  150. {
  151. AnsACMFlowEvent *e = new AnsACMFlowEvent();
  152. e->ans_context = ans_ctx;
  153. m_fsm->PostEventFIFO(e);
  154. }
  155. public:
  156. BOOL m_bIsPadType;
  157. private:
  158. CFlowControlFSM *m_fsm;
  159. CAutoArray<CUUID> m_arrListener;
  160. };
  161. void FlowControlServiceSession::Handle_SwitchToAgentFlow( SpOnewayCallContext<FlowService_SwitchToAgentFlow_Info>::Pointer ctx )
  162. {
  163. DbgToBeidou(ctx->link, __FUNCTION__)();
  164. m_pEntity->SwitchToAgentFlow(ctx->Info.req_context);
  165. }
  166. void FlowControlServiceSession::Handle_DisallowControl( SpOnewayCallContext<FlowService_DisallowControl_Info>::Pointer ctx )
  167. {
  168. DbgToBeidou(ctx->link, __FUNCTION__)();
  169. m_pEntity->DisallowControl();
  170. }
  171. void FlowControlServiceSession::Handle_ReturnAgent( SpOnewayCallContext<FlowService_ReturnAgent_Info>::Pointer ctx )
  172. {
  173. DbgToBeidou(ctx->link, __FUNCTION__)();
  174. m_pEntity->ReturnAgent(ctx->Info.ans_context);
  175. }
  176. void FlowControlServiceSession::Handle_SwitchToFrontFlow(SpOnewayCallContext<FlowService_SwitchToFrontFlow_Info>::Pointer ctx)
  177. {
  178. DbgToBeidou(ctx->link, __FUNCTION__)();
  179. m_pEntity->SwitchToFrontFlow();
  180. }
  181. void FinishClose(CEntityBase *pEntity, ErrorCodeEnum Error = Error_Succeed)
  182. {
  183. if (pEntity) {
  184. CFlowControlEntity *pFlowControlEntity = static_cast<CFlowControlEntity *>(pEntity);
  185. pFlowControlEntity->FinishClose(Error);
  186. }
  187. }
  188. SP_BEGIN_ENTITY_MAP()
  189. SP_ENTITY(CFlowControlEntity)
  190. SP_END_ENTITY_MAP()