mod_heartbeat.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // mod_heartbeat.cpp : Defines the exported functions for the DLL application.
  2. //
  3. #include "stdafx.h"
  4. #include "mod_heartbeat.h"
  5. void HeartBeatServerSession::Handle_Instruction(SpReqAnsContext<HeartBeatService_Instruction_Req, HeartBeatService_Instruction_Ans>::Pointer ctx)
  6. {
  7. LOG_FUNCTION();
  8. m_pEntity->Instruction(ctx);
  9. }
  10. void HeartBeatServerSession::Handle_CardActive(SpReqAnsContext<HeartBeatService_CardActive_Req, HeartBeatService_CardActive_Ans>::Pointer ctx)
  11. {
  12. LOG_FUNCTION();
  13. m_pEntity->CardActive(ctx);
  14. }
  15. void HeartBeatServerSession::Handle_CrossTermCall(SpReqAnsContext<HeartBeatService_CrossTermCall_Req, HeartBeatService_CrossTermCall_Ans>::Pointer ctx)
  16. {
  17. LOG_FUNCTION();
  18. m_pEntity->CrossTermCall(ctx);
  19. }
  20. void HeartBeatServerSession::Handle_CallFromILToRVC(SpOnewayCallContext<HeartBeatService_CallFromILToRVC_Info>::Pointer ctx)
  21. {
  22. LOG_FUNCTION();
  23. m_pEntity->CallFromILToRVC(ctx);
  24. }
  25. void HeartBeatServerSession::Handle_CallResultToIL(SpOnewayCallContext<HeartBeatService_CallResultToIL_Info>::Pointer ctx)
  26. {
  27. LOG_FUNCTION();
  28. m_pEntity->CallResultToIL(ctx);
  29. }
  30. ErrorCodeEnum CHeartBeatEntity::GetEntityErrorList(int &warmLevel,CSimpleStringA &strList)
  31. {
  32. if (m_pSelfCheckerClient == NULL)
  33. {
  34. m_pSelfCheckerClient = new SelfCheckerService_ClientBase(this);
  35. if (m_pSelfCheckerClient == NULL)
  36. {
  37. Dbg("create(new) client failed.");
  38. return Error_Resource;
  39. }
  40. Dbg("creat selfchecher client suc.");
  41. }
  42. ErrorCodeEnum eErr = Error_Unexpect;
  43. CSmartPointer<IAsynWaitSp> spWait;
  44. if (!m_bConnetedSS)
  45. {
  46. ErrorCodeEnum eErrConn = Error_Unexpect;
  47. eErrConn = m_pSelfCheckerClient->Connect(spWait);
  48. if (eErrConn == Error_Succeed && spWait != NULL)
  49. eErr = spWait->WaitAnswer(2000);
  50. if (eErrConn != Error_Succeed || eErr != Error_Succeed)
  51. {
  52. Dbg("connect to selfchecker failed.");
  53. if(eErrConn != Error_Succeed) m_pSelfCheckerClient->SafeDelete();
  54. else m_pSelfCheckerClient->GetFunction()->CloseSession();
  55. m_pSelfCheckerClient = NULL;
  56. return Error_Unexpect;
  57. }
  58. Dbg("connect to selfchecker suc.");
  59. m_bConnetedSS = true;
  60. }
  61. //SpReqAnsContext<SelfCheckerService_GetEntityErrorList_Req, SelfCheckerService_GetEntityErrorList_Ans>::Pointer ctx;
  62. SelfCheckerService_GetEntityErrorList_Req req;
  63. SelfCheckerService_GetEntityErrorList_Ans ans;
  64. eErr = m_pSelfCheckerClient->GetEntityErrorList(req,ans,5000);
  65. if (eErr != Error_Succeed)
  66. {
  67. Dbg("GetEntityErrorList failed.%d",eErr);
  68. m_bConnetedSS = false;
  69. m_pSelfCheckerClient->GetFunction()->CloseSession();
  70. m_pSelfCheckerClient = NULL;
  71. return eErr;
  72. }
  73. m_fsm.SetErrorList(ans.warmLevel,ans.list);
  74. return Error_Succeed;
  75. }
  76. void CHeartBeatEntity::OnSysVarEvent(const char *pszKey,
  77. const char *pszValue, const char *pszOldValue, const char *pszEntityName)
  78. {
  79. if ((_strnicmp(pszKey, "TradeManageState", strlen("TradeManageState")) == 0))
  80. {
  81. if (_strnicmp(pszValue, "L", strlen("L")) == 0)
  82. {
  83. Dbg("To set trade manager state to 8.");
  84. m_fsm.SetTradeManagerState(8);
  85. }
  86. else
  87. {
  88. Dbg("To set trade manager state to 1.");
  89. m_fsm.SetTradeManagerState(1);
  90. }
  91. }
  92. if ((_strnicmp(pszKey, "TerminalManagerState", strlen("TerminalManagerState")) == 0))
  93. {
  94. if (_strnicmp(pszValue, "L", strlen("L")) == 0)
  95. {
  96. Dbg("To set terminal manager state to 7.");
  97. m_fsm.SetTradeManagerState(7);
  98. }
  99. else if (_strnicmp(pszValue, "N", strlen("N")) == 0)
  100. {
  101. Dbg("To set terminal manager state to 1.");
  102. m_fsm.SetTradeManagerState(1);
  103. }
  104. else if (_strnicmp(pszValue, "K", strlen("K")) == 0)
  105. {
  106. Dbg("To set terminal manager state to 6.");
  107. m_fsm.SetTradeManagerState(6);
  108. }
  109. }
  110. if ((_strnicmp(pszKey, "TerminalStage", strlen("TerminalStage")) == 0))
  111. {
  112. if (_strnicmp(pszValue, "A", strlen("A")) == 0)
  113. {
  114. Dbg("To set terminal stage to %s.",pszValue);
  115. m_fsm.SetTerminalStageState(pszValue);
  116. }
  117. }
  118. }
  119. void CHeartBeatEntity::OnBroadcastEvent(CUUID SubID, const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, CAutoBuffer Buffer)
  120. {
  121. if (_strnicmp(pszEntityName, "HealthManager", strlen("HealthManager")) == 0)
  122. {
  123. if (dwMessageSignature == eMsgSig_TerminalManager)
  124. {
  125. HealthManager::TerminalManager tm;
  126. SpBuffer2Object(Buffer, tm);
  127. if (tm.op == 99)
  128. {
  129. Dbg("Receive healthmanager event 99,to set terminal manager state to 1.");
  130. m_fsm.SetTradeManagerState(1);
  131. }
  132. }
  133. }
  134. }
  135. void CHeartBeatEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  136. const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  137. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName, const char *pszMessage, const linkContext& pLinkInfo)
  138. {
  139. switch (dwUserCode)
  140. {
  141. default:
  142. break;
  143. }
  144. }
  145. SP_BEGIN_ENTITY_MAP()
  146. SP_ENTITY(CHeartBeatEntity)
  147. SP_END_ENTITY_MAP()