InitializerFSM.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #include "stdafx2.h"
  2. #include "InitializerFSM.h"
  3. #include "mod_Initializer.h"
  4. #include "Event.h"
  5. #include "../EventCode.h"
  6. CInitializerFSM::CInitializerFSM()
  7. {
  8. //
  9. }
  10. CInitializerFSM::~CInitializerFSM()
  11. {
  12. m_iState = FSM_STATE_EXIT; // 屏蔽退出ASSERT错误
  13. }
  14. void CInitializerFSM::OnStateTrans(int iSrcState, int iDstState)
  15. {
  16. Dbg("trans from %s to %s", GetStateName(iSrcState), GetStateName(iDstState));
  17. }
  18. // 初始化PinPad及KMC
  19. ErrorCodeEnum CInitializerFSM::OnInit()
  20. {
  21. AddStateHooker(this);
  22. return Error_Succeed;
  23. }
  24. ErrorCodeEnum CInitializerFSM::OnExit()
  25. {
  26. RemoveStateHooker(this);
  27. return Error_Succeed;
  28. }
  29. bool CInitializerFSM::IsInitializeSucc()
  30. {
  31. return m_iState == s4;
  32. }
  33. void CInitializerFSM::s1_on_entry()
  34. {
  35. Dbg("Enter s1_on_entry.");
  36. //简化版自动做第一次初始化
  37. CInitializerEntity* pEntity = (CInitializerEntity*)m_pEntity;
  38. if (pEntity->IsIL())
  39. {
  40. int nInitFlg = 0;//默认未初始化
  41. pEntity->GetInitializedFlg(nInitFlg);
  42. if (nInitFlg == 0)
  43. {
  44. Dbg("this machine has not been initializd, start init...");
  45. //初始化
  46. CSimpleStringA strAddr;
  47. int nPort=0;
  48. if (pEntity->GetAuthAccessAddr(strAddr, nPort))
  49. {
  50. pEntity->StartInitializeNew(strAddr, nPort, pEntity->m_strUserID, pEntity->m_strPassword);
  51. }
  52. }
  53. }
  54. }
  55. void CInitializerFSM::s1_on_exit()
  56. {
  57. }
  58. unsigned int CInitializerFSM::s1_on_event(FSMEvent* event)
  59. {
  60. Dbg("Enter s1_on_event");
  61. if (event->iEvt == Event_ShowGUI)
  62. {
  63. // 启动GUI
  64. ((CInitializerEntity*)m_pEntity)->StartGUI();
  65. }
  66. else if (event->iEvt == Event_ShowNewGUI)
  67. {
  68. // 启动web初始化界面
  69. Dbg("start GUI New.");
  70. ((CInitializerEntity*)m_pEntity)->StartGUINew();
  71. }
  72. return 0;
  73. }
  74. void CInitializerFSM::s2_on_entry()
  75. {
  76. //
  77. }
  78. void CInitializerFSM::s2_on_exit()
  79. {
  80. //
  81. }
  82. unsigned int CInitializerFSM::s2_on_event(FSMEvent* event)
  83. {
  84. if (event->iEvt == Event_LoginResult)
  85. {
  86. return event->param1;
  87. }
  88. return 0;
  89. }
  90. void CInitializerFSM::s3_on_entry()
  91. {
  92. //
  93. }
  94. void CInitializerFSM::s3_on_exit()
  95. {
  96. //
  97. }
  98. unsigned int CInitializerFSM::s3_on_event(FSMEvent* event)
  99. {
  100. if (event->iEvt == Event_InitMKResult)
  101. return event->param1;
  102. return 0;
  103. }
  104. void CInitializerFSM::s4_on_entry()
  105. {
  106. // 写日志 通知健康模块初始化成功
  107. LogEvent(Severity_Middle, EVENT_MOD_INITIALIZER_MK_LOADED, "主密钥初始化成功");
  108. CInitializerEntity* pEntity = (CInitializerEntity*)m_pEntity;
  109. if (pEntity->m_type == 0) {
  110. pEntity->m_ctx->Ans.Errcode = Error_Succeed;
  111. pEntity->m_ctx->Ans.ErrMsg = "";
  112. pEntity->m_ctx->Answer(Error_Succeed);
  113. }
  114. else if(pEntity->m_type == 1){
  115. pEntity->m_ctx_blue->Ans.Errcode = Error_Succeed;
  116. pEntity->m_ctx_blue->Ans.ErrMsg = "";
  117. pEntity->m_ctx_blue->Answer(Error_Succeed);
  118. }
  119. FSMEvent* fsmEvent = new FSMEvent(Event_ReStart);
  120. PostEventFIFO(fsmEvent);
  121. Dbg("Leave s4_on_entry.");
  122. }
  123. void CInitializerFSM::s4_on_exit()
  124. {
  125. //
  126. }
  127. unsigned int CInitializerFSM::s4_on_event(FSMEvent* event)
  128. {
  129. return 0;
  130. }
  131. void CInitializerFSM::s5_on_entry()
  132. {
  133. Dbg("Entry s5_on_entry().");
  134. //LogError(Severity_Middle, Error_Unexpect, EVENT_MOD_INITIALIZER_MK_FAILED, "主密钥初始化失败");
  135. LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_FAILED,
  136. GetOutPutStr("%s%s","Initializer","主密钥初始化失败").c_str());
  137. FSMEvent* fsmEvent = new FSMEvent(Event_ReStart);
  138. PostEventFIFO(fsmEvent);
  139. }
  140. void CInitializerFSM::s5_on_exit()
  141. {
  142. //
  143. }
  144. unsigned int CInitializerFSM::s5_on_event(FSMEvent* event)
  145. {
  146. if (event->iEvt == Event_ShowGUI)
  147. {
  148. // 启动GUI
  149. ((CInitializerEntity*)m_pEntity)->StartGUI();
  150. }
  151. else if (event->iEvt == Event_ShowNewGUI)
  152. {
  153. // 启动web初始化界面
  154. ((CInitializerEntity*)m_pEntity)->StartGUINew();
  155. }
  156. return 0;
  157. }