mod_heartbeat.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. m_pSelfCheckerClient->SafeDelete();
  39. m_pSelfCheckerClient = NULL;
  40. return Error_Resource;
  41. }
  42. Dbg("creat selfchecher client suc.");
  43. }
  44. ErrorCodeEnum eErr = Error_Unexpect;
  45. CSmartPointer<IAsynWaitSp> spWait;
  46. if (!m_bConnetedSS)
  47. {
  48. ErrorCodeEnum eErrConn = Error_Unexpect;
  49. eErrConn = m_pSelfCheckerClient->Connect(spWait);
  50. if (eErrConn == Error_Succeed && spWait != NULL)
  51. eErr = spWait->WaitAnswer(2000);
  52. if (eErrConn != Error_Succeed || eErr != Error_Succeed)
  53. {
  54. Dbg("connect to selfchecker failed.");
  55. m_pSelfCheckerClient->SafeDelete();
  56. m_pSelfCheckerClient = NULL;
  57. return Error_Unexpect;
  58. }
  59. Dbg("connect to selfchecker suc.");
  60. m_bConnetedSS = true;
  61. }
  62. //SpReqAnsContext<SelfCheckerService_GetEntityErrorList_Req, SelfCheckerService_GetEntityErrorList_Ans>::Pointer ctx;
  63. SelfCheckerService_GetEntityErrorList_Req req;
  64. SelfCheckerService_GetEntityErrorList_Ans ans;
  65. eErr = m_pSelfCheckerClient->GetEntityErrorList(req,ans,5000);
  66. if (eErr != Error_Succeed)
  67. {
  68. Dbg("GetEntityErrorList failed.%d",eErr);
  69. m_bConnetedSS = false;
  70. m_pSelfCheckerClient->SafeDelete();
  71. m_pSelfCheckerClient = NULL;
  72. return eErr;
  73. }
  74. m_fsm.SetErrorList(ans.warmLevel,ans.list);
  75. return Error_Succeed;
  76. }
  77. void CHeartBeatEntity::OnSysVarEvent(const char *pszKey,
  78. const char *pszValue, const char *pszOldValue, const char *pszEntityName)
  79. {
  80. if ((_strnicmp(pszKey, "TradeManageState", strlen("TradeManageState")) == 0))
  81. {
  82. if (_strnicmp(pszValue, "L", strlen("L")) == 0)
  83. {
  84. Dbg("To set trade manager state to 8.");
  85. m_fsm.SetTradeManagerState(8);
  86. }
  87. else
  88. {
  89. Dbg("To set trade manager state to 1.");
  90. m_fsm.SetTradeManagerState(1);
  91. }
  92. }
  93. if ((_strnicmp(pszKey, "TerminalManagerState", strlen("TerminalManagerState")) == 0))
  94. {
  95. if (_strnicmp(pszValue, "L", strlen("L")) == 0)
  96. {
  97. Dbg("To set terminal manager state to 7.");
  98. m_fsm.SetTradeManagerState(7);
  99. }
  100. else if (_strnicmp(pszValue, "N", strlen("N")) == 0)
  101. {
  102. Dbg("To set terminal manager state to 1.");
  103. m_fsm.SetTradeManagerState(1);
  104. }
  105. else if (_strnicmp(pszValue, "K", strlen("K")) == 0)
  106. {
  107. Dbg("To set terminal manager state to 6.");
  108. m_fsm.SetTradeManagerState(6);
  109. }
  110. }
  111. if ((_strnicmp(pszKey, "TerminalStage", strlen("TerminalStage")) == 0))
  112. {
  113. if (_strnicmp(pszValue, "A", strlen("A")) == 0)
  114. {
  115. Dbg("To set terminal stage to %s.",pszValue);
  116. m_fsm.SetTerminalStageState(pszValue);
  117. }
  118. }
  119. }
  120. void CHeartBeatEntity::OnBroadcastEvent(CUUID SubID, const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, CAutoBuffer Buffer)
  121. {
  122. if (_strnicmp(pszEntityName, "HealthManager", strlen("HealthManager")) == 0)
  123. {
  124. if (dwMessageSignature == eMsgSig_TerminalManager)
  125. {
  126. HealthManager::TerminalManager tm;
  127. SpBuffer2Object(Buffer, tm);
  128. if (tm.op == 99)
  129. {
  130. Dbg("Receive healthmanager event 99,to set terminal manager state to 1.");
  131. m_fsm.SetTradeManagerState(1);
  132. }
  133. }
  134. }
  135. }
  136. void CHeartBeatEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  137. const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  138. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName, const char *pszMessage)
  139. {
  140. switch (dwUserCode)
  141. {
  142. default:
  143. break;
  144. }
  145. }
  146. SP_BEGIN_ENTITY_MAP()
  147. SP_ENTITY(CHeartBeatEntity)
  148. SP_END_ENTITY_MAP()