// mod_healthmanager.cpp : Defines the exported functions for the DLL application. // #include "stdafx.h" #if defined(RVC_OS_WIN) #include #include #include #include #include #pragma comment( lib, "User32.lib" ) #pragma comment( lib, "advapi32.lib" ) #pragma comment(lib, "IPHLPAPI.lib") #include "..\mod_chromium\Chromium_client_g.h" //启动浏览器接口 using namespace Chromium; #include #else #include #include #include #include #include #include #include #include "../mod_chromium/Chromium_client_g.h" //启动浏览器接口 using namespace Chromium; #endif //RVC_OS_WIN #include #include #include #include "toolkit.h" #include "array.h" #include "fileutil.h" #include "iniutil.h" #include "osutil.h" #if defined(RVC_OS_LINUX) #include "EntityBootStruct.h" #include #include "RestfulFunc.h" #include "api_manage_list.h" #include "api_manufacture_controller.h" #include "JsonConvertHelper.hpp" #endif using namespace std; #include "mod_healthmanager.h" #include "CommEntityUtil.hpp" #include "CommEntitySettings.hpp" #include "TerminalInfoQueryConn.h" const DWORD HEALTHMANAGER_TIMER_ID = 1; const DWORD HEALTHMANAGER_WAIT_MAINPAGE_OPEN_TIMER_ID = 2; const DWORD HEALTHMANAGER_SELFCHECK_TIMER_ID = 3; const DWORD HEALTHMANAGER_TIMER_INTERVAL = 60000; const DWORD HEALTHMANAGER_WAIT_MAINPAGE_OPEN_TIMER_INTERVAL = 60000; const DWORD HEALTHMANAGER_REBOOT_OS_IN_MINUTES_AFTER_TIME = 5; const DWORD HEALTHMANAGER_SELFCHECK_TIMER_INTERVAL = 60000; const int MAX_STOP_AYSNC_TIMEOUT = 20000; const int MAX_TERM_AYSNC_TIMEOUT = 30000; const int MAX_START_AYSNC_TIMEOUT = 20000; #define WORKING_BUFFER_SIZE 15000 #define MAX_TRIES 3 #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) #define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) #if defined(RVC_OS_LINUX)//oiltmp //for defines in header file #include "Chromium_client_g.h" using namespace Chromium; #endif #define MediaDev_OutSpeaker 1 #define MediaDev_InSpeaker 2 #define MediaDev_OutMicrophone 3 #define MediaDev_InMicrophone 4 template class TimerOutHelper : public ITimerListener { public: typedef void (T::*FuncTimer)(); TimerOutHelper(T *p, FuncTimer pTimerFunc, bool bDeleteSelf = false) : m_pObject(p), m_pTimer(pTimerFunc), m_bDeleteSelf(bDeleteSelf) {} virtual void OnTimeout(DWORD dwTimerID) { (m_pObject->*m_pTimer)(); if (m_bDeleteSelf) delete this; } private: T *m_pObject; FuncTimer m_pTimer; bool m_bDeleteSelf; }; void HealthManagerSession::Handle_EnterState(SpReqAnsContext::Pointer ctx) { LOG_FUNCTION(); DbgToBeidou(ctx->link, __FUNCTION__)(); m_pEntity->EnterState(ctx); } void HealthManagerSession::Handle_ExitState(SpReqAnsContext::Pointer ctx) { LOG_FUNCTION(); DbgToBeidou(ctx->link, __FUNCTION__)(); m_pEntity->ExitState(ctx); } void HealthManagerSession::Handle_DoEvent(SpReqAnsContext::Pointer ctx) { LOG_FUNCTION(); DbgToBeidou(ctx->link, __FUNCTION__)(); m_pEntity->DoEvent(ctx); } void HealthManagerSession::Handle_GetNetworkState(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); m_pEntity->GetNetworkState(ctx); } void HealthManagerSession::Handle_QueryHardwareInfo(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); m_pEntity->QueryHardwareInfo(ctx); } void HealthManagerSession::Handle_ReadCenterConfigStr(SpReqAnsContext::Pointer ctx) { LOG_FUNCTION(); DbgToBeidou(ctx->link, __FUNCTION__)(); m_pEntity->ReadCenterConfigStr(ctx); } void HealthManagerSession::Handle_GetAuthErrMsg(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); m_pEntity->GetAuthErrMsg(ctx); } void HealthManagerSession::Handle_RealCheck(SpReqAnsContext::Pointer ctx) { LOG_FUNCTION(); DbgToBeidou(ctx->link, __FUNCTION__)(); m_pEntity->RealCheck(ctx); } void HealthManagerSession::Handle_QueryCenterCfg(SpReqAnsContext::Pointer ctx) { LOG_FUNCTION(); DbgToBeidou(ctx->link, __FUNCTION__)(); m_pEntity->QueryCenterCfg(ctx); } /** TerminalStage A: 准入通过? C: 准入不通过? D:设备故障 B: N: U: */ //almost disused. ErrorCodeEnum CHealthManagerEntity::RestartModule(const char* pEntityName) { CSmartPointer pFunc = GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); if (pFuncPrivilege == NULL) { DbgWithLink(LOG_LEVEL_WARN,LOG_TYPE_SYSTEM)("restart mc NoPrivilege"); return Error_NoPrivilege; } map::iterator it; it = m_modRunInfo.find(pEntityName); if (it == m_modRunInfo.end()) { DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("add %s to modfuninfo(%d).",pEntityName,m_modRunInfo.size()); m_modRunInfo[pEntityName].dwStart = SP::Module::Comm::RVCGetTickCount(); } else { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("modruninfo EntityName=%s", pEntityName); } CSmartPointer spWait; ErrorCodeEnum eErrCode = Error_Succeed; eErrCode = pFuncPrivilege->TerminateEntity(pEntityName,spWait); if (spWait != NULL) eErrCode = spWait->WaitAnswer(10000); if (eErrCode != Error_Succeed) { DbgWithLink(LOG_LEVEL_WARN,LOG_TYPE_SYSTEM)("kill %s %d",pEntityName,eErrCode); return eErrCode; } Sleep(3000); eErrCode = pFuncPrivilege->StartEntity(pEntityName,NULL,spWait); if (spWait != NULL) eErrCode = spWait->WaitAnswer(10000); if (eErrCode != Error_Succeed) { DbgWithLink(LOG_LEVEL_WARN,LOG_TYPE_SYSTEM)("start %s %d",pEntityName,eErrCode); return eErrCode; } return eErrCode; } void CHealthManagerEntity::AfterWaitRestartPC() { CSmartPointer pFunc = GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); if (pFuncPrivilege == NULL) { DbgWithLink(LOG_LEVEL_ERROR,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("restart pc NoPrivilege"); return; } ErrorCodeEnum eErr; CSimpleStringA csCustomerHandle(""); eErr = GetFunction()->GetSysVar("CustomerHandle",csCustomerHandle); if (eErr != Error_Succeed) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get CustomerHandle failed (%s).", SpStrError(eErr)); } else DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("CustomerHandle:%s", csCustomerHandle.GetData()); if (csCustomerHandle[0] == 'N') { m_bWaitRestartPC = false; pFuncPrivilege->DisplayBlueScreen("PAUSE SERVICE"); DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("time comes,restart machine"); m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_RunExcepition, RebootWay_OS); } } void CHealthManagerEntity::OnCheckTimeTimeout() { if (!m_bSayIdle) DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnCheckTimeTimeout"); //oilyang@20220330 check if need restart framework by THE key CenterSetting updated. if (m_bToRestartByCenterSetting) { CSimpleStringA csTermStage(""); ErrorCodeEnum eErrCode; eErrCode = GetFunction()->GetSysVar("TerminalStage", csTermStage); Dbg("OnCheckTimeTimeout::ToRestartByCenterSetting to get termstage %s", csTermStage.GetData()); //oilyang@20250313 in Main page('UIState' is 'M') or TerminalStage is (NOT 'S') AND (NOT 'A'),that is in close page which caused by terminal app if (m_bInMainPage || (!m_bInMainPage && csTermStage.Compare("S") != 0 && csTermStage.Compare("A") != 0) ) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("THE key CenterSetting updated,we must restart framework right now."); m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_Resource, RebootWay_Framework); } } SYSTEMTIME localTime; GetLocalTimeRVC(localTime); //for example:[1----6] // ^ here we go //in reboot period if (localTime.wHour >= m_rebootHourBegin && localTime.wHour <= m_rebootHourEnd) { //reach setting reboot time if (localTime.wHour == m_restartHour && (localTime.wMinute >= m_restartMinute && localTime.wMinute <= m_restartMinute + HEALTHMANAGER_REBOOT_OS_IN_MINUTES_AFTER_TIME)) { m_OSRunTicks = SP::Module::Comm::RVCGetTickCount(); //the os haven't reboot today if (m_OSRunTicks > m_restartHour * 60 * 60 * 1000 + m_restartMinute * 60 * 1000) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to restart machine daily"); m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_Period, RebootWay_OS); } } } ErrorCodeEnum eErr = Error_Unexpect; CSmartPointer spConfigRun; eErr = GetFunction()->OpenConfig(Config_Run, spConfigRun); if (eErr != Error_Succeed) DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("timer open cfg file failed!"); if (!m_bSayIdle) DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_fsm.GetFSMState():%d", m_fsm.GetFSMState()); int iCheckGuardian = 0; if (m_fsm.GetFSMState() == HM_FSM_STATE_IDLE || (m_fsm.GetFSMState() == HM_FSM_STATE_CMS)) { //oilyang@20210922 add comment //1、AccessAuth ok //2、have ever enter main page OR if (!m_bSayIdle) DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_fsm.GetAccessAuthFlag():%d, CheckIfHaveEnterMainPageEver:%d", m_fsm.CheckIfAccessAuthSuc(), CheckIfHaveEnterMainPageEver()); //oilyang@20241230 check if have enter Main page ever if (CheckIfHaveEnterMainPageEver()) { iCheckGuardian = CheckGuardianIsRun(true); if (!m_bSayIdle) DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("iCheckGuardian:%d", iCheckGuardian); if (!m_bSayIdle) { m_bSayIdle = true; if (iCheckGuardian > 0) { if (m_pfUpgradeRestart != NULL) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("healthmanager say idle,so tell the guardian.%d", m_pfUpgradeRestart(3, 0)); } } CSimpleStringA csRunCfgPath(""), csStartTime(""); ErrorCodeEnum eErr = GetFunction()->GetPath("RunCfg", csRunCfgPath); csStartTime = csRunCfgPath + SPLIT_SLASH_STR + "starttime.dat"; DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("csStartTime:%s", csStartTime.GetData()); #if defined(RVC_OS_WIN) if (_access((const char*)csStartTime, 0) == 0) { int ret = DeleteFileA(csStartTime);//oiltmp@20240423 why don't use remove ,what's the different? if (ret != 0)//删除成功,清理前次记录的guardian版本记录 { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete start time file [%s] suc.", csStartTime.GetData()); spConfigRun->WriteConfigValue("Run", "VersionEx", ""); } else DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete time file [%s] error.[%d]", csStartTime.GetData(), GetLastError()); } #else if (access((const char*)csStartTime, F_OK) == 0) { int ret = remove(csStartTime); if (ret == 0)//删除成功,清理前次记录的guardian版本记录 spConfigRun->WriteConfigValue("Run", "VersionEx", ""); else DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete time file [%s] error.[%d]", csStartTime.GetData(), errno); } #endif } if (iCheckGuardian > 0) { if (m_pfShake != NULL) { WorkStateEnum eShake; m_pfShake(eShake); m_ullGuardShakeCount++; } if (m_ullGuardShakeCount == 2)//in the next timeout(1 minute later than before,to restart guardian) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("准备重新启动guardian"); bool bStop = StopGuardian(); if (bStop) { bool bGuardian = StartGuardian(); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("restart guardian %d", bGuardian); } } else if (m_ullGuardShakeCount % 5 == 0) { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("the %d shake hand(guardian)", m_ullGuardShakeCount); } } else if (iCheckGuardian == -1) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("未启动guardian,准备启动guardian"); bool bGuardian = StartGuardian(); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("start guardian %d", bGuardian); } } else { //oilyang@20190905 add if auth suc,tell guardian,for upgrade if (m_fsm.CheckIfAccessAuthSuc()) { if (CheckGuardianIsRun(true) > 0) { if (m_pfUpgradeRestart != NULL) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("auth suc,so tell the guardian.%d", m_pfUpgradeRestart(5, 0)); } } } } } //oilyang@20210331 if accessauth told me not to restart framework,so that it can have time to retry if (!m_bNeedGuardianRestart) { if (CheckGuardianIsRun(true) > 0) { if (m_pfShake != NULL) { WorkStateEnum eShake; DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("accessauth told me not to restart framework,so that it can have time to retry.%d", m_pfShake(eShake)); } } } if (m_fsm.GetFSMState() == HM_FSM_STATE_CMS) { GetFunction()->ResetTimer(HEALTHMANAGER_TIMER_ID, HEALTHMANAGER_TIMER_INTERVAL); return; } if (m_bWaitRestartPC) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("finally we the restart time come,no wait."); //m_bWaitRestartPC = false; AfterWaitRestartPC(); } GetFunction()->ResetTimer(HEALTHMANAGER_TIMER_ID, HEALTHMANAGER_TIMER_INTERVAL); } #if defined(RVC_OS_LINUX) bool FindGuardianPid(CAutoArray &pIDArr) { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to check guardian process"); char* relate_processes[] = { "guardian" }; int relate_processes_count = 1; alive_process_info processes[64]; int alive_process_info_count = 64; memset(processes, 0, sizeof(processes)); int retOfDetect = osutil_detect_unique_app(relate_processes, relate_processes_count, &alive_process_info_count, processes); DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("detect guardian return:%d, alive_process_info_count:%d", retOfDetect, alive_process_info_count); if (alive_process_info_count > 0) { if (alive_process_info_count > 64) DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("too many guardian:%d", alive_process_info_count); else { if (alive_process_info_count == 1) pIDArr.Append(&processes[0].pid, 0, 1); else { for (int i = 0; i < alive_process_info_count; i++) { pIDArr.Append(&processes[i].pid, 0, 1); DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("The %d(th) guardian's pid is:%d", i + 1, processes[i].pid); } } } return true; } return false; } #endif //RVC_OS_LINUX int CHealthManagerEntity::CheckGuardianIsRun(bool bStart) { #ifdef RVC_OS_WIN HANDLE hSnapshot; //find guardian.exe hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnapshot) { PROCESSENTRY32 pe; pe.dwSize = sizeof(pe); if (Process32First(hSnapshot, &pe)) { do { if (_stricmp(&pe.szExeFile[0], "guardian.exe") == 0) { if (!m_bSayIdle) DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("guardian is running."); return 1; } } while (Process32Next(hSnapshot, &pe)); } CloseHandle(hSnapshot); } Sleep(1000); DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("cannot find guardian."); if (!m_bNeedGuardian)//no need guardian { if (!m_bSayIdle) DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("no need guardian, so don't care about bStart flag"); return 0; } else { bool bStartResult = false; if (bStart) bStartResult = StartGuardian(); if (bStartResult) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start guardian ok."); return 1; } else { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("start guardian failed."); return -1; } } #else CAutoArray pIDArr; bool bFind = false; bFind = FindGuardianPid(pIDArr); if (bFind) { for (int i = 0; i < pIDArr.GetCount(); i++) { int ret = kill(pIDArr[i], 0); if (0 == ret) { if (!m_bSayIdle) DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("guardian.exe is active, pid:%d", pIDArr[i]); return 1; } else { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("process: guardian.exe inactive, pID:%d,ret:%d", pIDArr[i], ret); } } } else DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("cannot find guardian."); if (!m_bNeedGuardian)//no need guardian { if (!m_bSayIdle) DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("no need guardian, so don't care about bStart flag"); return 0; } else { bool bStartResult = false; if (bStart) bStartResult = StartGuardian(); if (bStartResult) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start guardian ok."); return 1; } else { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("start guardian failed."); return -1; } } #endif //RVC_OS_WIN } bool CHealthManagerEntity::StopGuardian() { #ifdef RVC_OS_WIN DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("to stop guardian"); HANDLE hSnapshot; int rc = TRUE; int result; HANDLE hProcess; //find and kill guardian.exe hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnapshot) { PROCESSENTRY32 pe; pe.dwSize = sizeof(pe); if (Process32First(hSnapshot, &pe)) { do { if (_stricmp(&pe.szExeFile[0], "guardian.exe") == 0) { hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID ); if( hProcess == NULL ) { DbgWithLink(LOG_LEVEL_ERROR,LOG_TYPE_SYSTEM)("Fail to open process(%d)!",GetLastError()); return false; } else { result = TerminateProcess(hProcess,-1); if (result) { Sleep(3000); DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("Terminate guardian suc."); return true; } else { DbgWithLink(LOG_LEVEL_ERROR,LOG_TYPE_SYSTEM)("Terminate guardian failed(%d).",GetLastError()); return false; } CloseHandle( hProcess ); } Sleep(3000); WaitForSingleObject(&pe.th32ProcessID, INFINITE ); break; } } while (Process32Next(hSnapshot, &pe)); } CloseHandle(hSnapshot); } Sleep(3000); return false; #else //why add the fallowing before ?oiltmp@20240407 //int ret = m_pfUpgradeRestart(6, 0); //Dbg("healthmanager tell the guardian to quit.%d", ret); Sleep(5000); CAutoArray pIDArr; bool bFind = false; bFind = FindGuardianPid(pIDArr); if (bFind) { for (int i = 0; i < pIDArr.GetCount(); i++) { if (pIDArr[i] == 0) continue; int ret = kill(pIDArr[i], 9 /*SIGKILL*/); if (ret < 0) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("kill guardian(pid:%d) failed:%d", pIDArr[i], errno); return false; } else DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("kill guardian(pid:%d) successfully.", pIDArr[i]); } return true; } DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("can't find guardian pid."); return true; #endif //RVC_OS_WIN } bool CHealthManagerEntity::StartGuardian() { LOG_FUNCTION(); //oiltmp TODO 如果是未安装,不启动guardian //root.ini 不存在,表示未安装 CSystemStaticInfo staticInfo; GetFunction()->GetSystemStaticInfo(staticInfo); /** 添加日志控制逻辑 Gifur@202414]*/ SP::Module::Comm::Settings::InitializeOtherLogSwitch(this, "guardian"); DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("to start guardian"); // Start the child process. CSimpleStringA csBinPath, csAll, csSep("\""); ErrorCodeEnum Error = GetFunction()->GetPath("Bin", csBinPath); #if defined(RVC_OS_WIN) STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); GetFunction()->FlushLogFile(); csBinPath +="\\guardian.exe"; if (m_fsm.IfInUpgradeProcess() && !m_versionEx.IsNullOrEmpty()) { string xTmp = csBinPath;//路径值 xTmp = xTmp.replace(xTmp.find(m_currentVer), m_currentVer.GetLength(), m_versionEx); if(ExistsFileA(xTmp.c_str())){ csBinPath = xTmp.c_str(); DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("current version:%s,ex version:%s", m_currentVer.GetData(), m_versionEx.GetData()); }else{ DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("ex version file is not exist [%s],use current Version, current version:%s,ex version:%s",xTmp.c_str(),m_currentVer.GetData(), m_versionEx.GetData()); } } csAll = csSep + csBinPath + csSep + " " + staticInfo.strTerminalID;//add terminalno to guardian DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("guardian path[%s], run script[%s]", csBinPath.GetData(), csAll.GetData()); LPTSTR szCmdline = _strdup(csAll); if( !CreateProcessA( NULL,szCmdline,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi)) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("CreateProcess failed (%d).\n", GetLastError()); return false; } return true; #else char app[MAX_PATH]; memset(app, 0, sizeof(app)); tk_process_t* process = NULL; tk_process_option_t option; csBinPath += "/guardian"; sprintf(app, "%s %s %s %d", (const char*)csBinPath, staticInfo.strTerminalID.GetData(), "shouhu", 1); Dbg("path:%s, app:%s", (const char*)csBinPath, (const char*)app); option.exit_cb = NULL; option.file = NULL; option.flags = 0; option.params = app; if (0 == process_spawn(&option, &process)) { Dbg("process_spawn guardian"); FREE(process); return true; } Dbg("end of StartGuardian"); return false; #endif //RVC_OS_WIN } bool CHealthManagerEntity::DoRestart() { LOG_FUNCTION(); CSmartPointer spCerConfig; ErrorCodeEnum err = GetFunction()->OpenConfig(Config_CenterSetting, spCerConfig); if (err != Error_Succeed) { DbgWithLink(LOG_LEVEL_ERROR,LOG_TYPE_SYSTEM)("open cfg file failed!"); return false; } ErrorCodeEnum eErr = GetFunction()->GetSystemStaticInfo(m_sysStaticInfo); if (eErr != Error_Succeed) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("Get system static info failed(%s).", SpStrError(eErr)); m_sysStaticInfo.strMachineType = ""; m_sysStaticInfo.strSite = ""; m_sysStaticInfo.InstallVersion = CVersion(); } m_restartHour = m_restartMinute = 1; //the region (RestartHourBegin,RestartHourEnd) that we should reboot VTM m_rebootHourBegin = 1; m_rebootHourEnd = 6; do { int value(0); spCerConfig->ReadConfigValueInt(GetEntityName(), "RestartHourBegin", value); if (value > 0 && value < 8) { m_rebootHourBegin = value; } } while (false); do { int value(0); spCerConfig->ReadConfigValueInt(GetEntityName(), "RestartHourEnd", value); if (value > 0 && value < 8) { m_rebootHourEnd = value; } } while (false); //to calculate the restartHour & restartMinute of the Terminal ToCalcRebootHourAndMinute(m_rebootHourBegin, m_rebootHourEnd); do { m_maxAbnormalTimes = 30; int value(0); spCerConfig->ReadConfigValueInt(GetEntityName(), "MaxAbnormalTimes", value); if (value > 0) { m_maxAbnormalTimes = value; } } while (false); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("MaxAbnormalTimes:%d", m_maxAbnormalTimes); do { int value(0); spCerConfig->ReadConfigValueInt(GetEntityName(), "StopSelfCheck", value); if (value == 1) { m_stopSelfCheck = 1; } } while (false); DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("m_restartHour:m_restartMinute=%d:%d",m_restartHour,m_restartMinute); CSmartPointer spConfigRun; eErr = GetFunction()->OpenConfig(Config_Run, spConfigRun); spConfigRun->ReadConfigValue("Run", "VersionEx", m_versionEx); //判断上个版本号值是否为空 if(m_versionEx.IsNullOrEmpty()){ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("get VersionEx is null"); } spCerConfig->ReadConfigValueInt(GetEntityName(), "MaxTimeWaitMainPageMS", m_maxWaitMainpageTime); if (m_maxWaitMainpageTime < 5000) m_maxWaitMainpageTime = HEALTHMANAGER_WAIT_MAINPAGE_OPEN_TIMER_INTERVAL; CSimpleStringA csimpleStrMachineTypeCfg; auto rc = spCerConfig->ReadConfigValue("NonExclusive", "NonGuardian", csimpleStrMachineTypeCfg); m_currentVer = m_sysStaticInfo.InstallVersion.ToString(); DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("get current version [%s]", m_currentVer.GetData()); CSimpleStringA csTermStage(""); GetFunction()->GetSysVar("TerminalStage", csTermStage); if(csimpleStrMachineTypeCfg.IndexOf(m_sysStaticInfo.strMachineType)>=0 || csTermStage.Compare("N") == 0)//oilyang@20240104 N for install vtm app { LogWarn(Severity_Low, Error_Unexpect, HealthManager_UserErrorCode_Need_No_Guardian, "terminal is not need start up guardian"); m_bNeedGuardian = false; if (CheckGuardianIsRun() > 0)//or true? { bool bStop = StopGuardian(); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("no need for guardian, to stop guardian:%d", bStop); } //设置一个系统变量给关门页面使用 //liuwt@20220104 N noguardian Y needguardian eErr = GetFunction()->SetSysVar("NeedGuardian","N"); if (eErr != Error_Succeed) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("set NeedGuardian N failed (%s).", SpStrError(eErr)); } } DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("[NonExclusive],NonGuardian=%s", csimpleStrMachineTypeCfg.GetData()); SYSTEMTIME localTime; GetLocalTimeRVC(localTime); ITimerListener *pListener = new TimerOutHelper(this, &CHealthManagerEntity::OnCheckTimeTimeout); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("set check timer %d(ms)", HEALTHMANAGER_TIMER_INTERVAL); GetFunction()->SetTimer(HEALTHMANAGER_TIMER_ID, pListener, HEALTHMANAGER_TIMER_INTERVAL); CSimpleStringA deamonBasePath = ""; err = GetFunction()->GetPath("bin",deamonBasePath); if (err != Error_Succeed) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get bin path failed(%s).", SpStrError(err)); return false; } #if defined(RVC_OS_WIN) deamonBasePath += "\\GuardianBase.dll"; #else deamonBasePath += "/libGuardianBase.so"; #endif DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to check if in upgrade process"); if (m_fsm.IfInUpgradeProcess() && !m_versionEx.IsNullOrEmpty()) { string xTmp(deamonBasePath.GetData()); xTmp = xTmp.replace(xTmp.find(m_currentVer), m_currentVer.GetLength(), m_versionEx); //判断文件是否存在,如果不存在,则启动当前版本guardian. if(ExistsFileA(xTmp.c_str())){ deamonBasePath = xTmp.c_str(); DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("current version:%s,ex version:%s", m_currentVer.GetData(), m_versionEx.GetData()); }else{ DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("ex version guardian dll(so) is not exist ,use current Version file, current version:%s,ex version:%s", m_currentVer.GetData(), m_versionEx.GetData()); } } #if defined(RVC_OS_WIN) DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("guardian file path [%s]", deamonBasePath.GetData()); HMODULE hDll = LoadLibraryA(deamonBasePath); if (hDll == NULL) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("load guardianbase.dll failed(%d)", GetLastError()); return false; } m_pfShake = (pfShakeHands)GetProcAddress(hDll,"ShakeHands"); if (m_pfShake == NULL) { DbgWithLink(LOG_LEVEL_ERROR,LOG_TYPE_SYSTEM)("get ShakeHands function address failed(%d)",GetLastError()); return false; } m_pfUpgradeRestart = (pfUpgradeRestart)GetProcAddress(hDll,"UpgradeRestart"); if (m_pfUpgradeRestart == NULL) { DbgWithLink(LOG_LEVEL_ERROR,LOG_TYPE_SYSTEM)("get UpgradeRestart function address failed(%d)",GetLastError()); return false; } #else DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("guardian file path [%s]", (LPCTSTR)deamonBasePath); void* handle = dlopen(deamonBasePath, RTLD_LAZY); if (handle == NULL) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("load libGuardianBase.so failed(%d)", errno); return false; } m_pfShake = (pfShakeHands)dlsym(handle, "ShakeHands"); if (m_pfShake == NULL) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get ShakeHands failed(%d)", GetLastError()); return false; } m_pfUpgradeRestart = (pfUpgradeRestart)dlsym(handle, "UpgradeRestart"); if (m_pfUpgradeRestart == NULL) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get UpgradeRestart failed(%d)", GetLastError()); return false; } #endif DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("have load guardian base file (dll/so)."); if (CheckGuardianIsRun(true) > 0) { Sleep(500); if (m_bNeedGuardian) { DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("to tell guardian framework is starting."); //tell guardian framework is starting...oilyang 20150514 DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("feedback of framework is starting.%d", m_pfUpgradeRestart(4, 0)); } else { DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("need Upgrade guardian only"); //tell guardian framework we need Upgrade !!!Only!!! oilyang@20211221 DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("feedback of need Upgrade guardian only.%d", m_pfUpgradeRestart(6, 0)); } } return true; } bool CHealthManagerEntity::SaveCurrentVersion() { CSimpleStringA csRootVer,csRunInfo,csBakFile,csVerFile; ErrorCodeEnum eErr; if ((eErr = GetFunction()->GetPath("RootVer",csRootVer)) != Error_Succeed) { DbgWithLink(LOG_LEVEL_ERROR,LOG_TYPE_SYSTEM)("Get version path failed(%s).", SpStrError(eErr)); return false; } if ((eErr = GetFunction()->GetPath("RunInfo",csRunInfo)) != Error_Succeed) { DbgWithLink(LOG_LEVEL_ERROR,LOG_TYPE_SYSTEM)("get runinfo path failed(%s)", SpStrError(eErr)); return false; } #if defined(RVC_OS_WIN) csBakFile = csRunInfo + "\\runcfg\\version.dat"; #else csBakFile = csRunInfo + "/runcfg/version.dat"; #endif ofstream outfile (csBakFile,std::ofstream::binary); CSmartPointer spConfigRun; eErr = GetFunction()->OpenConfig(Config_Run, spConfigRun); if (eErr != Error_Succeed) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("SaveCurrentVersion open run cfg file failed(%s)!", SpStrError(eErr)); return -1; } else spConfigRun->WriteConfigValue("Run", "VersionEx", m_currentVer); int size = m_currentVer.GetLength(); char* buffer = new char[size]; ZeroMemory(buffer,size); //infile.read (buffer,size); memcpy(buffer, m_currentVer,size); outfile.write (buffer,size); delete[] buffer; outfile.close(); //infile.close(); return true; } bool CHealthManagerEntity::SaveFrameStartTimeForUpgrade() { CSimpleStringA csRunInfo,csBakFile; ErrorCodeEnum eErr; if ((eErr = GetFunction()->GetPath("RunInfo",csRunInfo)) != Error_Succeed) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get runinfo path failed(%s)", SpStrError(eErr)); return false; } #if defined(RVC_OS_WIN) csBakFile = csRunInfo + "\\runcfg\\starttime.dat"; #else csBakFile = csRunInfo + "/runcfg/starttime.dat"; #endif ofstream outfile (csBakFile,std::ofstream::binary); CSystemRunInfo sysRunInfo; GetFunction()->GetSystemRunInfo(sysRunInfo); if (eErr != Error_Succeed) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get system run info failed(%s).", SpStrError(eErr)); return false; } CSimpleStringA csStartTime = sysRunInfo.tmStart.ToTimeString(); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get current time start [%s]", csStartTime.GetData()); int size = csStartTime.GetLength(); char* buffer = new char[size]; ZeroMemory(buffer,size); //infile.read (buffer,size); memcpy(buffer,csStartTime,size); outfile.write (buffer,size); delete[] buffer; outfile.close(); //infile.close(); return true; } void CHealthManagerEntity::ReadCenterConfigStr(SpReqAnsContext::Pointer ctx) { if (ctx->Req.key.IsNullOrEmpty() || ctx->Req.entity.IsNullOrEmpty()) ctx->Answer(Error_Param); else { CSimpleStringA str = ""; CSmartPointer spCerConfig; ErrorCodeEnum eErrCode = GetFunction()->OpenConfig(Config_CenterSetting, spCerConfig); if (eErrCode == Error_Succeed) spCerConfig->ReadConfigValue(ctx->Req.entity, ctx->Req.key, str); ctx->Ans.value = str; ctx->Answer(Error_Succeed); } } void CHealthManagerEntity::QueryCenterCfg(SpReqAnsContext::Pointer ctx) { if (ctx->Req.key.IsNullOrEmpty() || ctx->Req.module.IsNullOrEmpty()) ctx->Answer(Error_Param); else { CSimpleStringA str = ""; CSmartPointer spCerConfig; ErrorCodeEnum eErrCode = GetFunction()->OpenConfig(Config_CenterSetting, spCerConfig); if (eErrCode == Error_Succeed) spCerConfig->ReadConfigValue(ctx->Req.module.GetData(), ctx->Req.key, str); ctx->Ans.value = str; ctx->Answer(Error_Succeed); } } void CHealthManagerEntity::GetAuthErrMsg(SpReqAnsContext::Pointer ctx) { LOG_FUNCTION(); CSimpleStringA tmp; GetFunction()->GetSysVar("AuthErrMsg", tmp);//获取错误页信息 DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetAuthErrMsg msg = %s", tmp.GetData()); ctx->Ans.errMsg = tmp; ctx->Answer(Error_Succeed); } void CHealthManagerEntity::OnLog(const CAutoArray& SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel, const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID, const CAutoArray& Param, const char* pszEntityName, const char* pszModuleName, const char* pszMessage, const linkContext& pLinkInfo) { if (dwUserCode != LOG_EVT_IEBROWSER_MOUSE_OP) DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("user code:%x,from entity:%s", dwUserCode, pszEntityName); switch (dwUserCode) { case EVENT_RESTART_SHELL: case Event_Req_Framework_Restart: //case framework restart after upgrade case EVENT_CONSOLE_REQ_RESTART_SHELL: case Event_Req_Framework_Rollback://case after rollback //according to zl commented the following line 20150828 //case EVENT_UKEY_CUSTOMER_MANANAGER_SYS_EXIT: case LOG_EVT_IEBROWSER_RESET_SITE_RESTART: //重设root.ini的site,重启框架 case Event_Req_Framework_No_Upgrade_Restart://升级请求重启框架(体系外升级等等) case Event_Req_Framework_Rollback_Restart: case Event_DeviceAdapterUpgrade_Framework_Restart://适配器升级,重启应用 case Event_DeviceAdapterRollBack_Framework_Restart://适配器回退,重启应用 { //TODO oilyang@20230613 all of the Privilege CMD need to been collated LogWarn(Severity_Low, Error_Unexpect, HealthManager_UserErrorCode_PrivilegeCMD, CSimpleStringA::Format("%x", dwUserCode)); int iCheckGuardian = CheckGuardianIsRun(); if (iCheckGuardian < 0) { bool bStartGuardian = StartGuardian(); if (!bStartGuardian) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Before restart frame,start guardian failed."); break; } DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Before restart frame,start guardian suc."); Sleep(2000); } if (dwUserCode == Event_Req_Framework_Restart) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Event_Req_Framework_Restart.!!!!"); FrameworkRestartTask* task = new FrameworkRestartTask(this); //版本升级,有监控 task->eWarmPageType = WarmPageType_TerminalUpgrade; task->needVerctrl = true; task->eTrigger = RebootTrigger_FrameUpgrade; task->eWay = RebootWay_Framework; GetFunction()->PostThreadPoolTask(task); break; } else if (dwUserCode == Event_Req_Framework_Rollback) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("version rollback succeed.to restart framework"); FrameworkRestartTask* task = new FrameworkRestartTask(this); //心跳重启,无监控 task->eWarmPageType = WarmPageType_HeartBeatRollBack; task->eTrigger = RebootTrigger_RollBack; task->eWay = RebootWay_Framework; GetFunction()->PostThreadPoolTask(task); break; } else if (dwUserCode == Event_Req_Framework_No_Upgrade_Restart) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Event_Req_Framework_No_Upgrade_Restart.!!!!"); FrameworkRestartTask* task = new FrameworkRestartTask(this); //体系外升级,无监控 task->eWarmPageType = WarmPageType_ThirdPartyUpgrade; task->eTrigger = RebootTrigger_ThirdPartyUpgrade; task->eWay = RebootWay_Framework; GetFunction()->PostThreadPoolTask(task); break; } else if (dwUserCode == Event_Req_Framework_Rollback_Restart) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("version rollback succeed.to restart framework"); FrameworkRestartTask* task = new FrameworkRestartTask(this); //回退,无监控 task->eWarmPageType = WarmPageType_UpgradeRollBack; task->eTrigger = RebootTrigger_RollBack; task->eWay = RebootWay_Framework; GetFunction()->PostThreadPoolTask(task); break; } else if (dwUserCode == Event_DeviceAdapterUpgrade_Framework_Restart || dwUserCode == Event_DeviceAdapterRollBack_Framework_Restart) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DeviceAdapter upgrade/rollback succeed.to restart framework"); FrameworkRestartTask* task = new FrameworkRestartTask(this); task->eWarmPageType = WarmPageType_DeviceAdapterUpgrade; task->eTrigger = RebootTrigger_DeviceAdapterUpgrade; task->eWay = RebootWay_Framework; GetFunction()->PostThreadPoolTask(task); break; } m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_Unknown, RebootWay_Framework); } break; case EVENT_RESTART_MACHINE: case Event_Req_OS_Restart://case os restart after outside update case Event_Req_OS_Upgrade_Restart: case EVENT_CONSOLE_REQ_RESTART_POWER: case Event_DeviceAdapterUpgrade_OS_Restart: case Event_DeviceAdapterRollBack_OS_Restart: { LogWarn(Severity_Low, Error_Unexpect, HealthManager_UserErrorCode_PrivilegeCMD, CSimpleStringA::Format("%x", dwUserCode)); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("restart [%x]", dwUserCode); if (dwUserCode == Event_Req_OS_Restart) { FrameworkRestartTask* task = new FrameworkRestartTask(this); task->eTrigger = RebootTrigger_OSUpgrade; task->eWay = RebootWay_OS; GetFunction()->PostThreadPoolTask(task); } else if (dwUserCode == Event_Req_OS_Upgrade_Restart) { FrameworkRestartTask* task = new FrameworkRestartTask(this); task->eWarmPageType = WarmPageType_TerminalUpgrade; task->needVerctrl = true; task->eTrigger = RebootTrigger_OSUpgrade; task->eWay = RebootWay_OS; GetFunction()->PostThreadPoolTask(task); } else if (dwUserCode == Event_DeviceAdapterUpgrade_OS_Restart || dwUserCode == Event_DeviceAdapterRollBack_OS_Restart) { FrameworkRestartTask* task = new FrameworkRestartTask(this); task->eWarmPageType = WarmPageType_DeviceAdapterUpgrade; task->eTrigger = RebootTrigger_DeviceAdapterUpgrade; task->eWay = RebootWay_OS; GetFunction()->PostThreadPoolTask(task); } else m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_Unknown, RebootWay_OS); } break; case LOG_EVT_IEBROWSER_RESTART_MACHINE: { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("machine restart now [%x]", dwUserCode); LogWarn(Severity_Low, Error_Unexpect, LOG_EVT_IEBROWSER_RESTART_MACHINE, "ClosePage/UserDeskTop to call restart machine."); m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_Unknown, RebootWay_OS); break; } case LOG_EVT_IEBROWSER_SHUTDOWN_MACHINE: { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ClosePage/UserDeskTop to call shutdown machine. [%x]", dwUserCode); LogWarn(Severity_Low, Error_Unexpect, LOG_EVT_IEBROWSER_SHUTDOWN_MACHINE, "ClosePage/UserDeskTop to call shutdown machine."); m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_DeadForever, RebootWay_OS); break; } case EVENT_MOD_SIP_RESART: DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SIPPhone said to wait chance to restart(power) pc."); m_bWaitRestartPC = true; break; case EVENT_ACCESSAUTH_SUCCEED: { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501B1")("access auth succeed."); m_fsm.SetVtmLoadResult(VtmLoad_AccessAuth_Suc); m_bNeedAuthRetry = false; m_bNeedGuardianRestart = true; m_dwTimeOfAuthSuc = SP::Module::Comm::RVCGetTickCount() / 1000; GetFunction()->SetTimer(HEALTHMANAGER_WAIT_MAINPAGE_OPEN_TIMER_ID, this, m_maxWaitMainpageTime); CSimpleStringA msg(true); GetFunction()->GetSysVar("AuthErrMsg", msg); Dbg("AuthErrMsg 在healthmanager的内容是: %s.", msg.GetData()); if (msg.GetLength() != 0) { WarnPromptTask* task = new WarnPromptTask(this); //通过工作线程弹窗并告警 GetFunction()->PostThreadPoolTask(task); } ITimerListener* pListener = new TimerOutHelper(this, &CHealthManagerEntity::OnSelfCheckTimeout); GetFunction()->SetTimer(HEALTHMANAGER_SELFCHECK_TIMER_ID, pListener, HEALTHMANAGER_SELFCHECK_TIMER_INTERVAL); break; } //oilyang@20210331 distinguish reasons of accessauth failed to decide what to do next //case EVENT_ACCESSAUTH_FAILED: //case EVENT_ACCESSAUTH_TIMEOUT: case CONTROL_ACCESSAUTH_NORETRY_NORESTART: case CONTROL_ACCESSAUTH_RETRY_NORESTART: case CONTROL_ACCESSAUTH_RETRY_RESTART: case CONTROL_ACCESSAUTH_UNKNOWN: { if (dwUserCode == CONTROL_ACCESSAUTH_NORETRY_NORESTART) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501F1").setResultCode("RTA5108")("receive accessauth failed result:%d. no retry,no restart.", dwUserCode); m_bNeedAuthRetry = false; m_bNeedGuardianRestart = false; } else if (dwUserCode == CONTROL_ACCESSAUTH_RETRY_NORESTART) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501F1").setResultCode("RTA5109")("receive accessauth failed result:%d. retry,no restart.", dwUserCode); m_bNeedAuthRetry = true; m_bNeedGuardianRestart = false; } else if (dwUserCode == CONTROL_ACCESSAUTH_RETRY_RESTART) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501F1").setResultCode("RTA510A")("receive accessauth failed result:%d. retry,restart.", dwUserCode); m_bNeedAuthRetry = true; m_bNeedGuardianRestart = true; } else if (dwUserCode == CONTROL_ACCESSAUTH_UNKNOWN) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501F1").setResultCode("RTA510B")("receive accessauth failed result:%d. unknown access failed.no retry,restart.", dwUserCode); m_bNeedAuthRetry = false; m_bNeedGuardianRestart = true; } m_fsm.SetVtmLoadResult(VtmLoad_AccessAuth_Fail); if (m_bNeedAuthRetry) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501F2")("retry AccessAuth"); m_fsm.ToReAccessAuth(); } } break; case ERR_ACCESSAUTH_SERVICE_FAILED: //准入服务告知禁止此终端准入,无需重试,无需guardian重启 { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501F1").setResultCode("RTA510C")("service forbid this terminal, no retry, no restart:(usercode)%d", dwUserCode); m_bNeedAuthRetry = false; m_bNeedGuardianRestart = false; m_fsm.SetVtmLoadResult(VtmLoad_AccessAuth_servFail); } //m_fsm.SetVtmLoadResult(VtmLoad_AccessAuth_Suc);//oiltest break; case EVENT_MOD_RELEASESIP_TIMEOUT: DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("RELEASESIP_TIMEOUT."); RestartModule("SIPPhone"); break; case LOG_EVT_HEALTHMANAGER_BROWSER_IDLE: //IE重启之后,重置是否进入主页变量 DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Browser(Chromuim) to idle."); LogWarn(Severity_Low, Error_Unexpect, HealthManager_UserErrorCode_Receive_Browser_Idle , "Browser(Chromuim) to idle."); break; case LOG_EVT_PINPAD_OPEN_SUC: DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PinPad open suc."); m_fsm.SetPinPadOpenSuc(); break; case EVENT_MOD_CENTERSETTING_CRITICAL_UPDATE: DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CenterSetting update some critical item,we need to restart framework."); m_bToRestartByCenterSetting = true; break; default: //Dbg("unknown event(%d)...", dwUserCode); return; } } void CHealthManagerEntity::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_bInMainPage = true; if (!CheckIfHaveEnterMainPageEver()) { CSystemRunInfo sysRunInfo; if (GetFunction()->GetSystemRunInfo(sysRunInfo) != Error_Succeed || sysRunInfo.eAppBootState == AppBootState_CallAccessAuth) GetFunction()->GetPrivilegeFunction()->RefreshAppBootState(AppBootState_FirstEnterMainPage); CSmartPointer spConfigRun; ErrorCodeEnum eErr = GetFunction()->OpenConfig(Config_Run, spConfigRun); spConfigRun->WriteConfigValueInt("Run", "UpgradeRestartTimes", 0); spConfigRun->WriteConfigValueInt("Run", "UpgradeRestartOSTimes", 0); ULONGLONG dwElapse = SP::Module::Comm::RVCGetTickCount();//使用机器启动时间秒数 DWORD elapseTimeTemp = dwElapse / 1000; DWORD dwToMainPageCostTime = elapseTimeTemp - m_dwTimeOfAuthSuc;//从准入通过到首次收到进入首页事件 CSimpleStringA xMsg = CSimpleStringA::Format("{\"Decripstion\":\"the first enter main page from HealthManger started.\",\"version\":\"%s\",\"elapseTime\":\"%d\",\"enterMainPageTime\":\"%d\"}" , m_sysStaticInfo.InstallVersion.ToString().GetData(), elapseTimeTemp, dwToMainPageCostTime); LogWarn(Severity_Low, Error_Unexpect, LOG_EVT_HEALTH_FIRST_ENTER_MAINPADE_FROM_HEALTH_START, xMsg.GetData()); //oilyang@20230518 最大设置时间的3倍、2倍、1倍还没进入首页 if (dwToMainPageCostTime > m_maxWaitMainpageTime / 1000 * 3) DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501B2").setResultCode("RTA5106").setCostTime(dwToMainPageCostTime)(m_sysStaticInfo.InstallVersion.ToString().GetData()); else if (dwToMainPageCostTime > m_maxWaitMainpageTime / 1000 * 2) DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501B2").setResultCode("RTA5105").setCostTime(dwToMainPageCostTime)(m_sysStaticInfo.InstallVersion.ToString().GetData()); else if (dwToMainPageCostTime > m_maxWaitMainpageTime / 1000) DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501B2").setResultCode("RTA5104").setCostTime(dwToMainPageCostTime)(m_sysStaticInfo.InstallVersion.ToString().GetData()); else DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501B2").setCostTime(dwToMainPageCostTime)(m_sysStaticInfo.InstallVersion.ToString().GetData()); } } else m_bInMainPage = false; } } void CHealthManagerEntity::OnBroadcastEvent(CUUID SubID, const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, CAutoBuffer Buffer) { } void CHealthManagerEntity::OnTimeout(DWORD dwTimeID) { switch (dwTimeID) { case HEALTHMANAGER_WAIT_MAINPAGE_OPEN_TIMER_ID: if (!CheckIfHaveEnterMainPageEver()) DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setResultCode("RTA5101") ("After receive accessauth success event, havn't receive enter main page.", m_maxWaitMainpageTime / 1000); break; default: break; } } bool CHealthManagerEntity::StartManagerDesktopPage(CSimpleStringA pageName) { Sleep(10000); ChromiumSrv_ClientBase* chromiumClient = new ChromiumSrv_ClientBase(this); ErrorCodeEnum error = chromiumClient->Connect(); if (error == Error_Succeed) { ChromiumSrv_OpenBrowser_Req req; ChromiumSrv_OpenBrowser_Ans ans; int width = 0; int height = 0; #ifdef RVC_OS_WIN width = GetSystemMetrics(SM_CXSCREEN); height = GetSystemMetrics(SM_CYSCREEN); #else struct winsize size; ioctl(STDIN_FILENO, TIOCGWINSZ, &size); width = size.ws_row; height = size.ws_col; #endif // RVC_OS_WIN auto pFunc = GetFunction(); CSimpleStringA strPath, statusPagePath, fileStart; fileStart = "file:///"; pFunc->GetPath("Bin", strPath); strPath += "\\Chromium\\cefclient.exe"; pFunc->GetPath("Bin", statusPagePath); statusPagePath = statusPagePath + CSimpleStringA("/../res/ManagerDesktop/") + pageName; statusPagePath = fileStart + statusPagePath; req.mainUrl = statusPagePath; req.type = "SpecialPageFromOtherEntity"; req.name = "tempMessage"; req.param1 = CSimpleStringA::Format("%d*%d", width, height); req.param2 = CSimpleStringA::Format("0*0"); req.top = -1; error = (*chromiumClient)(EntityResource::getLink().upgradeLink())->OpenBrowser(req, ans, 10000); chromiumClient->GetFunction()->CloseSession(); if (error != Error_Succeed) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Start chromium page [%s] failed.", statusPagePath.GetData()); return false; } else { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Start chromium page [%s] success.", statusPagePath.GetData()); return true; } } return false; } void CHealthManagerEntity::WarnAndRestartFunc(RebootTriggerEnum eTrigger, RebootWayEnum eWay, WarmPageTypeEnum eWarmPageType, bool needVerctrl) { switch (eWarmPageType) { case WarmPageType_TerminalUpgrade: StartManagerDesktopPage("TerminalUpgradeRestart.html"); Sleep(5000);//oiltmp to be defined ??? break; case WarmPageType_DeviceAdapterUpgrade: StartManagerDesktopPage("DeviceAdapterUpgradeRestart.html"); Sleep(5000);//oiltmp to be defined ??? break; case WarmPageType_HeartBeatRollBack: StartManagerDesktopPage("HeartBeatRollBackRestart.html"); Sleep(5000);//oiltmp to be defined ??? break; case WarmPageType_UpgradeRollBack: StartManagerDesktopPage("UpgradeRollBackRestart.html"); Sleep(5000);//oiltmp to be defined ??? break; case WarmPageType_ThirdPartyUpgrade: StartManagerDesktopPage("ThirdPartyUpgradeRestart.html"); Sleep(5000);//oiltmp to be defined ??? break; case WarmPageType_None: default: break; } if (needVerctrl) { SaveCurrentVersion(); SaveFrameStartTimeForUpgrade(); if (CheckGuardianIsRun(true) > 0) { ErrorCodeEnum eErr = Error_Unexpect; //Dbg("to tell guardian framework is restarting.%d",eErr); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to tell guardian framework is restarting.%d", m_pfUpgradeRestart(1, 0)); } DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("framework shutdown in restart task"); } m_fsm.QuitFrameworkAndSaveInfo(eTrigger, eWay); } namespace { ErrorCodeEnum SplitAdapterFileName(CSimpleStringA strFileName, CAutoArray& values) { #ifdef RVC_OS_WIN CSimpleStringA strPrefix(""); CSimpleStringA strSuffix(".dll"); #else CSimpleStringA strPrefix("lib"); CSimpleStringA strSuffix(".so"); #endif //RVC_OS_WIN if (strFileName.GetLength() < strPrefix.GetLength() + strSuffix.GetLength()) { return Error_Param; } CSimpleStringA pureAdapterName = strFileName.SubString( strPrefix.GetLength(), strFileName.GetLength() - strPrefix.GetLength() - strSuffix.GetLength()); values = pureAdapterName.Split('.'); if (values.GetCount() != 4) { return Error_DataCheck; } return Error_Succeed; } } void CHealthManagerEntity::OnEntityStateHook(const char* pszEntityName, const char* pszTriggerEntity, EntityStateEnum eState, EntityStateEnum eLastState) { if (m_fsm.CheckIsRebooting())//oilyang@20250415 no need to process entity state changing event while in rebooting return; CSmartPointer pFunc = GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); if (pFuncPrivilege == NULL) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("NoPrivilege"); return; } CSmartPointer spWait; ErrorCodeEnum errCode; { switch (eState) { case EntityState_Lost: { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("%s trigger by %s: from %s to %s", pszEntityName, pszTriggerEntity, SpStrEntityState(eLastState), SpStrEntityState(eState)); CSimpleStringA tmpWarnMsg = CSimpleStringA::Format("%s lost. trig entity:%s,lastState:%s", pszEntityName, pszTriggerEntity, SpStrEntityState(eLastState)); CEntityStaticInfo esi = { 0 }; ErrorCodeEnum ec = GetFunction()->GetEntityStaticInfo(pszEntityName, esi); //0x101 0x21D int iByteHigh, iByteLow; iByteHigh = (esi.wEntityDevelopID & 0xF00) >> 8; iByteLow = esi.wEntityDevelopID & 0xFF; if (iByteHigh < 1 || iByteHigh > 9) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("Unexpected entity id:%x", esi.wEntityDevelopID); break; } CSimpleStringA csResultCode(true); //实体lost的RTAxxxx的后两位xx,规则同RTAxxxx的前两位xx(实体标识码),由实体编号自动生成。健康实体本身的自定义RTAxxxx应该避开这些自定义 //'0':0x30 'A':0x41 if (iByteLow > 0 && iByteLow < 10) csResultCode = CSimpleStringA::Format("RTA51%c%c", iByteHigh + 0x30, iByteLow + 0x30); else csResultCode = CSimpleStringA::Format("RTA51%c%c", iByteHigh + 0x30, iByteLow - 10 + 0x41); DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("resultcode:%s", csResultCode.GetData()); LogWarn(Severity_High, Error_Unexpect, HealthManager_UserErrorCode_EntityLost_Start + esi.wEntityDevelopID, tmpWarnMsg.GetData()); DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501S1").setResultCode(csResultCode.GetData())(tmpWarnMsg.GetData()); //doing nothing before enter main page. HandShake will take it. //AND if selfcheck is doing, no action at all if (CheckIfHaveEnterMainPageEver() && m_modRunInfo[pszEntityName].abnormalCount < m_maxAbnormalTimes && !m_modRunInfo[pszEntityName].bAbnormalBusy) { m_modRunInfo[pszEntityName].bAbnormalBusy = true; m_modRunInfo[pszEntityName].abnormalCount++; EntityLostProcTask* task; task = new EntityLostProcTask(this, pszEntityName); GetFunction()->PostThreadPoolTask(task); } } break; case EntityState_Idle: { if (_strnicmp("Chromium", pszEntityName, strlen("Chromium")) == 0) LogEvent(Severity_Middle, LOG_EVT_HEALTHMANAGER_BROWSER_IDLE, "Chromium to idle."); } default: break; } } } void CHealthManagerEntity::ToCalcRebootHourAndMinute(int restartBegin, int restartEnd) { if (m_sysStaticInfo.strTerminalID.GetLength() < 6) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("wrong terminalNo:[%s]", m_sysStaticInfo.strTerminalID.GetData()); return; } if ((restartBegin <= 0 || restartEnd <= 0) || restartEnd < restartBegin || restartEnd > 7) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("wrong setting,restartBegin:%d,restartEnd:%d, use default (1-6)", restartBegin, restartEnd); restartBegin = 1; restartEnd = 6; } //以1分钟对重启区间进行切片,截取终端号前6位+最后1位,进行取模hash到重启区间 int modNum = (restartEnd - restartBegin) * 60 -1;//if the modNum like 300 or 200 ,the remainder is not random ,because the TerminalNo is not random int xTerm = atoi(m_sysStaticInfo.strTerminalID.SubString(0, 6) + m_sysStaticInfo.strTerminalID.SubString(m_sysStaticInfo.strTerminalID.GetLength() - 1, 1)); int minutes = xTerm % modNum; m_restartHour = 1 + (minutes / 60); m_restartMinute = minutes - (m_restartHour - 1) * 60; DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("restartBegin:%d, restartEnd:%d, xTerm:%d, minutes:%d, m_restartHour:%d, m_restartMinute:%d", restartBegin, restartEnd, xTerm, minutes, m_restartHour, m_restartMinute); } void CHealthManagerEntity::RealCheck(SpReqAnsContext::Pointer ctx) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501R1")("%s", ctx->Req.name.GetData()); CheckEntity(ctx->Req.name, Test_ShakeHand); ctx->Answer(Error_Succeed); } void CHealthManagerEntity::OnAnswer(CSmartPointer pAsynWaitSp) { CSmartPointer spCallback; CSmartPointer pData; pAsynWaitSp->GetCallback(spCallback, pData); //LOG_ASSERT(pData); callback_entry* entry = dynamic_cast((IReleasable*)pData.GetRawPointer()); entry->ErrorResult = pAsynWaitSp->AsyncGetAnswer(); callback_entry* new_entry = new callback_entry(); new_entry->EntityName = entry->EntityName; new_entry->ErrorResult = entry->ErrorResult; new_entry->op = entry->op; new_entry->state = entry->state; if (new_entry->op == Test_ShakeHand && new_entry->ErrorResult != Error_Succeed) { if (!m_modRunInfo[new_entry->EntityName].bAbnormalBusy) { ExceptionErrorProcess((const char*)new_entry->EntityName, new_entry->ErrorResult); std::map msgInfo; msgInfo["EntityName"] = new_entry->EntityName.GetData(); msgInfo["EntityState"] = SpStrEntityState((EntityStateEnum)new_entry->state); msgInfo["SelfTestReturnCode"] = SpStrError(new_entry->ErrorResult); std::pair strResult; strResult = generateJsonStr(msgInfo); DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501S2")(strResult.second.c_str()); } } } ErrorCodeEnum CHealthManagerEntity::ExceptionErrorProcess(const char* pszEntityName, ErrorCodeEnum eTestResult) { CSmartPointer pFunc = GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); CSmartPointer spWait; ErrorCodeEnum eErrCode = Error_Unexpect; switch (eTestResult) { case Error_TimeOut: case Error_Unexpect: case Error_InvalidState: { m_modRunInfo[pszEntityName].bAbnormalBusy = true; DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ExceptionErrorProcess %s, abnormalCount:%d", pszEntityName, m_modRunInfo[pszEntityName].abnormalCount); m_modRunInfo[pszEntityName].abnormalCount++; eErrCode = pFuncPrivilege->StopEntity(pszEntityName, spWait); if (eErrCode == Error_Succeed) { eErrCode = spWait->WaitAnswer(MAX_STOP_AYSNC_TIMEOUT); if (eErrCode != Error_Succeed) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("spwait stop %s failed: %s.", pszEntityName, SpStrError(eErrCode)); eErrCode = pFuncPrivilege->TerminateEntity(pszEntityName, spWait); eErrCode = spWait->WaitAnswer(MAX_TERM_AYSNC_TIMEOUT); if (eErrCode != Error_Succeed) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("spwait terminate %s failed: %s.", pszEntityName, SpStrError(eErrCode)); m_modRunInfo[pszEntityName].bAbnormalBusy = false; break; } } } else { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Stop %s failed(%d).", pszEntityName, eErrCode); m_modRunInfo[pszEntityName].bAbnormalBusy = false; break; } Sleep(2000); eErrCode = pFuncPrivilege->StartEntity(pszEntityName, NULL, spWait); if (eErrCode == Error_Succeed) { eErrCode = spWait->WaitAnswer(MAX_START_AYSNC_TIMEOUT); if (eErrCode != Error_Succeed) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("spwait start %s failed(%d).", pszEntityName, eErrCode); m_modRunInfo[pszEntityName].bAbnormalBusy = false; break; } DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Start entity %s suc.", pszEntityName); } else { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("(re)Start %s failed(%d).", pszEntityName, eErrCode); m_modRunInfo[pszEntityName].bAbnormalBusy = false; break; } m_modRunInfo[pszEntityName].bAbnormalBusy = false; } break; default: break; } return eErrCode; } ErrorCodeEnum CHealthManagerEntity::CheckEntity(const char* pszEntityName, EntityTestEnum eTestType) { //oilyang@20170926 no need to check by self.Let the HealthManager entity to do it. //oilyang@20231106 no need to check VtmLoader if (pszEntityName != NULL && (strnicmp(pszEntityName, GetEntityName(), strlen(GetEntityName())) == 0 || strnicmp(pszEntityName, "VtmLoader", strlen("VtmLoader")) == 0)) return Error_Succeed; CSmartPointer pFunc = GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); CSmartPointer spWait; ErrorCodeEnum errCode; errCode = pFuncPrivilege->TestEntity(pszEntityName, eTestType, spWait); if (errCode == Error_Succeed) { callback_entry* entry = new callback_entry(); entry->pRawData = NULL; entry->EntityName = pszEntityName; entry->ErrorResult = Error_Unexpect; entry->op = Test_ShakeHand; spWait->SetCallback(this, entry); } else DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Test %s,%d", pszEntityName, errCode); return errCode; } void CHealthManagerEntity::OnSelfCheckTimeout() { if (m_stopSelfCheck == 1 || m_fsm.CheckIsRebooting()) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop self check OR is rebooting"); return; } CSmartPointer pFunc = GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); CSmartPointer spWait; ErrorCodeEnum errCode; int activeEnCount = m_activeEntity.GetCount(); //oilyang@20230426 ,常规自检时,针对"TerminalStage"做对应处理(自检分常规自检和即时自检) //"S":准入服务告知准入不过,不再进行实体自检 //非"A":其他启动失败导致进关门页,不再对硬件以及其他没必要自检的实体进行自检 CSimpleStringA tmpTerminalStage(""); GetFunction()->GetSysVar("TerminalStage", tmpTerminalStage); for (int i = 0; i < activeEnCount; ++i) { if (m_fsm.CheckIsRebooting()) break; CSimpleStringA pszEntityName(m_activeEntity[i]); //invalid or "HealthManager" itself,no need to check // if (m_activeEntity[i].IsNullOrEmpty() || m_activeEntity[i].Compare(GetEntityName()) == 0) continue; if (tmpTerminalStage.Compare("S") == 0) continue; else if (tmpTerminalStage.Compare("A") != 0) { //the hardward entity and some other entity no need to test if (_strnicmp("PinPad", pszEntityName, strlen("PinPad")) == 0 || _strnicmp("CardIssuerStand", pszEntityName, strlen("CardIssuerStand")) == 0 || _strnicmp("CardIssuerStore", pszEntityName, strlen("CardIssuerStore")) == 0 || _strnicmp("ContactlessCard", pszEntityName, strlen("ContactlessCard")) == 0 || _strnicmp("IDCertificate", pszEntityName, strlen("IDCertificate")) == 0 || _strnicmp("gpio", pszEntityName, strlen("gpio")) == 0 || _strnicmp("HSPScanner", pszEntityName, strlen("HSPScanner")) == 0 || _strnicmp("FingerPrint", pszEntityName, strlen("FingerPrint")) == 0 ) continue; } //oilyang@20240524 abnormal within MAX limited times, AND NOT in lost process, else no check at all if (m_modRunInfo[pszEntityName].abnormalCount < m_maxAbnormalTimes && !m_modRunInfo[pszEntityName].bAbnormalBusy) CheckEntity(m_activeEntity[i].GetData(), Test_ShakeHand); } GetFunction()->ResetTimer(HEALTHMANAGER_SELFCHECK_TIMER_ID, HEALTHMANAGER_SELFCHECK_TIMER_INTERVAL); } void CHealthManagerEntity::EntityLostProc(CSimpleStringA entityName) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("EntityLostProc %s, lost %d times from VTM started", entityName.GetData(), m_modRunInfo[entityName].abnormalCount); CSmartPointer pFunc = GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); CSmartPointer spWait; ErrorCodeEnum eErrCode = pFuncPrivilege->TerminateEntity(entityName, spWait); if (eErrCode == Error_Succeed) { eErrCode = spWait->WaitAnswer(10000); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("on lost kill wait %d", eErrCode); } else DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("on lost kill %d", eErrCode); Sleep(5000); eErrCode = pFuncPrivilege->StartEntity(entityName, NULL, spWait); if (eErrCode == Error_Succeed) { eErrCode = spWait->WaitAnswer(10000); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("on lost start wait %d", eErrCode); } else DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("on lost start %d", eErrCode); if (CheckIfHaveEnterMainPageEver() && _strnicmp("TokenKeeper", entityName, strlen("TokenKeeper")) == 0) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("TokenKeeper lost"); m_fsm.ToReAccessAuth(); } m_modRunInfo[entityName].bAbnormalBusy = false; } bool CHealthManagerEntity::CheckIfHaveEnterMainPageEver() { if (!m_bSayIdle) { CSystemRunInfo sysRunInfo; if (GetFunction()->GetSystemRunInfo(sysRunInfo) == Error_Succeed && sysRunInfo.eAppBootState == AppBootState_FirstEnterMainPage) return true; else return false; } else return true; } SP_BEGIN_ENTITY_MAP() SP_ENTITY(CHealthManagerEntity) SP_END_ENTITY_MAP()