123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- #include "stdafx2.h"
- #include "InitializerFSM.h"
- #include "mod_Initializer.h"
- #include "Event.h"
- #include "../EventCode.h"
- CInitializerFSM::CInitializerFSM()
- {
- //
- }
- CInitializerFSM::~CInitializerFSM()
- {
- m_iState = FSM_STATE_EXIT; // 屏蔽退出ASSERT错误
- }
- void CInitializerFSM::OnStateTrans(int iSrcState, int iDstState)
- {
- Dbg("trans from %s to %s", GetStateName(iSrcState), GetStateName(iDstState));
- }
- // 初始化PinPad及KMC
- ErrorCodeEnum CInitializerFSM::OnInit()
- {
- AddStateHooker(this);
- return Error_Succeed;
- }
- ErrorCodeEnum CInitializerFSM::OnExit()
- {
- RemoveStateHooker(this);
- return Error_Succeed;
- }
- bool CInitializerFSM::IsInitializeSucc()
- {
- return m_iState == s4;
- }
-
- void CInitializerFSM::s1_on_entry()
- {
- Dbg("Enter s1_on_entry.");
- //简化版自动做第一次初始化
- CInitializerEntity* pEntity = (CInitializerEntity*)m_pEntity;
- if (pEntity->IsIL())
- {
- int nInitFlg = 0;//默认未初始化
- pEntity->GetInitializedFlg(nInitFlg);
-
- if (nInitFlg == 0)
- {
- Dbg("this machine has not been initializd, start init...");
- //初始化
- CSimpleStringA strAddr;
- int nPort=0;
- if (pEntity->GetAuthAccessAddr(strAddr, nPort))
- {
- pEntity->StartInitializeNew(strAddr, nPort, pEntity->m_strUserID, pEntity->m_strPassword);
- }
- }
- }
- }
- void CInitializerFSM::s1_on_exit()
- {
- }
- unsigned int CInitializerFSM::s1_on_event(FSMEvent* event)
- {
- Dbg("Enter s1_on_event");
- if (event->iEvt == Event_ShowGUI)
- {
- // 启动GUI
- ((CInitializerEntity*)m_pEntity)->StartGUI();
- }
- else if (event->iEvt == Event_ShowNewGUI)
- {
- // 启动web初始化界面
- Dbg("start GUI New.");
- ((CInitializerEntity*)m_pEntity)->StartGUINew();
- }
- return 0;
- }
- void CInitializerFSM::s2_on_entry()
- {
- //
- }
- void CInitializerFSM::s2_on_exit()
- {
- //
- }
- unsigned int CInitializerFSM::s2_on_event(FSMEvent* event)
- {
- if (event->iEvt == Event_LoginResult)
- {
- return event->param1;
- }
- return 0;
- }
- void CInitializerFSM::s3_on_entry()
- {
- //
- }
- void CInitializerFSM::s3_on_exit()
- {
- //
- }
- unsigned int CInitializerFSM::s3_on_event(FSMEvent* event)
- {
- if (event->iEvt == Event_InitMKResult)
- return event->param1;
-
- return 0;
- }
- void CInitializerFSM::s4_on_entry()
- {
- // 写日志 通知健康模块初始化成功
- LogEvent(Severity_Middle, EVENT_MOD_INITIALIZER_MK_LOADED, "主密钥初始化成功");
- CInitializerEntity* pEntity = (CInitializerEntity*)m_pEntity;
- if (pEntity->m_type == 0) {
- pEntity->m_ctx->Ans.Errcode = Error_Succeed;
- pEntity->m_ctx->Ans.ErrMsg = "";
- pEntity->m_ctx->Answer(Error_Succeed);
- }
- else if(pEntity->m_type == 1){
- pEntity->m_ctx_blue->Ans.Errcode = Error_Succeed;
- pEntity->m_ctx_blue->Ans.ErrMsg = "";
- pEntity->m_ctx_blue->Answer(Error_Succeed);
- }
- FSMEvent* fsmEvent = new FSMEvent(Event_ReStart);
- PostEventFIFO(fsmEvent);
- Dbg("Leave s4_on_entry.");
- }
- void CInitializerFSM::s4_on_exit()
- {
- //
- }
- unsigned int CInitializerFSM::s4_on_event(FSMEvent* event)
- {
- return 0;
- }
- void CInitializerFSM::s5_on_entry()
- {
- Dbg("Entry s5_on_entry().");
- //LogError(Severity_Middle, Error_Unexpect, EVENT_MOD_INITIALIZER_MK_FAILED, "主密钥初始化失败");
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_FAILED,
- GetOutPutStr("%s%s","Initializer","主密钥初始化失败").c_str());
- FSMEvent* fsmEvent = new FSMEvent(Event_ReStart);
- PostEventFIFO(fsmEvent);
- }
- void CInitializerFSM::s5_on_exit()
- {
- //
- }
- unsigned int CInitializerFSM::s5_on_event(FSMEvent* event)
- {
- if (event->iEvt == Event_ShowGUI)
- {
- // 启动GUI
- ((CInitializerEntity*)m_pEntity)->StartGUI();
- }
- else if (event->iEvt == Event_ShowNewGUI)
- {
- // 启动web初始化界面
- ((CInitializerEntity*)m_pEntity)->StartGUINew();
- }
- return 0;
- }
|