#include "stdafx.h" #define WIN32_LEAN_AND_MEAN #include "SelfCheckerFSM.h" #include "SpHelper.h" #include "EventCode.h" #pragma comment(lib,"user32.lib") class CSelfCheckerEntity; const int MAX_AYSNC_TIMEOUT = 60000; const int MAX_CHECK_TIME = 60000; const int MAX_CPU_CHECK_TIME = 5000; const int TIMER_ID_CHECK = 0; const int TIMER_CPU_CHECK = 1; const int THOUSAND = 1024; const int MILLION = 1048576; int ActionStrToInt(const char *pAction) { int ret = 0; char x = *pAction; if (x >= '0' && x <= '9') return x - '0'; else return 0; } DWORD GetRadixProduct(int times,int radix) { DWORD dwRet = 1; if (times < 0 || (radix != 10 && radix != 16)) return 0; else { for (int i = 0; i < times; i++) dwRet *= radix; } return dwRet; } DWORD CodeStrToInt(const char *pCode) { CSimpleStringA csCode(pCode); csCode = csCode.Trim(); int len = csCode.GetLength(); if (len < 0 || len > 10) { return 0; } DWORD dwRet = 0; if (len > 2 && csCode[0] == '0' && (csCode[1] == 'x' || csCode[1] == 'X'))//"0x1234,0X12FF" { for (int i = 2; i < len; i++) { if (csCode[i] <= '9' && csCode[i] >= '0') dwRet += (csCode[i] - '0')*GetRadixProduct(len - i - 1,16); else if (csCode[i] <= 'f' && csCode[i] >= 'a') dwRet += (csCode[i] - 'a' + 10)*GetRadixProduct(len - i - 1,16); else if (csCode[i] <= 'F' && csCode[i] >= 'A') dwRet += (csCode[i] - 'A' + 10)*GetRadixProduct(len - i - 1, 16); else return 0;//because there is a invalid char,break process and return 0 } } else//"768" { for (int i = 0; i < len; i++) { if (csCode[i] <= '9' && csCode[i] >= '0') dwRet += (csCode[i] - '0')*GetRadixProduct(len - i - 1, 10); else return 0;//because there is a invalid char,break process and return 0 } } return dwRet; } unsigned long long GetTickCountRVC() { #ifdef RVC_OS_WIN return GetTickCount64(); #else struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000); #endif //RVC_OS_WIN } ErrorCodeEnum CSelfCheckerFSM::OnInit() { m_xIdlePre = m_xKernelPre = m_xUserPre = 0; ErrorCodeEnum errCode = Initial(); if (errCode != Error_Succeed) return Error_IO; return Error_Succeed; } ErrorCodeEnum CSelfCheckerFSM::OnExit() { return Error_Succeed; } void CSelfCheckerFSM::s0_on_entry() { LOG_FUNCTION(); ErrorCodeEnum errCode; CAutoArray tmpInstIDs; CAutoArray tmpNames; errCode = GetEntityBase()->GetFunction()->GetAllRegistedEntity(tmpNames,tmpInstIDs); if (errCode != Error_Succeed) { Dbg("Get started entity failed.[%d]",errCode); } for (int i = 0; i < tmpNames.GetCount(); ++i) { ErrorCodeEnum eErr; CSmartPointer pFunc = GetEntityBase()->GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); CEntityRunInfo runInfo; eErr = pFunc->GetEntityRunInfo(tmpNames[i], runInfo); if (runInfo.eState != EntityState_NoStart) { Dbg("Add entity %s",(const char*)tmpNames[i]); m_allEntity.push_back(tmpNames[i]); m_activeEntity.push_back(tmpNames[i]); } } //m_pEntity-> m_entityNames.push_back(tmpNames[i]); FSMEvent *pEvt = new FSMEvent(USER_EVT_INIT); PostEventFIFO(pEvt); } void CSelfCheckerFSM::s0_on_exit() { LOG_FUNCTION(); } unsigned int CSelfCheckerFSM::s0_on_event(FSMEvent* pEvt) { LOG_FUNCTION(); switch(pEvt->iEvt) { case USER_EVT_INIT: pEvt->SetHandled(); break; default: break; } return 0; } void CSelfCheckerFSM::s1_on_entry() { LOG_FUNCTION(); void *pTmpData = NULL; ITimerListener *pListener = new TimerOutHelper(this, &CSelfCheckerFSM::OnNormalWorkTimerout,pTmpData); GetEntityBase()->GetFunction()->SetTimer(TIMER_ID_CHECK, pListener, MAX_CHECK_TIME); //oilyang@20170703 add for cpu usage for process pTmpData = NULL; pListener = new TimerOutHelper(this, &CSelfCheckerFSM::OnCalcCpuUsageTimerout, pTmpData); GetEntityBase()->GetFunction()->SetTimer(TIMER_CPU_CHECK, pListener, MAX_CPU_CHECK_TIME); } void CSelfCheckerFSM::s1_on_exit() { LOG_FUNCTION(); } unsigned int CSelfCheckerFSM::s1_on_event(FSMEvent* evt) { LOG_FUNCTION(); return 0; } void CSelfCheckerFSM::s2_on_entry() { LOG_FUNCTION(); } void CSelfCheckerFSM::s2_on_exit() { LOG_FUNCTION(); } unsigned int CSelfCheckerFSM::s2_on_event(FSMEvent* evt) { LOG_FUNCTION(); return 0; } void CSelfCheckerFSM::s3_on_entry() { LOG_FUNCTION(); } void CSelfCheckerFSM::s3_on_exit() { LOG_FUNCTION(); } unsigned int CSelfCheckerFSM::s3_on_event(FSMEvent* evt) { LOG_FUNCTION(); return 0; } int ch2int(char ch) { if (ch >= '0' && ch <= '9') return ch-'0'; else if (ch >= 'a' && ch <= 'f') return ch-'a'+10; else if (ch >= 'A' && ch <= 'F') return ch-'A'+10; return 0; } long hexstr2int(const char *str, int len) { long result = 0; for (int i = 0; i < len; ++i) { result += (ch2int(str[i]) << ((len-i-1)*4)); } return result; } bool StrEqualNoCase(const char *s1, const char *s2,int len) { if (strlen(s1) != strlen(s2)) return false; for (int i = 0; i < len; ++i) { if (toupper(s1[i]) != toupper(s2[i])) return false; } return true; } ErrorCodeEnum CSelfCheckerFSM::Initial() { ErrorCodeEnum err; CSmartPointer spConfig; err = GetEntityBase()->GetFunction()->OpenConfig(Config_Software, spConfig); if (err != Error_Succeed) { Dbg("open cfg file failed!"); return Error_IO; } m_restartNormal = 3; m_restartSpecial = 5; m_maxOsRestart = 5; m_maxPowerRestart = 5; spConfig->ReadConfigValueInt("init","RestartNormal",m_restartNormal); spConfig->ReadConfigValueInt("init","RestartSpecial",m_restartSpecial); spConfig->ReadConfigValueInt("init","MaxOsRestart",m_maxOsRestart); spConfig->ReadConfigValueInt("init","MaxPowerRestart",m_maxPowerRestart); spConfig->ReadConfigValueInt("init","SimulateTestFlag",m_simulateTest); spConfig->ReadConfigValue("init","KeyEntity",m_csKeyEntity); spConfig->ReadConfigValueInt("init","CpuTooHighPercent",m_cpuHighPercent); spConfig->ReadConfigValueInt("init","MemoryTooHighPercent",m_memHighPercent); spConfig->ReadConfigValueInt("init","HardDiskTooHighPercent",m_diskHighPercent); ifstream is; CSimpleStringA cfgPath(""),cfgXml(""); err = GetEntityBase()->GetFunction()->GetPath("cfg",cfgPath); //cfgPath = cfgPath + "\\SelfChecker.ini"; cfgXml = cfgPath + "/SelfCheckerProc.xml"; ReadXmlFile(cfgXml); Dbg("cfgxml[%s]", cfgXml); //is.open (cfgPath, ios::binary); //if (!is.is_open()) // return Error_IO; //string line; //long curr,end; //is.seekg(0,ios_base::end); //end = is.tellg(); //is.seekg(0,ios_base::beg); //CheckPattern eSection = CHECK_UNKNOWN; ////load config file //do //{ // getline(is,line); // if (line[0] == '[') // { // size_t secEnd = line.find(']',1); // if (secEnd != string::npos) // { // string strSec = line.substr(1,secEnd-1); // if (StrEqualNoCase(strSec.c_str(),"ShakeHand",strSec.length())) // eSection = CHECK_HANDSHAKE; // else if (StrEqualNoCase(strSec.c_str(),"Examine",strSec.length())) // eSection = CHECK_EXAMINE; // else if (StrEqualNoCase(strSec.c_str(),"Reset",strSec.length())) // eSection = CHECK_RESET; // else if (StrEqualNoCase(strSec.c_str(),"Restart",strSec.length())) // eSection = CHECK_RESTART; // else // eSection = CHECK_UNKNOWN; // } // } // else if (((unsigned)(line[0]+1) > 256) || line[0] == ';') // {//Chinese and other... // curr = is.tellg(); // continue; // } // else if (isalpha(line[0])) // { // if (eSection == CHECK_UNKNOWN) // { // curr = is.tellg(); // continue; // } // size_t keyPos = line.find('=',0); // if (keyPos != string::npos) // { // string keyName = line.substr(0,keyPos); // size_t douPos = line.find(',',keyPos); // size_t fenPos,start = keyPos; // m_entCfgInfo[keyName.c_str()].entityRestartCount = 0; // m_entCfgInfo[keyName.c_str()].osRestartCount = 0; // m_entCfgInfo[keyName.c_str()].powerRestartCount = 0; // m_entCfgInfo[keyName.c_str()].bWaitRestart = false; // for (;douPos != string::npos;) // { // ErrorCodeEnum evtCode = (ErrorCodeEnum)hexstr2int(line.substr(start+1+2,douPos-start-2-1).c_str(),douPos-start-2-1); // fenPos = line.find(';',douPos); // TestActionEnum actCode; // if (fenPos != string::npos) // { // actCode = (TestActionEnum)atoi(line.substr(douPos+1,fenPos-douPos-1).c_str()); // } // else // { // int xx = line.length()-douPos-1; // actCode = (TestActionEnum)atoi(line.substr(douPos+1,line.length()-douPos-1).c_str()); // } // switch(eSection) // { // case CHECK_HANDSHAKE: // m_entCfgInfo[keyName.c_str()].hsInfo[evtCode] = actCode; // break; // case CHECK_EXAMINE: // break; // case CHECK_RESET: // m_entCfgInfo[keyName.c_str()].resetInfo[evtCode] = actCode; // break; // case CHECK_RESTART: // break; // } // douPos = line.find(',',fenPos); // start = fenPos; // } // } // } // curr = is.tellg(); //}while(curr < end); auto list = m_csKeyEntity.Split(','); for (int i = 0; i < list.GetCount(); ++i) { CSimpleStringA entity = list[i]; Dbg("%s",LPCTSTR(entity)); m_vKeyEntity.push_back(entity); } CSystemStaticInfo sysInfo; err = GetEntityBase()->GetFunction()->GetSystemStaticInfo(sysInfo); if (err != Error_Succeed) { Dbg("Get System Static info failed(%d).",err); return Error_Unexpect; } m_csMachineType = sysInfo.strMachineType; m_csSite = sysInfo.strSite; CSmartPointer spConfigRun; err = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfigRun); if (err == Error_Succeed) { spConfigRun->ReadConfigValueInt("WarnRecord", "disk", m_diskLastWarnHour); } return Error_Succeed; } ErrorCodeEnum CSelfCheckerFSM::ExceptionErrorProcess(const char *pszEntityName, ErrorCodeEnum eCode) { CSmartPointer pFunc = GetEntityBase()->GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); CSmartPointer spWait; Dbg("proc:%s,%d", pszEntityName, eCode); //do nothing if (eCode == Error_Cancel) return Error_Succeed; bool bUpgrade = false; //need to do something ErrorCodeEnum eErrCode = Error_Succeed; if ((m_entCfgInfo.find(pszEntityName) != m_entCfgInfo.end()) && ((m_entCfgInfo[pszEntityName]).hsInfo.find(eCode) != (m_entCfgInfo[pszEntityName]).hsInfo.end())) { TestActionEnum eAction = (m_entCfgInfo[pszEntityName]).hsInfo.find(eCode)->second; Dbg("action:%d", eAction); switch (eAction) { case ACTION_EXAMINE: break; case ACTION_RESET: break; case ACTION_CLOSE: eErrCode = pFuncPrivilege->CloseEntity(pszEntityName, spWait); if (eErrCode == Error_Succeed) { } break; case ACTION_ENTITY_RESTART: { if (m_entCfgInfo[pszEntityName].bWaitRestart) { Dbg("waiting restart..."); break; } if (m_entRunInfo[pszEntityName].loadOpt == 99) { Dbg("not configure? name:[%s]", pszEntityName); break; } //LogErrInfo("restart ",pszEntityName,eCode); m_entCfgInfo[pszEntityName].entityRestartCount++; Dbg("normalcount:%d,count:%d", m_restartNormal, m_entCfgInfo[pszEntityName].entityRestartCount); if (m_entCfgInfo[pszEntityName].entityRestartCount > m_restartNormal) { if ((!strnicmp(m_csMachineType, "RVC.Pad", strlen("RVC.Pad")) && !strnicmp(m_csSite, "cmb.FLB", strlen("cmb.FLB"))) || (!strnicmp(m_csMachineType, "RPM.Stand1S", strlen("RPM.Stand1S")))) { if (m_entRunInfo[pszEntityName].loadOpt == 0) m_entCfgInfo[pszEntityName].entityRestartCount = 0; } else { LogErrInfo(pszEntityName, " restart too many,upgrade process.", eCode); bUpgrade = true; m_entCfgInfo[pszEntityName].bWaitRestart = true; } eErrCode = Error_Succeed; break; } eErrCode = pFuncPrivilege->StopEntity(pszEntityName, spWait); if (eErrCode == Error_Succeed) { eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); if (eErrCode != Error_Succeed) { Dbg("spwait stop %s failed: %s.", pszEntityName, SpStrError(eErrCode)); eErrCode = pFuncPrivilege->TerminateEntity(pszEntityName, spWait); eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); if (eErrCode != Error_Succeed) { Dbg("spwait terminate %s failed: %s.", pszEntityName, SpStrError(eErrCode)); break; } } } else { Dbg("Stop %s failed(%d).", pszEntityName, eErrCode); break; } Sleep(2000); CSimpleStringA csIEUrl; if (_strnicmp("IEBrowser", pszEntityName, strlen("IEBrowser")) == 0) { GetEntityBase()->GetFunction()->GetSysVar("IEUrl", csIEUrl); Dbg("Url:[%s]", (const char*)csIEUrl); eErrCode = pFuncPrivilege->StartEntity(pszEntityName, csIEUrl, spWait); } else eErrCode = pFuncPrivilege->StartEntity(pszEntityName, NULL, spWait); if (eErrCode == Error_Succeed) { eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); if (eErrCode != Error_Succeed) { Dbg("spwait start %s failed(%d).", pszEntityName, eErrCode); break; } Dbg("Start entity %s suc.", pszEntityName); } else { Dbg("(re)Start %s failed(%d).", pszEntityName, eErrCode); break; } } break; case ACTION_OS_RESTART: Dbg("test os restart"); if (m_entRunInfo[pszEntityName].loadOpt == 1 || m_entRunInfo[pszEntityName].loadOpt == 2) LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_OS_RESTART, pszEntityName); break; case ACTION_POWER_RESTART: Dbg("test power restart"); if (m_entRunInfo[pszEntityName].loadOpt == 1 || m_entRunInfo[pszEntityName].loadOpt == 2) LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_POWER_RESTART, pszEntityName); break; default: break; } if (bUpgrade) { LogActionProcess(pszEntityName, eCode, eAction); } } else { Dbg("%s not configured,use default setting(%d)", LPCTSTR(pszEntityName), eCode); switch (eCode) { case Error_TimeOut: case Error_Unexpect: case Error_InvalidState: { eErrCode = pFuncPrivilege->StopEntity(pszEntityName, spWait); if (eErrCode == Error_Succeed) { eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); if (eErrCode != Error_Succeed) { Dbg("spwait stop %s failed: %s.", pszEntityName, SpStrError(eErrCode)); eErrCode = pFuncPrivilege->TerminateEntity(pszEntityName, spWait); eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); if (eErrCode != Error_Succeed) { Dbg("spwait terminate %s failed: %s.", pszEntityName, SpStrError(eErrCode)); break; } } } else { Dbg("Stop %s failed(%d).", pszEntityName, eErrCode); break; } Sleep(5000); CSimpleStringA csIEUrl; if (_strnicmp("IEBrowser", pszEntityName, strlen("IEBrowser")) == 0) { GetEntityBase()->GetFunction()->GetSysVar("IEUrl", csIEUrl); Dbg("Url:[%s]", (const char*)csIEUrl); eErrCode = pFuncPrivilege->StartEntity(pszEntityName, csIEUrl, spWait); } else eErrCode = pFuncPrivilege->StartEntity(pszEntityName, NULL, spWait); if (eErrCode == Error_Succeed) { eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); if (eErrCode != Error_Succeed) { Dbg("spwait start %s failed(%d).", pszEntityName, eErrCode); break; } } else { Dbg("(re)Start %s failed(%d).", pszEntityName, eErrCode); break; } } break; default: break; } } return eErrCode; } ErrorCodeEnum CSelfCheckerFSM::CheckEntity(const char *pszEntityName,EntityTestEnum eTestType) { //oilyang@20170926 no need to check by self.Let the HealthManager entity to do it. if (pszEntityName != NULL && strnicmp(pszEntityName, GetEntityBase()->GetEntityName(), strlen(GetEntityBase()->GetEntityName())) == 0) return Error_Succeed; CSmartPointer pFunc = GetEntityBase()->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 Dbg("Test %s,%d",pszEntityName,errCode); //errCode = ExceptionErrorProcess(pszEntityName,errCode); return errCode; } void CSelfCheckerFSM::OnNormalWorkTimerout(void *pData) { CSmartPointer pFunc = GetEntityBase()->GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); CSmartPointer spWait; ErrorCodeEnum errCode; //CSelfCheckerEntity* pEntity = ((CSelfCheckerEntity*)m_pEntity); // pEntity->GetActiveCount(); int activeEnCount = m_activeEntity.size(); vector::iterator it; //oiltmp 20131219 //GetSystemCPUStatus(); //GetSystemMemoryStatus(); //GetSystemDiskStatus(); for (it = m_activeEntity.begin();it != m_activeEntity.end(); ++it) { errCode = CheckEntity(*it,Test_ShakeHand); CEntityRunInfo runInfo; pFunc->GetEntityRunInfo(*it,runInfo); CheckEntityResouce(*it,runInfo); } GetEntityBase()->GetFunction()->ResetTimer(TIMER_ID_CHECK,MAX_CHECK_TIME); if (m_simulateTest)//oiltest { Dbg("simulate logevent framework restart"); LogEvent(Severity_Middle,Event_Req_Framework_Restart,"oiltest"); m_simulateTest = false; } } void CSelfCheckerFSM::OnCalcCpuUsageTimerout(void *pData) { CSmartPointer pFunc = GetEntityBase()->GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); CSmartPointer spWait; ErrorCodeEnum errCode; int activeEnCount = m_activeEntity.size(); vector::iterator it; for (it = m_activeEntity.begin(); it != m_activeEntity.end(); ++it) { CEntityRunInfo runInfo; pFunc->GetEntityRunInfo(*it, runInfo); CalcEntityCpuUsage(*it, runInfo, m_bFirstCalcCpu); CheckEntityResouce(*it, runInfo); } GetSystemCPUStatus(); GetSystemMemoryStatus(); GetSystemDiskStatus(); m_bFirstCalcCpu = !m_bFirstCalcCpu; GetEntityBase()->GetFunction()->ResetTimer(TIMER_CPU_CHECK, MAX_CPU_CHECK_TIME*2); } ErrorCodeEnum CSelfCheckerFSM::GetAllLiveEntity(CAutoArray &allEntitys) { allEntitys.Clear(); vector::iterator it; int start = 0; int size = m_allEntity.size(); allEntitys.Init(size); CSimpleStringA testStr = ""; for (it = m_allEntity.begin(); it != m_allEntity.end(); ++it,++start) { CSimpleStringA tmpName = *it; allEntitys[start] = tmpName; testStr += tmpName; testStr += ";"; } Dbg("allentity[%d][%s]",allEntitys.GetCount(),(const char*)testStr); return Error_Succeed; } //ErrorCodeEnum CSelfCheckerFSM::AddEntity(const char *pszEntityName) //{ // if (pszEntityName == NULL) // return Error_Null; // m_activeEntity.push_back(pszEntityName); // m_allEntity.push_back(pszEntityName); // // return Error_Succeed; //} //ErrorCodeEnum CSelfCheckerFSM::RemoveEntity(const char *pszEntityName) //{ // if (pszEntityName == NULL) // return Error_Null; // vector::iterator it; // for (it = m_activeEntity.begin(); it != m_activeEntity.end(); ++it) // { // if(!strncmp(pszEntityName,*it,it->GetLength())) // { // m_activeEntity.erase(it); // break; // } // } // return Error_Succeed; //} void CSelfCheckerFSM::DoOnCreated(const char *pszEntityName,ErrorCodeEnum eOnStartErrorCode,const char *pszCallerEntity) { if (eOnStartErrorCode == Error_Succeed) { vector::iterator it,itAct; bool bFound = false, bActFound = false; Dbg("oncreated %s",pszEntityName); for (it = m_allEntity.begin(); it != m_allEntity.end(); ++it) { if(!strncmp(pszEntityName,*it,it->GetLength())) { Dbg("already exist %s",pszEntityName); bFound = true; break; } } if(!bFound) m_allEntity.push_back(pszEntityName); for (itAct = m_activeEntity.begin(); itAct != m_activeEntity.end(); ++itAct) { if(!strncmp(pszEntityName,*itAct,itAct->GetLength())) { Dbg("active entity already exist %s",pszEntityName); bActFound = true; break; } } if (!bActFound) { m_activeEntity.push_back(pszEntityName); } m_entCfgInfo[pszEntityName].entityRestartCount = 0; } } void CSelfCheckerFSM::DoOnClosed(const char *pszEntityName,EntityCloseCauseEnum eCloseCause,ErrorCodeEnum eOnCloseErrorCode,const char *pszCallerEntity) { //not close by selfchecker if (strncmp(pszCallerEntity,GetEntityBase()->GetEntityName(),strlen(pszCallerEntity))) { if (eCloseCause == CloseCause_Self || eCloseCause == CloseCause_Other) { vector::iterator it; for (it = m_activeEntity.begin(); it != m_activeEntity.end(); ++it) { if(!strncmp(pszEntityName,*it,it->GetLength())) { Dbg("onclosed %s",pszEntityName); m_activeEntity.erase(it); break; } } } } CAutoArray testAutoArray; GetAllLiveEntity(testAutoArray); } void CSelfCheckerFSM::DoOnException(const char *pszEntityName,const char *pszFunctionName,EntityStateEnum eState,EntityStateEnum eLastState,ErrorCodeEnum eErrorCode) { Dbg("OnException:%s,%s,%d,%d,%d",pszEntityName,pszFunctionName,eState,eLastState,eErrorCode); } void CSelfCheckerFSM::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; m_entRunInfo[new_entry->EntityName].eTest = new_entry->ErrorResult; //add test result oilyang 20150616 //m_entRunInfo[new_entry->EntityName].eState = 9; //add test result oilyang 20150616 //Dbg("oiltest [%s]%d,%d,%d.",(LPCTSTR)new_entry->EntityName,m_entRunInfo[new_entry->EntityName].eState,m_entRunInfo[new_entry->EntityName].eTest,new_entry->ErrorResult); if (new_entry->op == Test_ShakeHand && new_entry->ErrorResult != Error_Succeed) { Dbg("oiltmp shakehand %s turns out %s, entity state: %s", (LPCTSTR)new_entry->EntityName, SpStrError(new_entry->ErrorResult), SpStrEntityState((EntityStateEnum)new_entry->state)); } if (new_entry->ErrorResult != Error_Succeed) { ErrorCodeEnum eErr; CSmartPointer pFunc = GetEntityBase()->GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); //TODO(Gifur@20210507) Linux Platform has no IEBrowser!! CEntityRunInfo ieInfo; eErr = pFunc->GetEntityRunInfo("IEBrowser",ieInfo); const bool bIEStarted = (eErr == Error_Succeed && ieInfo.eState != EntityState_NoStart); if (_strnicmp("MediaController", (const char*)new_entry->EntityName, strlen("MediaController")) == 0 && !bIEStarted) { Dbg("On loading stage,don't process MediaController exception."); } else { //ExceptionErrorProcess(new_entry->EntityName,new_entry->ErrorResult); Proc((const char*)new_entry->EntityName, ProcType_Shake, new_entry->ErrorResult); } } else { CSmartPointer spEntityFunction = GetEntityBase()->GetFunction(); CSmartPointer spConfig; ErrorCodeEnum eErr = spEntityFunction->OpenConfig(Config_Run, spConfig); if (eErr != Error_Succeed) { Dbg("open run cfg file failed!"); return; } spConfig->WriteConfigValueInt(new_entry->EntityName,"OsRestart",0); spConfig->WriteConfigValueInt(new_entry->EntityName,"PowerRestart",0); } } void CSelfCheckerFSM::LogErrInfo(const char* msgHead,const char* msgBody,const int errCode) { //oiltest to redifine this Dbg("%s,%s,%d",msgHead,msgBody,errCode); } void CSelfCheckerFSM::LogActionProcess(const char *pszEntityName,ErrorCodeEnum errCode,TestActionEnum eAct) { Dbg("LogActionProcess:entity[%s],errCode[%d],eAction[%d]",pszEntityName,errCode,eAct); CSmartPointer spEntityFunction = GetEntityBase()->GetFunction(); CSmartPointer spConfig; ErrorCodeEnum eErr = spEntityFunction->OpenConfig(Config_Run, spConfig); if (eErr != Error_Succeed) { Dbg("open run cfg file failed!"); return; } int osTimes,powerTimes; osTimes = powerTimes = 0; spConfig->ReadConfigValueInt(pszEntityName,"OsRestart",osTimes); spConfig->ReadConfigValueInt(pszEntityName,"PowerRestart",powerTimes); switch(eAct) { case ACTION_ENTITY_RESTART: if (osTimes > m_maxOsRestart || powerTimes > m_maxPowerRestart) { Dbg("restart too much,give up[%d][%d].",osTimes,powerTimes); break; } //if not the KEY entity,don't upgrade to restart computer //if (!IsKeyEntity(pszEntityName)) break; osTimes++; powerTimes++; spConfig->WriteConfigValueInt(pszEntityName,"OsRestart",osTimes); spConfig->WriteConfigValueInt(pszEntityName,"PowerRestart",powerTimes); //for simple and effective,use power restart only LogEvent(Severity_Middle,LOG_EVT_SELFCHECK_POWER_RESTART,pszEntityName); m_entCfgInfo[pszEntityName].bWaitRestart = true; break; default: break; } } #ifdef RVC_OS_WIN ULONGLONG subtractTime(const FILETIME &a, const FILETIME &b) { LARGE_INTEGER la, lb; la.LowPart = a.dwLowDateTime; la.HighPart = a.dwHighDateTime; lb.LowPart = b.dwLowDateTime; lb.HighPart = b.dwHighDateTime; return la.QuadPart - lb.QuadPart; } float getUsage(HANDLE hProcess,FILETIME *prevSysKernel, FILETIME *prevSysUser, FILETIME *prevProcKernel, FILETIME *prevProcUser, bool firstRun = false) { FILETIME sysIdle, sysKernel, sysUser; FILETIME procCreation, procExit, procKernel, procUser; if (!GetSystemTimes(&sysIdle, &sysKernel, &sysUser) || !GetProcessTimes(hProcess, &procCreation, &procExit, &procKernel, &procUser)) { // can't get time info so return return -1.; } // check for first call if (firstRun) { // save time info before return prevSysKernel->dwLowDateTime = sysKernel.dwLowDateTime; prevSysKernel->dwHighDateTime = sysKernel.dwHighDateTime; prevSysUser->dwLowDateTime = sysUser.dwLowDateTime; prevSysUser->dwHighDateTime = sysUser.dwHighDateTime; prevProcKernel->dwLowDateTime = procKernel.dwLowDateTime; prevProcKernel->dwHighDateTime = procKernel.dwHighDateTime; prevProcUser->dwLowDateTime = procUser.dwLowDateTime; prevProcUser->dwHighDateTime = procUser.dwHighDateTime; return -1.; } ULONGLONG sysKernelDiff = subtractTime(sysKernel, *prevSysKernel); ULONGLONG sysUserDiff = subtractTime(sysUser, *prevSysUser); ULONGLONG procKernelDiff = subtractTime(procKernel, *prevProcKernel); ULONGLONG procUserDiff = subtractTime(procUser, *prevProcUser); ULONGLONG sysTotal = sysKernelDiff + sysUserDiff; ULONGLONG procTotal = procKernelDiff + procUserDiff; return (float)((100.0 * procTotal) / sysTotal); } #else //oiltestlinux #endif //RVC_OS_WIN void CSelfCheckerFSM::CheckEntityResouce(const char *pszEntityName,CEntityRunInfo &info) { if (info.eState != EntityState_Idle) return; #ifdef RVC_OS_WIN HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_QUERY_LIMITED_INFORMATION,FALSE,info.dwProcessID); if (hProcess == NULL) { Dbg("OpenProcess %s failed %d.",pszEntityName,GetLastError()); return; } //GetSystemInfo PIO_COUNTERS pIOCounters = new IO_COUNTERS; BOOL ret = GetProcessIoCounters(hProcess,pIOCounters); if (ret == 0) { Dbg("GetProcessIoCounters %s failed %d.",pszEntityName,GetLastError()); } PROCESS_MEMORY_COUNTERS pmc; const int showSize = 20; if (GetProcessMemoryInfo(hProcess,&pmc,sizeof(pmc))) { if ((pmc.WorkingSetSize/MILLION > showSize) && (pmc.PeakWorkingSetSize/MILLION > showSize) && (pmc.PagefileUsage/MILLION > showSize) && (pmc.PeakPagefileUsage/MILLION > showSize)) { m_entRunInfo[pszEntityName].memoryHighCount++; if (m_entRunInfo[pszEntityName].memoryHighCount > ((60000 / MAX_CPU_CHECK_TIME)) * 2)//more than 2 minutes { m_entRunInfo[pszEntityName].memoryHighCount = 0; Dbg("%s,WorkingSetSize %u, Peak %u,PageFileUsage %u, Peak %u", (LPCTSTR)pszEntityName, pmc.WorkingSetSize / MILLION, pmc.PeakWorkingSetSize / MILLION, pmc.PagefileUsage / MILLION, pmc.PeakPagefileUsage / MILLION); } } } //Dbg can't support the ULONGLONG...oilyang 20140730 //Dbg("Entity %s:",pszEntityName); //Dbg("read op %u,write op %u",pIOCounters->ReadOperationCount,pIOCounters->WriteOperationCount); //Dbg("read transfer %u,write transfer %u",pIOCounters->ReadTransferCount,pIOCounters->WriteTransferCount); //Dbg("other op %u,other transfer %u",pIOCounters->OtherOperationCount,pIOCounters->OtherTransferCount); CloseHandle(hProcess); #else return;//oiltestlinux #endif //RVC_OS_WIN } void CSelfCheckerFSM::CalcEntityCpuUsage(const char *pszEntityName, CEntityRunInfo &info,bool bFirst) { if (info.eState != EntityState_Idle) return; #ifdef RVC_OS_WIN HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_QUERY_LIMITED_INFORMATION, FALSE, info.dwProcessID); if (hProcess == NULL) { Dbg("OpenProcess %s failed %d.", pszEntityName, GetLastError()); return; } float ret = getUsage(hProcess, &(m_entRunInfo[pszEntityName].prevSysKernel), &(m_entRunInfo[pszEntityName].prevSysUser) , &(m_entRunInfo[pszEntityName].prevProcKernel), &(m_entRunInfo[pszEntityName].prevProcUser),bFirst); if (!bFirst && ret > 2 && ret < 100)//where a entity have been restarted,the bFirst flag maybe wrong,the 'ret' can be big than 100! { Dbg("entity %s,cpu ratio:%f", pszEntityName, ret); m_entRunInfo[pszEntityName].cpuRatio = ret; } CloseHandle(hProcess); #else return;//oiltestlinux #endif //RVC_OS_WIN } void CSelfCheckerFSM::GetSystemMemoryStatus() { #ifdef RVC_OS_WIN // Use to convert bytes to KB #define DIV 1024 // Specify the width of the field in which to print the numbers. // The asterisk in the format specifier "%*I64d" takes an integer // argument and uses it to pad and right justify the number. #define WIDTH 7 MEMORYSTATUSEX statex; statex.dwLength = sizeof (statex); GlobalMemoryStatusEx (&statex); if (statex.dwMemoryLoad > m_memHighPercent) { Dbg("memory used: %*ld .", WIDTH, statex.dwMemoryLoad); LogWarn(Severity_Low, Error_Resource, LOG_EVT_SELFCHECK_MEMORY_TOO_HIGH, "Free memory is few."); } //Dbg ("(physical)%*I64d,(phy free)%*I64d,(paging)%*I64d,(pg free)%*I64d,(virtaul)%*I64d,(vt free)%*I64d", // WIDTH, statex.ullTotalPhys/DIV,WIDTH, statex.ullAvailPhys/DIV,WIDTH, statex.ullTotalPageFile/DIV // ,WIDTH, statex.ullAvailPageFile/DIV,WIDTH, statex.ullTotalVirtual/DIV,WIDTH, statex.ullAvailVirtual/DIV); // Show the amount of extended memory available. //Dbg ("There are %*I64d free Kbytes of extended memory.\n",WIDTH, statex.ullAvailExtendedVirtual/DIV); #else //oiltestlinux #endif } void CSelfCheckerFSM::GetSystemCPUStatus() { #ifdef RVC_OS_WIN #define _WIN32_WINNT 0x0601 FILETIME idleTime,kernelTime,userTime; BOOL ret = GetSystemTimes(&idleTime,&kernelTime,&userTime); if (ret == 0) { Dbg("GetSystemCPUStatus.GetSystemTimes failed(%d).",GetLastError()); return; } __int64 xIdle,xKernel,xUser; xIdle = idleTime.dwHighDateTime; xIdle <<= 32; xIdle |= idleTime.dwLowDateTime; xKernel = kernelTime.dwHighDateTime; xKernel <<= 32; xKernel |= kernelTime.dwLowDateTime; xUser = userTime.dwHighDateTime; xUser <<= 32; xUser |= userTime.dwLowDateTime; //Dbg("%u,%u,%u,%u,%u,%u",idleTime.dwHighDateTime,idleTime.dwLowDateTime,kernelTime.dwHighDateTime,kernelTime.dwLowDateTime,userTime.dwHighDateTime,userTime.dwLowDateTime); if (m_xIdlePre != 0) { __int64 xI,xK,xU; xI = xIdle - m_xIdlePre; xK = xKernel - m_xKernelPre; xU = xUser - m_xUserPre; int ratio = 0; if ((xK +xU) != 0) ratio = (xK - xI + xU) * 100 / (xK + xU); if (ratio > 50)//oiltmp@20170919 need to read from configure file?maybe or not Dbg("cpu %d",ratio); if (ratio > m_cpuHighPercent) { CSimpleStringA cpuHighEntitys(""); char cpuRatioBuf[16]; ZeroMemory(cpuRatioBuf, sizeof(cpuRatioBuf)); map::iterator it; for (it = m_entRunInfo.begin(); it != m_entRunInfo.end(); ++it) { if (it->second.cpuRatio > 0 && it->second.cpuRatio < 100) { itoa(it->second.cpuRatio, cpuRatioBuf, 10); cpuHighEntitys.Append(it->first + ":" + cpuRatioBuf + "||"); } } Dbg("cpu ratio:%s",(const char*)cpuHighEntitys); LogWarn(Severity_Low, Error_Resource, LOG_EVT_SELFCHECK_CPU_TOO_HIGH, (const char*)cpuHighEntitys); } } m_xIdlePre = xIdle; m_xKernelPre = xKernel; m_xUserPre = xUser; int warnLevel; CSimpleStringA strList(""); #else //oiltestlinux #endif //RVC_OS_WIN } void CSelfCheckerFSM::GetSystemDiskStatus() { #ifdef RVC_OS_WIN ULARGE_INTEGER ulAvailFree,ulTotalBytes,ulTotalFree; BOOL ret = GetDiskFreeSpaceEx(NULL,&ulAvailFree,&ulTotalBytes,&ulTotalFree); if (ret == 0) { Dbg("GetSystemDiskStatus.GetDiskFreeSpaceEx failed(%d).",GetLastError()); return; } //Dbg("%d,%d,%d",(ulAvailFree.QuadPart/MILLION)*100,ulTotalBytes.QuadPart,(ulTotalBytes.QuadPart/MILLION)); DWORD dwAvFree = ulAvailFree.QuadPart/MILLION; DWORD dwTotal = ulTotalBytes.QuadPart/MILLION; DWORD dwTotalFree = ulTotalFree.QuadPart/MILLION; int ratio = dwTotalFree*100/dwTotal; if ((100 - ratio) > m_diskHighPercent) { Dbg("The disk has %d MB(%d%) available.\n", dwTotalFree, ratio); //oilyang@20200526 根据wq建议,降低磁盘空间偏少的告警频率 SYSTEMTIME localTime; GetLocalTime(&localTime); if (m_diskLastWarnHour != localTime.wHour) { m_diskLastWarnHour = localTime.wHour; CSmartPointer spConfigRun; ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfigRun); if (eErr == Error_Succeed) { spConfigRun->WriteConfigValueInt("WarnRecord", "disk", m_diskLastWarnHour); } LogWarn(Severity_Low, Error_Resource, LOG_EVT_SELFCHECK_HARDDISK_TOO_HIGH, "Harddisk free space is few."); } } #else //oiltestlinux #endif //RVC_OS_WIN } bool CSelfCheckerFSM::IsKeyEntity(const char *pszEntityName) { vector::iterator it; for (it = m_vKeyEntity.begin(); it != m_vKeyEntity.end(); ++it) { if (!_strnicmp(pszEntityName,*it,strlen(pszEntityName))) return true; } return false; } int CSelfCheckerFSM::AddEntityState(const char *pszEntityName,EntityStateEnum eState) { if (eState == EntityState_Starting) { m_entRunInfo[pszEntityName].bGetLoadOpt = false; m_entRunInfo[pszEntityName].bRestarting = false; m_entRunInfo[pszEntityName].loadOpt = 99; m_entRunInfo[pszEntityName].eState = eState; m_entRunInfo[pszEntityName].eTest = Error_Succeed; } else m_entRunInfo[pszEntityName].eState = eState; Dbg("ADDDDD %s,%d,%d,%d",pszEntityName,m_entRunInfo[pszEntityName].eState,m_entRunInfo[pszEntityName].eTest,eState); if (eState == EntityState_Idle) { m_entRunInfo[pszEntityName].eTest = Error_Succeed; m_entRunInfo[pszEntityName].memoryHighCount = 0; } m_entRunInfo[pszEntityName].cpuRatio = 0; return 0; } ErrorCodeEnum CSelfCheckerFSM::GetEntityErrorList(int &warmLevel,CSimpleStringA &strList) { map::iterator it; CSimpleStringA tmpStr(""); bool bLost = false; for (it = m_entRunInfo.begin(); it != m_entRunInfo.end(); ++it) { if (m_entRunInfo[it->first].eState == EntityState_Lost) bLost = true; char buf[16],bufTest[16]; ZeroMemory(buf,16); ZeroMemory(bufTest, 16); //Dbg("oiltest20160425[%s],%d,%d", (const char*)it->first, m_entRunInfo[it->first].eState, m_entRunInfo[it->first].eTest); if (m_entRunInfo[it->first].eState == EntityState_Lost || m_entRunInfo[it->first].eState == EntityState_Close || m_entRunInfo[it->first].eState == EntityState_Killed || m_entRunInfo[it->first].eTest != Error_Succeed) { tmpStr += it->first; tmpStr += "="; if (m_entRunInfo[it->first].eState == EntityState_Lost || m_entRunInfo[it->first].eState == EntityState_Close || m_entRunInfo[it->first].eState == EntityState_Killed) { _itoa(m_entRunInfo[it->first].eState, buf, 10); tmpStr += buf; } if (m_entRunInfo[it->first].eTest != Error_Succeed) { Dbg("[%s],%s,%s", (const char*)it->first, SpStrEntityState((EntityStateEnum)m_entRunInfo[it->first].eState), SpStrError((ErrorCodeEnum)m_entRunInfo[it->first].eTest)); _itoa(m_entRunInfo[it->first].eTest, bufTest, 10); tmpStr += ",(selfcheck code):"; tmpStr += bufTest; } tmpStr += ";"; } } if (tmpStr.GetLength() < 2) m_warmLevel = warmLevel = 0; if (bLost) m_warmLevel = warmLevel = 3; m_warmLevel = warmLevel = 1;//for temp set 20150617 strList = tmpStr; if (strList.GetLength() > 2) Dbg("warnlevel:%d,ErrorList [%s]", m_warmLevel,(LPCTSTR)strList); return Error_Succeed; } int CSelfCheckerFSM::Proc(string entity, ProcType eType, DWORD dwCode, const char *pszMessage) { ConnectToHealthManager(); if (!m_entRunInfo[entity.c_str()].bGetLoadOpt) { if (m_pHealthClient != NULL) { HealthManagerService_GetEntityCfgInfo_Req req; HealthManagerService_GetEntityCfgInfo_Ans ans; req.name = entity.c_str(); ErrorCodeEnum errCode = m_pHealthClient->GetEntityCfgInfo(req, ans, 10000); if (errCode == Error_Succeed) { m_entRunInfo[entity.c_str()].bGetLoadOpt = true; Dbg("to get entity cfg info suc:%d", ans.loadOpt); SetEntityCfgInfo(entity.c_str(), ans.loadOpt); } } } map::iterator it; if ((it = m_mapEntity.find(entity.c_str())) == m_mapEntity.end()) { Dbg("can't find entity %s configure setting,using default setting.",entity.c_str()); //Error_TimeOut: //Error_Unexpect: //Error_InvalidState: if (eType == ProcType_Shake && (dwCode == Error_TimeOut || dwCode == Error_Unexpect || dwCode == Error_InvalidState)) ExceptionErrorProcessXml(eType,entity.c_str(), ACTION_ENTITY_RESTART,true); else if (eType == ProcType_Warn) ExceptionErrorProcessXml(eType, entity.c_str(), dwCode, true, pszMessage); else Dbg("What's this:type:%d,receive code:%x,msg:%s, from entity %s.", eType, dwCode, pszMessage, entity.c_str()); return -1; } vector::iterator vIt, vEnd; if (eType == ProcType_Shake) { vIt = it->second.vShake.begin(); vEnd = it->second.vShake.end(); } else if (eType == ProcType_Warn) { vIt = it->second.vWarn.begin(); vEnd = it->second.vWarn.end(); } for (; vIt != vEnd; vIt++) { if (vIt->code == dwCode) { if (vIt->upgradecount > 0) { Dbg("action size:%d,upgradecount:%d", vIt->proctime.size(), vIt->upgradecount); UINT64 happentime = GetTickCountRVC(); if (vIt->proctime.size() < vIt->upgradecount - 1)//just add record,do nothing { vIt->proctime.push_back(happentime); Dbg("just add record"); return 0; } else { //to find the 1st record happened in last upgradetime minute //and remove the record happened far ago(upgradetime minutes before) vector::iterator ittime, itFisrtInPeriod, xxxIt; bool bFar = false; int count = 0; for (ittime = vIt->proctime.begin(); ittime != vIt->proctime.end(); ittime++) { itFisrtInPeriod = ittime; UINT64 difftime = happentime - *ittime; if (difftime / (1000 * 60) < vIt->upgradetime) break; else { count++; Dbg("the %d th action",count); bFar = true; } } if (!bFar) { //to do upgrade action Dbg("to do upgrade action"); ExceptionErrorProcessXml(eType,entity.c_str(), vIt->upgradeaction); vIt->proctime.clear(); return 0; } else { if (count == 1 && vIt->proctime.size() == 1) vIt->proctime.clear(); else vIt->proctime.erase(vIt->proctime.begin(), itFisrtInPeriod); for (xxxIt = vIt->proctime.begin(); xxxIt != vIt->proctime.end(); xxxIt++) { cout << *xxxIt << " # "; } cout << endl; vIt->proctime.push_back(happentime); for (xxxIt = vIt->proctime.begin(); xxxIt != vIt->proctime.end(); xxxIt++) { cout << *xxxIt << " * "; } Dbg("after clear,add record"); return 0; } } } Dbg("Entity %s receive %d,to do action:%d", entity.c_str(), dwCode, vIt->action); ExceptionErrorProcessXml(eType,entity.c_str(), vIt->action,true, pszMessage); return 0; } } Dbg("can't find corresponding action of entity %s,type:%d,code:%x",entity.c_str(),eType,dwCode); Dbg("use default process..."); if (eType == ProcType_Shake && (dwCode == Error_TimeOut || dwCode == Error_Unexpect || dwCode == Error_InvalidState)) ExceptionErrorProcessXml(eType, entity.c_str(), ACTION_ENTITY_RESTART, true); else if (eType == ProcType_Warn) ExceptionErrorProcessXml(eType, entity.c_str(), dwCode, true, pszMessage); return -1; } bool CSelfCheckerFSM::ReadXmlFile(const char *szFileName) {//读取Xml文件,并遍历 //MessageBox(0, 0, 0, 0); LOG_FUNCTION(); tinyxml2::XMLDocument *doc = new tinyxml2::XMLDocument(); XMLError err = doc->LoadFile(szFileName); if (err != XML_SUCCESS) { Dbg("open file %s failed.GetLastError:%d",szFileName,GetLastError()); return false; } //doc->GetDocument(); string out = ""; XMLNode *pF = doc->FirstChild(); XMLElement *pRoot = doc->RootElement(); //pF->FirstChildElement(); if (pRoot == NULL) { Dbg("Get root element failed."); return false; } else pF = pRoot->FirstChild(); while (pF != NULL) { if (pF->ToElement() == NULL) { pF = pF->FirstChild(); continue; } const char *pName = pF->ToElement()->Name(); if (!strncmp(pName, "SelfCheckerConfig", strlen("SelfCheckerConfig"))) { pF = pF->FirstChild(); continue; } else if (!strncmp(pName, "Entity", strlen("Entity"))) { EntityCfg entity; const char *attrName = pF->ToElement()->Attribute("name"); out += const_cast(attrName); out += "\r\n"; XMLNode *pChild = pF->FirstChild(); while (pChild != NULL) { if (!strncmp(pChild->Value(), "shakehandproc", strlen("shakehandproc"))) { XMLNode *pProc = pChild->FirstChild(); while (pProc != NULL) { ProcItem item; const char *code, *action, *upgradeaction, *upgradetime, *upgradecount; code = action = upgradeaction = upgradetime = upgradecount = NULL; if (pProc->ToElement() != NULL) { code = pProc->ToElement()->Attribute("code"); action = pProc->ToElement()->Attribute("action"); upgradeaction = pProc->ToElement()->Attribute("upgradeaction"); upgradetime = pProc->ToElement()->Attribute("upgradetime"); upgradecount = pProc->ToElement()->Attribute("upgradecount"); } if (code != NULL) { item.code = CodeStrToInt(code); Dbg("oiltest code:%s,%d", code, item.code); out += const_cast(code); out += " , "; } if (action != NULL) { item.action = ActionStrToInt(action); out += const_cast(action); out += " , "; } if (upgradeaction != NULL) { item.upgradeaction = ActionStrToInt(upgradeaction); out += const_cast(upgradeaction); } if (upgradetime != NULL) { item.upgradetime = atoi(upgradetime); } if (upgradecount != NULL) { item.upgradecount = atoi(upgradecount); } else item.upgradecount = 0; entity.vShake.push_back(item); out += "; "; pProc = pProc->NextSibling(); } } else if (!strncmp(pChild->Value(), "eventproc", strlen("eventproc"))) { XMLNode *pProc = pChild->FirstChild(); while (pProc != NULL) { ProcItem item; const char *code, *action, *upgradeaction, *upgradetime, *upgradecount; code = action = upgradeaction = upgradetime = upgradecount = NULL; if (pProc->ToElement() != NULL) { code = pProc->ToElement()->Attribute("code"); action = pProc->ToElement()->Attribute("action"); upgradeaction = pProc->ToElement()->Attribute("upgradeaction"); upgradetime = pProc->ToElement()->Attribute("upgradetime"); upgradecount = pProc->ToElement()->Attribute("upgradecount"); } if (code != NULL) { item.code = CodeStrToInt(code); out += const_cast(code); out += ","; } if (action != NULL) { item.action = ActionStrToInt(action); out += const_cast(action); out += ","; } if (upgradeaction != NULL) { item.upgradeaction = ActionStrToInt(upgradeaction); out += const_cast(upgradeaction); } if (upgradetime != NULL) { item.upgradetime = atoi(upgradetime); } if (upgradecount != NULL) { item.upgradecount = atoi(upgradecount); } else item.upgradecount = 0; entity.vWarn.push_back(item); out += "; "; pProc = pProc->NextSibling(); } } pChild = pChild->NextSibling(); } m_mapEntity[attrName] = entity; Dbg("add %s,vShake size:%d,vWarn size:%d", attrName, entity.vShake.size(), entity.vWarn.size()); } out += "\r\n"; pF = pF->NextSibling(); } //cout << out.c_str() << endl; return true; } ErrorCodeEnum CSelfCheckerFSM::ExceptionErrorProcessXml(ProcType eType, const char *pszEntityName, DWORD dwAction, bool bDefault,const char *pszMessage) { CSmartPointer pFunc = GetEntityBase()->GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); CSmartPointer spWait; ErrorCodeEnum eErrCode = Error_Unexpect; switch (dwAction) { case ACTION_EXAMINE: break; case ACTION_RESET: break; case ACTION_CLOSE: eErrCode = pFuncPrivilege->CloseEntity(pszEntityName, spWait); if (eErrCode == Error_Succeed) { } break; case ACTION_ENTITY_RESTART: { if (m_entCfgInfo[pszEntityName].bWaitRestart) { if (!bDefault) { Dbg("waiting restart..."); break; } } if (m_entRunInfo[pszEntityName].loadOpt == 99) { Dbg("not configure? name:[%s]", pszEntityName); break; } //oilyang@20200407 if being restarted by selfchecker,break if (m_entRunInfo[pszEntityName].bRestarting) { Dbg("%s is being restarted by selfchecker.", pszEntityName); break; } //oilyang@20200403 //for fwb test,PinPad&CardSwiper can't be stop immediately if (_strnicmp("PinPad", pszEntityName, strlen("PinPad")) == 0 || _strnicmp("CardSwiper", pszEntityName, strlen("CardSwiper")) == 0 || _strnicmp("Sensors", pszEntityName, strlen("Sensors")) == 0 || _strnicmp("IDCertificate", pszEntityName, strlen("IDCertificate")) == 0 || _strnicmp("FingerPrint", pszEntityName, strlen("FingerPrint")) == 0 || _strnicmp("DeviceControl", pszEntityName, strlen("DeviceControl")) == 0) eErrCode = pFuncPrivilege->TerminateEntity(pszEntityName, spWait); else eErrCode = pFuncPrivilege->StopEntity(pszEntityName, spWait); if (eErrCode == Error_Succeed) { eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); if (eErrCode != Error_Succeed) { Dbg("spwait stop %s failed: %s.", pszEntityName, SpStrError(eErrCode)); eErrCode = pFuncPrivilege->TerminateEntity(pszEntityName, spWait); eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); if (eErrCode != Error_Succeed) { Dbg("spwait terminate %s failed: %s.", pszEntityName, SpStrError(eErrCode)); break; } } } else { Dbg("Stop %s failed(%d).", pszEntityName, eErrCode); break; } Sleep(2000); CSimpleStringA csIEUrl; if (_strnicmp("IEBrowser", pszEntityName, strlen("IEBrowser")) == 0) { GetEntityBase()->GetFunction()->GetSysVar("IEUrl", csIEUrl); Dbg("Url:[%s]", (const char*)csIEUrl); eErrCode = pFuncPrivilege->StartEntity(pszEntityName, csIEUrl, spWait); } else eErrCode = pFuncPrivilege->StartEntity(pszEntityName, NULL, spWait); if (eErrCode == Error_Succeed) { eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); if (eErrCode != Error_Succeed) { Dbg("spwait start %s failed(%d).", pszEntityName, eErrCode); break; } Dbg("Start entity %s suc.", pszEntityName); } else { Dbg("(re)Start %s failed(%d).", pszEntityName, eErrCode); break; } } break; case ACTION_OS_RESTART: Dbg("test os restart"); if (m_entRunInfo[pszEntityName].loadOpt == 1 || m_entRunInfo[pszEntityName].loadOpt == 2) LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_OS_RESTART, pszEntityName); break; case ACTION_POWER_RESTART: Dbg("test power restart"); if (m_entRunInfo[pszEntityName].loadOpt == 1 || m_entRunInfo[pszEntityName].loadOpt == 2) LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_POWER_RESTART, pszEntityName); break; default: break; } return eErrCode; } void CSelfCheckerFSM::UpgradeActionProcess(const char *pszEntityName, const char *pAction) { return; } ErrorCodeEnum CSelfCheckerFSM::ConnectToHealthManager() { LOG_FUNCTION(); if (m_pHealthClient == NULL) { m_pHealthClient = new HealthManagerClient(GetEntityBase()); ErrorCodeEnum ErrorConn = m_pHealthClient->Connect(); if (ErrorConn != Error_Succeed) { m_pHealthClient->SafeDelete(); m_pHealthClient = NULL; Dbg("Connect to Healthmanager failed.%d", ErrorConn); return Error_Unexpect; } else { Dbg("HealthManager connected."); } } return Error_Succeed; } HealthManagerClient::HealthManagerClient(CEntityBase *pEntity) :HealthManagerService_ClientBase(pEntity) { }