mod_initiativetransfer.cpp 6.6 KB

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