123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- // mod_selfchecker.cpp : Defines the exported functions for the DLL application.
- //
- #include "stdafx.h"
- #include "mod_selfchecker.h"
- #include "EventCode.h"
- #include "ModuleMix.h"
- void SelfCheckerSession::Handle_RealCheck(SpReqAnsContext<SelfCheckerService_RealCheck_Req, SelfCheckerService_RealCheck_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- DbgToBeidou(ctx->link, __FUNCTION__)();
- m_pEntity->RealCheck(ctx);
- }
- void SelfCheckerSession::Handle_GetEntityErrorList(SpReqAnsContext<SelfCheckerService_GetEntityErrorList_Req, SelfCheckerService_GetEntityErrorList_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- m_pEntity->GetEntityErrorList(ctx);
- }
- ErrorCodeEnum CSelfCheckerEntity::GetEntityTestCode(const char* pszEntityName, ErrorCodeEnum& LastTestError, TestActionEnum& eLastAction)
- {
- return Error_NotImpl;
- }
- ErrorCodeEnum CSelfCheckerEntity::ExamineEntity(const char* pszEntityName)
- {
- CSmartPointer<IEntityFunction> pFunc = GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- CSmartPointer<IAsynWaitSp> spWait;
- //ErrorCodeEnum errCode;
- pFuncPrivilege->TestEntity(pszEntityName, Test_Examine, spWait);
- return Error_Succeed;
- }
- //ErrorCodeEnum CSelfCheckerEntity::AddEntity(const char *pszEntityName)
- //{
- // if (pszEntityName == NULL)
- // return Error_Null;
- // return m_fsm.AddEntity(pszEntityName);
- //}
- //ErrorCodeEnum CSelfCheckerEntity::RemoveEntity(vector<CSimpleStringA> &entityVec, const char *pszEntityName)
- //{
- // if (pszEntityName == NULL)
- // return Error_Null;
- // return m_fsm.RemoveEntity(pszEntityName);
- //}
- //ErrorCodeEnum CSelfCheckerEntity::CheckEntity()
- //{
- // return Error_Succeed;
- //}
- // if pszTriggerEntity=null mean created by shell
- void CSelfCheckerEntity::OnCreated(const char* pszEntityName, ErrorCodeEnum eOnStartErrorCode, const char* pszCallerEntity)
- {
- m_fsm.DoOnCreated(pszEntityName, eOnStartErrorCode, pszCallerEntity);
- }
- //Call after the entity has close or killed, eOnCloseErrorCode notic if the entity do OnClose normally and resource has beed release
- void CSelfCheckerEntity::OnClosed(const char* pszEntityName, EntityCloseCauseEnum eCloseCause, ErrorCodeEnum eOnCloseErrorCode, const char* pszCallerEntity)
- {
- m_fsm.DoOnClosed(pszEntityName, eCloseCause, eOnCloseErrorCode, pszCallerEntity);
- }
- //the following OnException & OnEntityStateHook doing the same thing repeatly???
- //1 case is entity raise exception and catch by framework,but not mean the entity will close,2 case is the entity is enter lost state
- void CSelfCheckerEntity::OnException(const char* pszEntityName, const char* pszFunctionName, EntityStateEnum eState, EntityStateEnum eLastState, ErrorCodeEnum eErrorCode)
- {
- m_fsm.DoOnException(pszEntityName, pszFunctionName, eState, eLastState, eErrorCode);
- }
- void CSelfCheckerEntity::OnEntityStateHook(const char* pszEntityName, const char* pszTriggerEntity, EntityStateEnum eState, EntityStateEnum eLastState)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s trigger by %s: from %s to %s",pszEntityName,pszTriggerEntity, SpStrEntityState(eLastState), SpStrEntityState(eState));
- m_fsm.AddEntityState(pszEntityName, eState);
- CSmartPointer<IEntityFunction> pFunc = GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- if (pFuncPrivilege == NULL)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("NoPrivilege");
- return;
- }
- CSmartPointer<IAsynWaitSp> spWait;
- ErrorCodeEnum errCode;
- int count = 0;
- {
- switch (eState)
- {
- case EntityState_Lost:
- {
- //oilyang@20220415 special process of RVC.PAD with FWB
- CSimpleStringA tmpFWBDevSN("");
- GetFunction()->GetSysVar("FWBDevSN", tmpFWBDevSN);
- if (m_sysInfo.strMachineType.Compare("RVC.PAD", true) == 0 && !tmpFWBDevSN.IsNullOrEmpty())
- {
- if (_strnicmp("PinPad", pszEntityName, strlen("PinPad")) == 0
- || _strnicmp("IDCertificate", pszEntityName, strlen("IDCertificate")) == 0
- || _strnicmp("FingerPrint", pszEntityName, strlen("FingerPrint")) == 0)
- {
- count = m_entityProcInfo[pszEntityName].restartTimes;
- if (count >= m_maxEtyRestartTimes)
- {
- LogWarn(Severity_Middle, Error_Unexpect, LOG_WARN_SELFCHECK_ENTITY_LOST_TIMES
- , CSimpleStringA::Format("%s restart %d times, give up.", pszEntityName, count).GetData());
- break;
- }
- m_fsm.CheckEntity(pszEntityName, Test_ShakeHand);
- m_entityProcInfo[pszEntityName].restartTimes = count + 1;
- }
- break;
- }
- //doing nothing except for loading stage. HandShake will take it.
- //and only for MediaController module.
- //oilyang@20210809 add entity lost LogWarn
- CSimpleStringA tmpWarnMsg = CSimpleStringA::Format("%s lost. trig entity:%s,lastState:%d", pszEntityName, pszTriggerEntity, eLastState);
- CEntityStaticInfo esi = { 0 };
- ErrorCodeEnum ec = GetFunction()->GetEntityStaticInfo(pszEntityName, esi);
- LogWarn(Severity_High, Error_Unexpect, SelfChecker_UserErrorCode_EntityLost_Start + esi.wEntityDevelopID, tmpWarnMsg.GetData());
- if (m_bEverInMainPage && _strnicmp("TokenKeeper", pszEntityName, strlen("TokenKeeper")) == 0)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("TokenKeeper lost");
- LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_TOKEN_KEEPER_LOST, "TokenKeeper lost,restart and auth again.");
- break;
- }
- if (m_bEverInMainPage)
- break;
- if (_strnicmp("MediaController", pszEntityName, strlen("MediaController")) != 0)
- break;
- count = m_entityProcInfo[pszEntityName].restartTimes;
- if (count >= m_maxEtyRestartTimes)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("%s has restart %d times,give up to restart it again.", pszEntityName, count);
- CSimpleStringA tmpWarnMsg = CSimpleStringA::Format("%s restart %d times,give up.", (LPCTSTR)pszEntityName, count);
- LogWarn(Severity_High, Error_Unexpect, LOG_WARN_SELFCHECK_ENTITY_LOST_TIMES, tmpWarnMsg.GetData());
- break;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s lost count %d", pszEntityName, count);
- errCode = pFuncPrivilege->TerminateEntity(pszEntityName, spWait);
- if (errCode == Error_Succeed)
- {
- errCode = spWait->WaitAnswer(10000);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("onlost kill wait %d", errCode);
- }
- else
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("onlost kill %d", errCode);
- Sleep(5000);
- errCode = pFuncPrivilege->StartEntity(pszEntityName, NULL, spWait);
- if (errCode == Error_Succeed)
- {
- errCode = spWait->WaitAnswer(10000);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("onlost start wait %d", errCode);
- }
- else
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("onlost start %d", errCode);
- m_entityProcInfo[pszEntityName].restartTimes = count + 1;
- }
- break;
- case EntityState_Idle:
- {
- m_entityProcInfo[pszEntityName].restartTimes = 0;
- if (!_strnicmp("SIPPhone", pszEntityName, strlen("SIPPhone")))
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SIPPhone change to idle.");
- LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_SIPPHONE_IDLE, "SIPPhone to idle.");
- }
- else if (!_strnicmp("HealthManager", pszEntityName, strlen("HealthManager")))
- {
- }
- else if (!_strnicmp("LocalMediaPlay", pszEntityName, strlen("LocalMediaPlay")))
- {
- LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_LOCALMEDIAPLAY_IDLE, "LocalMediaPlay to idle.");
- }
- if (_strnicmp("Chromium", pszEntityName, strlen("Chromium")) == 0)
- {
- LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_IEBROWSER_IDLE, "Chromium to idle.");
- m_bIEIdle = true;
- }
- }
- break;
- default:
- break;
- }
- }
- }
- void CSelfCheckerEntity::OnUserStateHook(const char* pszEntityName, DWORD dwState, DWORD dwLastState)
- {
- }
- void CSelfCheckerEntity::OnCeateConnection(const char* pszCallerEntity, const char* pszServiceEntity)
- {
- }
- void CSelfCheckerEntity::OnCloseConnection(const char* pszCallerEntity, const char* pszServiceEntity)
- {
- }
- void CSelfCheckerEntity::RealCheck(SpReqAnsContext<SelfCheckerService_RealCheck_Req, SelfCheckerService_RealCheck_Ans>::Pointer ctx)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Real check %s", (LPCTSTR)ctx->Req.name);
- m_fsm.CheckEntity(ctx->Req.name, Test_ShakeHand, false);
- ctx->Answer(Error_Succeed);
- }
- void CSelfCheckerEntity::GetEntityErrorList(SpReqAnsContext<SelfCheckerService_GetEntityErrorList_Req, SelfCheckerService_GetEntityErrorList_Ans>::Pointer ctx)
- {
- ErrorCodeEnum eErr = m_fsm.GetEntityErrorList(ctx->Ans.warmLevel, ctx->Ans.list);
- ctx->Answer(eErr);
- }
- void CSelfCheckerEntity::OnLog(const CAutoArray<CUUID>& SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
- const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
- const CAutoArray<DWORD>& Param, const char* pszEntityName, const char* pszModuleName, const char* pszMessage, const linkContext& pLinkInfo)
- {
- //oilyang@20170918 only process the Log_Error of Severity_High
- if (eLogType != Log_Error || eLevel != Severity_High)
- return;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("user code %d,%s", dwUserCode, (LPCTSTR)pszMessage);
- switch (dwUserCode)
- {
- default:
- break;
- }
- m_fsm.Proc(pszEntityName, ProcType_Warn, dwUserCode, pszMessage);
- }
- ErrorCodeEnum CSelfCheckerEntity::GetEntityStatusStr(CSimpleStringA& result)
- {
- CSmartPointer<IEntityFunction> pFunc = GetFunction();
- CEntityRunInfo runInfo;
- ErrorCodeEnum eErr;
- vector<CSimpleStringA>::iterator it;
- for (it = m_vQueryStateEntity.begin(); it != m_vQueryStateEntity.end(); ++it)
- {
- eErr = pFunc->GetEntityRunInfo(*it, runInfo);
- if (eErr == Error_Succeed)
- {
- result += UserDefEntityMsg[runInfo.dwUserState][0];
- result += " ;";
- }
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("state[%s]", (LPCTSTR)result);
- return Error_Succeed;
- }
- ErrorCodeEnum CSelfCheckerEntity::RestartModule(const char* pEntityName)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to RestartModule:%s", pEntityName);
- m_fsm.SetEntityRestarting(pEntityName, true);
- CSmartPointer<IEntityFunction> pFunc = GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- if (pFuncPrivilege == NULL)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("restart mc NoPrivilege");
- m_fsm.SetEntityRestarting(pEntityName, false);
- return Error_NoPrivilege;
- }
- CSmartPointer<IAsynWaitSp> spWait;
- ErrorCodeEnum eErrCode = Error_Succeed;
- eErrCode = pFuncPrivilege->TerminateEntity(pEntityName, spWait);
- if (spWait != NULL)
- eErrCode = spWait->WaitAnswer(10000);
- if (eErrCode != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("kill %s %d", pEntityName, eErrCode);
- m_fsm.SetEntityRestarting(pEntityName, false);
- return eErrCode;
- }
- Sleep(1000);
- eErrCode = pFuncPrivilege->StartEntity(pEntityName, NULL, spWait);
- if (spWait != NULL)
- eErrCode = spWait->WaitAnswer(10000);
- if (eErrCode != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start %s %d", pEntityName, eErrCode);
- m_fsm.SetEntityRestarting(pEntityName, false);
- return eErrCode;
- }
- m_fsm.SetEntityRestarting(pEntityName, false);
- return Error_Succeed;
- }
- void CSelfCheckerEntity::OnSysVarEvent(const char* pszKey, const char* pszValue, const char* pszOldValue, const char* pszEntityName)
- {
- if ((_strnicmp(pszKey, "UIState", strlen("UIState")) == 0))
- {
- if (_strnicmp(pszValue, "M", strlen("M")) == 0)
- {
- m_bEverInMainPage = true;
- m_fsm.SetEverEnterMainPageFlag();
- }
- }
- else if ((_strnicmp(pszKey, "TerminalStage", strlen("TerminalStage")) == 0))
- {
- //oiltmp
- if (!m_bGetEntityList)
- {
- m_bGetEntityList = true;
- CSmartPointer<IConfigInfo> spConfigCen;
- GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen);
- CSimpleStringA csCoreBootList(true), csSafeLoadList(true), csOperatingList(true), csKeyCB("CoreBootList."), csKeySL("SafeLoadList."), csKeyOp("OperatingList.");
- spConfigCen->ReadConfigValue("VtmLoader", (csKeyCB + m_sysInfo.strMachineType).GetData(), csCoreBootList);
- spConfigCen->ReadConfigValue("VtmLoader", (csKeySL + m_sysInfo.strMachineType).GetData(), csSafeLoadList);
- spConfigCen->ReadConfigValue("VtmLoader", (csKeyOp + m_sysInfo.strMachineType).GetData(), csOperatingList);
- m_fsm.GetEntityList(csCoreBootList);
- m_fsm.GetEntityList(csSafeLoadList);
- m_fsm.GetEntityList(csOperatingList);
- }
- }
- }
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(CSelfCheckerEntity)
- SP_END_ENTITY_MAP()
|