SelfCheckerFSM.cpp 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586
  1. #include "stdafx.h"
  2. #define WIN32_LEAN_AND_MEAN
  3. #include "SelfCheckerFSM.h"
  4. #include "EventCode.h"
  5. #pragma comment(lib,"user32.lib")
  6. class CSelfCheckerEntity;
  7. const int MAX_AYSNC_TIMEOUT = 60000;
  8. const int MAX_CHECK_TIME = 60000;
  9. const int MAX_CPU_CHECK_TIME = 5000;
  10. const int TIMER_ID_CHECK = 0;
  11. const int TIMER_CPU_CHECK = 1;
  12. const int THOUSAND = 1024;
  13. const int MILLION = 1048576;
  14. int ActionStrToInt(const char *pAction)
  15. {
  16. int ret = 0;
  17. char x = *pAction;
  18. if (x >= '0' && x <= '9')
  19. return x - '0';
  20. else
  21. return 0;
  22. }
  23. DWORD GetRadixProduct(int times,int radix)
  24. {
  25. DWORD dwRet = 1;
  26. if (times < 0 || (radix != 10 && radix != 16))
  27. return 0;
  28. else
  29. {
  30. for (int i = 0; i < times; i++)
  31. dwRet *= radix;
  32. }
  33. return dwRet;
  34. }
  35. DWORD CodeStrToInt(const char *pCode)
  36. {
  37. CSimpleStringA csCode(pCode);
  38. csCode = csCode.Trim();
  39. int len = csCode.GetLength();
  40. if (len < 0 || len > 10)
  41. {
  42. return 0;
  43. }
  44. DWORD dwRet = 0;
  45. if (len > 2 && csCode[0] == '0' && (csCode[1] == 'x' || csCode[1] == 'X'))//"0x1234,0X12FF"
  46. {
  47. for (int i = 2; i < len; i++)
  48. {
  49. if (csCode[i] <= '9' && csCode[i] >= '0')
  50. dwRet += (csCode[i] - '0')*GetRadixProduct(len - i - 1,16);
  51. else if (csCode[i] <= 'f' && csCode[i] >= 'a')
  52. dwRet += (csCode[i] - 'a' + 10)*GetRadixProduct(len - i - 1,16);
  53. else if (csCode[i] <= 'F' && csCode[i] >= 'A')
  54. dwRet += (csCode[i] - 'A' + 10)*GetRadixProduct(len - i - 1, 16);
  55. else
  56. return 0;//because there is a invalid char,break process and return 0
  57. }
  58. }
  59. else//"768"
  60. {
  61. for (int i = 0; i < len; i++)
  62. {
  63. if (csCode[i] <= '9' && csCode[i] >= '0')
  64. dwRet += (csCode[i] - '0')*GetRadixProduct(len - i - 1, 10);
  65. else
  66. return 0;//because there is a invalid char,break process and return 0
  67. }
  68. }
  69. return dwRet;
  70. }
  71. unsigned long long GetTickCountRVC() {
  72. #ifdef RVC_OS_WIN
  73. return GetTickCount64();
  74. #else
  75. struct timespec ts;
  76. clock_gettime(CLOCK_MONOTONIC, &ts);
  77. return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
  78. #endif //RVC_OS_WIN
  79. }
  80. ErrorCodeEnum CSelfCheckerFSM::OnInit()
  81. {
  82. m_xIdlePre = m_xKernelPre = m_xUserPre = 0;
  83. ErrorCodeEnum errCode = Initial();
  84. if (errCode != Error_Succeed)
  85. return Error_IO;
  86. return Error_Succeed;
  87. }
  88. ErrorCodeEnum CSelfCheckerFSM::OnExit()
  89. {
  90. return Error_Succeed;
  91. }
  92. void CSelfCheckerFSM::s0_on_entry()
  93. {
  94. LOG_FUNCTION();
  95. ErrorCodeEnum errCode;
  96. CAutoArray<WORD> tmpInstIDs;
  97. CAutoArray<CSimpleStringA> tmpNames;
  98. errCode = GetEntityBase()->GetFunction()->GetAllRegistedEntity(tmpNames,tmpInstIDs);
  99. if (errCode != Error_Succeed)
  100. {
  101. Dbg("Get started entity failed.[%d]",errCode);
  102. }
  103. for (int i = 0; i < tmpNames.GetCount(); ++i)
  104. {
  105. ErrorCodeEnum eErr;
  106. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  107. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  108. CEntityRunInfo runInfo;
  109. eErr = pFunc->GetEntityRunInfo(tmpNames[i], runInfo);
  110. if (runInfo.eState != EntityState_NoStart)
  111. {
  112. Dbg("Add entity %s",(const char*)tmpNames[i]);
  113. m_allEntity.push_back(tmpNames[i]);
  114. m_activeEntity.push_back(tmpNames[i]);
  115. }
  116. }
  117. //m_pEntity-> m_entityNames.push_back(tmpNames[i]);
  118. FSMEvent *pEvt = new FSMEvent(USER_EVT_INIT);
  119. PostEventFIFO(pEvt);
  120. }
  121. void CSelfCheckerFSM::s0_on_exit()
  122. {
  123. LOG_FUNCTION();
  124. }
  125. unsigned int CSelfCheckerFSM::s0_on_event(FSMEvent* pEvt)
  126. {
  127. LOG_FUNCTION();
  128. switch(pEvt->iEvt)
  129. {
  130. case USER_EVT_INIT:
  131. pEvt->SetHandled();
  132. break;
  133. default:
  134. break;
  135. }
  136. return 0;
  137. }
  138. void CSelfCheckerFSM::s1_on_entry()
  139. {
  140. LOG_FUNCTION();
  141. void *pTmpData = NULL;
  142. ITimerListener *pListener = new TimerOutHelper<CSelfCheckerFSM>(this, &CSelfCheckerFSM::OnNormalWorkTimerout,pTmpData);
  143. GetEntityBase()->GetFunction()->SetTimer(TIMER_ID_CHECK, pListener, MAX_CHECK_TIME);
  144. //oilyang@20170703 add for cpu usage for process
  145. pTmpData = NULL;
  146. pListener = new TimerOutHelper<CSelfCheckerFSM>(this, &CSelfCheckerFSM::OnCalcCpuUsageTimerout, pTmpData);
  147. GetEntityBase()->GetFunction()->SetTimer(TIMER_CPU_CHECK, pListener, MAX_CPU_CHECK_TIME);
  148. }
  149. void CSelfCheckerFSM::s1_on_exit()
  150. {
  151. LOG_FUNCTION();
  152. }
  153. unsigned int CSelfCheckerFSM::s1_on_event(FSMEvent* evt)
  154. {
  155. LOG_FUNCTION();
  156. return 0;
  157. }
  158. void CSelfCheckerFSM::s2_on_entry()
  159. {
  160. LOG_FUNCTION();
  161. }
  162. void CSelfCheckerFSM::s2_on_exit()
  163. {
  164. LOG_FUNCTION();
  165. }
  166. unsigned int CSelfCheckerFSM::s2_on_event(FSMEvent* evt)
  167. {
  168. LOG_FUNCTION();
  169. return 0;
  170. }
  171. void CSelfCheckerFSM::s3_on_entry()
  172. {
  173. LOG_FUNCTION();
  174. }
  175. void CSelfCheckerFSM::s3_on_exit()
  176. {
  177. LOG_FUNCTION();
  178. }
  179. unsigned int CSelfCheckerFSM::s3_on_event(FSMEvent* evt)
  180. {
  181. LOG_FUNCTION();
  182. return 0;
  183. }
  184. int ch2int(char ch)
  185. {
  186. if (ch >= '0' && ch <= '9')
  187. return ch-'0';
  188. else if (ch >= 'a' && ch <= 'f')
  189. return ch-'a'+10;
  190. else if (ch >= 'A' && ch <= 'F')
  191. return ch-'A'+10;
  192. return 0;
  193. }
  194. long hexstr2int(const char *str, int len)
  195. {
  196. long result = 0;
  197. for (int i = 0; i < len; ++i)
  198. {
  199. result += (ch2int(str[i]) << ((len-i-1)*4));
  200. }
  201. return result;
  202. }
  203. bool StrEqualNoCase(const char *s1, const char *s2,int len)
  204. {
  205. if (strlen(s1) != strlen(s2))
  206. return false;
  207. for (int i = 0; i < len; ++i)
  208. {
  209. if (toupper(s1[i]) != toupper(s2[i]))
  210. return false;
  211. }
  212. return true;
  213. }
  214. ErrorCodeEnum CSelfCheckerFSM::Initial()
  215. {
  216. ErrorCodeEnum err;
  217. CSmartPointer<IConfigInfo> spConfig;
  218. err = GetEntityBase()->GetFunction()->OpenConfig(Config_Software, spConfig);
  219. if (err != Error_Succeed) {
  220. Dbg("open cfg file failed!");
  221. return Error_IO;
  222. }
  223. m_restartNormal = 3;
  224. m_restartSpecial = 5;
  225. m_maxOsRestart = 5;
  226. m_maxPowerRestart = 5;
  227. spConfig->ReadConfigValueInt("init","RestartNormal",m_restartNormal);
  228. spConfig->ReadConfigValueInt("init","RestartSpecial",m_restartSpecial);
  229. spConfig->ReadConfigValueInt("init","MaxOsRestart",m_maxOsRestart);
  230. spConfig->ReadConfigValueInt("init","MaxPowerRestart",m_maxPowerRestart);
  231. spConfig->ReadConfigValueInt("init","SimulateTestFlag",m_simulateTest);
  232. spConfig->ReadConfigValue("init","KeyEntity",m_csKeyEntity);
  233. spConfig->ReadConfigValueInt("init","CpuTooHighPercent",m_cpuHighPercent);
  234. spConfig->ReadConfigValueInt("init","MemoryTooHighPercent",m_memHighPercent);
  235. spConfig->ReadConfigValueInt("init","HardDiskTooHighPercent",m_diskHighPercent);
  236. ifstream is;
  237. CSimpleStringA cfgPath(""),cfgXml("");
  238. err = GetEntityBase()->GetFunction()->GetPath("cfg",cfgPath);
  239. //cfgPath = cfgPath + "\\SelfChecker.ini";
  240. cfgXml = cfgPath + "/SelfCheckerProc.xml";
  241. ReadXmlFile(cfgXml);
  242. Dbg("cfgxml[%s]", cfgXml);
  243. //is.open (cfgPath, ios::binary);
  244. //if (!is.is_open())
  245. // return Error_IO;
  246. //string line;
  247. //long curr,end;
  248. //is.seekg(0,ios_base::end);
  249. //end = is.tellg();
  250. //is.seekg(0,ios_base::beg);
  251. //CheckPattern eSection = CHECK_UNKNOWN;
  252. ////load config file
  253. //do
  254. //{
  255. // getline(is,line);
  256. // if (line[0] == '[')
  257. // {
  258. // size_t secEnd = line.find(']',1);
  259. // if (secEnd != string::npos)
  260. // {
  261. // string strSec = line.substr(1,secEnd-1);
  262. // if (StrEqualNoCase(strSec.c_str(),"ShakeHand",strSec.length()))
  263. // eSection = CHECK_HANDSHAKE;
  264. // else if (StrEqualNoCase(strSec.c_str(),"Examine",strSec.length()))
  265. // eSection = CHECK_EXAMINE;
  266. // else if (StrEqualNoCase(strSec.c_str(),"Reset",strSec.length()))
  267. // eSection = CHECK_RESET;
  268. // else if (StrEqualNoCase(strSec.c_str(),"Restart",strSec.length()))
  269. // eSection = CHECK_RESTART;
  270. // else
  271. // eSection = CHECK_UNKNOWN;
  272. // }
  273. // }
  274. // else if (((unsigned)(line[0]+1) > 256) || line[0] == ';')
  275. // {//Chinese and other...
  276. // curr = is.tellg();
  277. // continue;
  278. // }
  279. // else if (isalpha(line[0]))
  280. // {
  281. // if (eSection == CHECK_UNKNOWN)
  282. // {
  283. // curr = is.tellg();
  284. // continue;
  285. // }
  286. // size_t keyPos = line.find('=',0);
  287. // if (keyPos != string::npos)
  288. // {
  289. // string keyName = line.substr(0,keyPos);
  290. // size_t douPos = line.find(',',keyPos);
  291. // size_t fenPos,start = keyPos;
  292. // m_entCfgInfo[keyName.c_str()].entityRestartCount = 0;
  293. // m_entCfgInfo[keyName.c_str()].osRestartCount = 0;
  294. // m_entCfgInfo[keyName.c_str()].powerRestartCount = 0;
  295. // m_entCfgInfo[keyName.c_str()].bWaitRestart = false;
  296. // for (;douPos != string::npos;)
  297. // {
  298. // ErrorCodeEnum evtCode = (ErrorCodeEnum)hexstr2int(line.substr(start+1+2,douPos-start-2-1).c_str(),douPos-start-2-1);
  299. // fenPos = line.find(';',douPos);
  300. // TestActionEnum actCode;
  301. // if (fenPos != string::npos)
  302. // {
  303. // actCode = (TestActionEnum)atoi(line.substr(douPos+1,fenPos-douPos-1).c_str());
  304. // }
  305. // else
  306. // {
  307. // int xx = line.length()-douPos-1;
  308. // actCode = (TestActionEnum)atoi(line.substr(douPos+1,line.length()-douPos-1).c_str());
  309. // }
  310. // switch(eSection)
  311. // {
  312. // case CHECK_HANDSHAKE:
  313. // m_entCfgInfo[keyName.c_str()].hsInfo[evtCode] = actCode;
  314. // break;
  315. // case CHECK_EXAMINE:
  316. // break;
  317. // case CHECK_RESET:
  318. // m_entCfgInfo[keyName.c_str()].resetInfo[evtCode] = actCode;
  319. // break;
  320. // case CHECK_RESTART:
  321. // break;
  322. // }
  323. // douPos = line.find(',',fenPos);
  324. // start = fenPos;
  325. // }
  326. // }
  327. // }
  328. // curr = is.tellg();
  329. //}while(curr < end);
  330. auto list = m_csKeyEntity.Split(',');
  331. for (int i = 0; i < list.GetCount(); ++i)
  332. {
  333. CSimpleStringA entity = list[i];
  334. Dbg("%s",LPCTSTR(entity));
  335. m_vKeyEntity.push_back(entity);
  336. }
  337. CSystemStaticInfo sysInfo;
  338. err = GetEntityBase()->GetFunction()->GetSystemStaticInfo(sysInfo);
  339. if (err != Error_Succeed)
  340. {
  341. Dbg("Get System Static info failed(%d).",err);
  342. return Error_Unexpect;
  343. }
  344. m_csMachineType = sysInfo.strMachineType;
  345. m_csSite = sysInfo.strSite;
  346. CSmartPointer<IConfigInfo> spConfigRun;
  347. err = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfigRun);
  348. if (err == Error_Succeed) {
  349. spConfigRun->ReadConfigValueInt("WarnRecord", "disk", m_diskLastWarnHour);
  350. }
  351. return Error_Succeed;
  352. }
  353. ErrorCodeEnum CSelfCheckerFSM::ExceptionErrorProcess(const char *pszEntityName, ErrorCodeEnum eCode)
  354. {
  355. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  356. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  357. CSmartPointer<IAsynWaitSp> spWait;
  358. Dbg("proc:%s,%d", pszEntityName, eCode);
  359. //do nothing
  360. if (eCode == Error_Cancel)
  361. return Error_Succeed;
  362. bool bUpgrade = false;
  363. //need to do something
  364. ErrorCodeEnum eErrCode = Error_Succeed;
  365. if ((m_entCfgInfo.find(pszEntityName) != m_entCfgInfo.end())
  366. && ((m_entCfgInfo[pszEntityName]).hsInfo.find(eCode) != (m_entCfgInfo[pszEntityName]).hsInfo.end()))
  367. {
  368. TestActionEnum eAction = (m_entCfgInfo[pszEntityName]).hsInfo.find(eCode)->second;
  369. Dbg("action:%d", eAction);
  370. switch (eAction)
  371. {
  372. case ACTION_EXAMINE:
  373. break;
  374. case ACTION_RESET:
  375. break;
  376. case ACTION_CLOSE:
  377. eErrCode = pFuncPrivilege->CloseEntity(pszEntityName, spWait);
  378. if (eErrCode == Error_Succeed)
  379. {
  380. }
  381. break;
  382. case ACTION_ENTITY_RESTART:
  383. {
  384. if (m_entCfgInfo[pszEntityName].bWaitRestart)
  385. {
  386. Dbg("waiting restart...");
  387. break;
  388. }
  389. if (m_entRunInfo[pszEntityName].loadOpt == 99)
  390. {
  391. Dbg("not configure? name:[%s]", pszEntityName);
  392. break;
  393. }
  394. //LogErrInfo("restart ",pszEntityName,eCode);
  395. m_entCfgInfo[pszEntityName].entityRestartCount++;
  396. Dbg("normalcount:%d,count:%d", m_restartNormal, m_entCfgInfo[pszEntityName].entityRestartCount);
  397. if (m_entCfgInfo[pszEntityName].entityRestartCount > m_restartNormal)
  398. {
  399. if ((!strnicmp(m_csMachineType, "RVC.Pad", strlen("RVC.Pad")) && !strnicmp(m_csSite, "cmb.FLB", strlen("cmb.FLB")))
  400. || (!strnicmp(m_csMachineType, "RPM.Stand1S", strlen("RPM.Stand1S"))))
  401. {
  402. if (m_entRunInfo[pszEntityName].loadOpt == 0)
  403. m_entCfgInfo[pszEntityName].entityRestartCount = 0;
  404. }
  405. else
  406. {
  407. LogErrInfo(pszEntityName, " restart too many,upgrade process.", eCode);
  408. bUpgrade = true;
  409. m_entCfgInfo[pszEntityName].bWaitRestart = true;
  410. }
  411. eErrCode = Error_Succeed;
  412. break;
  413. }
  414. eErrCode = pFuncPrivilege->StopEntity(pszEntityName, spWait);
  415. if (eErrCode == Error_Succeed)
  416. {
  417. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  418. if (eErrCode != Error_Succeed)
  419. {
  420. Dbg("spwait stop %s failed(%d).", pszEntityName, eErrCode);
  421. eErrCode = pFuncPrivilege->TerminateEntity(pszEntityName, spWait);
  422. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  423. if (eErrCode != Error_Succeed)
  424. {
  425. Dbg("spwait terminate %s failed(%d).", pszEntityName, eErrCode);
  426. break;
  427. }
  428. }
  429. }
  430. else
  431. {
  432. Dbg("Stop %s failed(%d).", pszEntityName, eErrCode);
  433. break;
  434. }
  435. Sleep(2000);
  436. CSimpleStringA csIEUrl;
  437. if (_strnicmp("IEBrowser", pszEntityName, strlen("IEBrowser")) == 0)
  438. {
  439. GetEntityBase()->GetFunction()->GetSysVar("IEUrl", csIEUrl);
  440. Dbg("Url:[%s]", (const char*)csIEUrl);
  441. eErrCode = pFuncPrivilege->StartEntity(pszEntityName, csIEUrl, spWait);
  442. }
  443. else
  444. eErrCode = pFuncPrivilege->StartEntity(pszEntityName, NULL, spWait);
  445. if (eErrCode == Error_Succeed)
  446. {
  447. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  448. if (eErrCode != Error_Succeed)
  449. {
  450. Dbg("spwait start %s failed(%d).", pszEntityName, eErrCode);
  451. break;
  452. }
  453. Dbg("Start entity %s suc.", pszEntityName);
  454. }
  455. else
  456. {
  457. Dbg("(re)Start %s failed(%d).", pszEntityName, eErrCode);
  458. break;
  459. }
  460. }
  461. break;
  462. case ACTION_OS_RESTART:
  463. Dbg("test os restart");
  464. if (m_entRunInfo[pszEntityName].loadOpt == 1 || m_entRunInfo[pszEntityName].loadOpt == 2)
  465. LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_OS_RESTART, pszEntityName);
  466. break;
  467. case ACTION_POWER_RESTART:
  468. Dbg("test power restart");
  469. if (m_entRunInfo[pszEntityName].loadOpt == 1 || m_entRunInfo[pszEntityName].loadOpt == 2)
  470. LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_POWER_RESTART, pszEntityName);
  471. break;
  472. default:
  473. break;
  474. }
  475. if (bUpgrade)
  476. {
  477. LogActionProcess(pszEntityName, eCode, eAction);
  478. }
  479. }
  480. else
  481. {
  482. Dbg("%s not configured,use default setting(%d)", LPCTSTR(pszEntityName), eCode);
  483. switch (eCode)
  484. {
  485. case Error_TimeOut:
  486. case Error_Unexpect:
  487. case Error_InvalidState:
  488. {
  489. eErrCode = pFuncPrivilege->StopEntity(pszEntityName, spWait);
  490. if (eErrCode == Error_Succeed)
  491. {
  492. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  493. if (eErrCode != Error_Succeed)
  494. {
  495. Dbg("spwait stop %s failed(%d).", pszEntityName, eErrCode);
  496. eErrCode = pFuncPrivilege->TerminateEntity(pszEntityName, spWait);
  497. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  498. if (eErrCode != Error_Succeed)
  499. {
  500. Dbg("spwait terminate %s failed(%d).", pszEntityName, eErrCode);
  501. break;
  502. }
  503. }
  504. }
  505. else
  506. {
  507. Dbg("Stop %s failed(%d).", pszEntityName, eErrCode);
  508. break;
  509. }
  510. Sleep(5000);
  511. CSimpleStringA csIEUrl;
  512. if (_strnicmp("IEBrowser", pszEntityName, strlen("IEBrowser")) == 0)
  513. {
  514. GetEntityBase()->GetFunction()->GetSysVar("IEUrl", csIEUrl);
  515. Dbg("Url:[%s]", (const char*)csIEUrl);
  516. eErrCode = pFuncPrivilege->StartEntity(pszEntityName, csIEUrl, spWait);
  517. }
  518. else
  519. eErrCode = pFuncPrivilege->StartEntity(pszEntityName, NULL, spWait);
  520. if (eErrCode == Error_Succeed)
  521. {
  522. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  523. if (eErrCode != Error_Succeed)
  524. {
  525. Dbg("spwait start %s failed(%d).", pszEntityName, eErrCode);
  526. break;
  527. }
  528. }
  529. else
  530. {
  531. Dbg("(re)Start %s failed(%d).", pszEntityName, eErrCode);
  532. break;
  533. }
  534. }
  535. break;
  536. default:
  537. break;
  538. }
  539. }
  540. return eErrCode;
  541. }
  542. ErrorCodeEnum CSelfCheckerFSM::CheckEntity(const char *pszEntityName,EntityTestEnum eTestType)
  543. {
  544. //oilyang@20170926 no need to check by self.Let the HealthManager entity to do it.
  545. if (pszEntityName != NULL && strnicmp(pszEntityName, GetEntityBase()->GetEntityName(), strlen(GetEntityBase()->GetEntityName())) == 0)
  546. return Error_Succeed;
  547. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  548. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  549. CSmartPointer<IAsynWaitSp> spWait;
  550. ErrorCodeEnum errCode;
  551. errCode = pFuncPrivilege->TestEntity(pszEntityName,eTestType,spWait);
  552. if (errCode == Error_Succeed)
  553. {
  554. callback_entry *entry = new callback_entry();
  555. entry->pRawData = NULL;
  556. entry->EntityName = pszEntityName;
  557. entry->ErrorResult = Error_Unexpect;
  558. entry->op = Test_ShakeHand;
  559. spWait->SetCallback(this, entry);
  560. }
  561. else
  562. Dbg("Test %s,%d",pszEntityName,errCode);
  563. //errCode = ExceptionErrorProcess(pszEntityName,errCode);
  564. return errCode;
  565. }
  566. void CSelfCheckerFSM::OnNormalWorkTimerout(void *pData)
  567. {
  568. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  569. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  570. CSmartPointer<IAsynWaitSp> spWait;
  571. ErrorCodeEnum errCode;
  572. //CSelfCheckerEntity* pEntity = ((CSelfCheckerEntity*)m_pEntity);
  573. // pEntity->GetActiveCount();
  574. int activeEnCount = m_activeEntity.size();
  575. vector<CSimpleStringA>::iterator it;
  576. //oiltmp 20131219
  577. //GetSystemCPUStatus();
  578. //GetSystemMemoryStatus();
  579. //GetSystemDiskStatus();
  580. for (it = m_activeEntity.begin();it != m_activeEntity.end(); ++it)
  581. {
  582. errCode = CheckEntity(*it,Test_ShakeHand);
  583. CEntityRunInfo runInfo;
  584. pFunc->GetEntityRunInfo(*it,runInfo);
  585. CheckEntityResouce(*it,runInfo);
  586. }
  587. GetEntityBase()->GetFunction()->ResetTimer(TIMER_ID_CHECK,MAX_CHECK_TIME);
  588. if (m_simulateTest)//oiltest
  589. {
  590. Dbg("simulate logevent framework restart");
  591. LogEvent(Severity_Middle,Event_Req_Framework_Restart,"oiltest");
  592. m_simulateTest = false;
  593. }
  594. }
  595. void CSelfCheckerFSM::OnCalcCpuUsageTimerout(void *pData)
  596. {
  597. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  598. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  599. CSmartPointer<IAsynWaitSp> spWait;
  600. ErrorCodeEnum errCode;
  601. int activeEnCount = m_activeEntity.size();
  602. vector<CSimpleStringA>::iterator it;
  603. for (it = m_activeEntity.begin(); it != m_activeEntity.end(); ++it)
  604. {
  605. CEntityRunInfo runInfo;
  606. pFunc->GetEntityRunInfo(*it, runInfo);
  607. CalcEntityCpuUsage(*it, runInfo, m_bFirstCalcCpu);
  608. CheckEntityResouce(*it, runInfo);
  609. }
  610. GetSystemCPUStatus();
  611. GetSystemMemoryStatus();
  612. GetSystemDiskStatus();
  613. m_bFirstCalcCpu = !m_bFirstCalcCpu;
  614. GetEntityBase()->GetFunction()->ResetTimer(TIMER_CPU_CHECK, MAX_CPU_CHECK_TIME*2);
  615. }
  616. ErrorCodeEnum CSelfCheckerFSM::GetAllLiveEntity(CAutoArray<CSimpleString> &allEntitys)
  617. {
  618. allEntitys.Clear();
  619. vector<CSimpleStringA>::iterator it;
  620. int start = 0;
  621. int size = m_allEntity.size();
  622. allEntitys.Init(size);
  623. CSimpleStringA testStr = "";
  624. for (it = m_allEntity.begin(); it != m_allEntity.end(); ++it,++start)
  625. {
  626. CSimpleStringA tmpName = *it;
  627. allEntitys[start] = tmpName;
  628. testStr += tmpName;
  629. testStr += ";";
  630. }
  631. Dbg("allentity[%d][%s]",allEntitys.GetCount(),(const char*)testStr);
  632. return Error_Succeed;
  633. }
  634. //ErrorCodeEnum CSelfCheckerFSM::AddEntity(const char *pszEntityName)
  635. //{
  636. // if (pszEntityName == NULL)
  637. // return Error_Null;
  638. // m_activeEntity.push_back(pszEntityName);
  639. // m_allEntity.push_back(pszEntityName);
  640. //
  641. // return Error_Succeed;
  642. //}
  643. //ErrorCodeEnum CSelfCheckerFSM::RemoveEntity(const char *pszEntityName)
  644. //{
  645. // if (pszEntityName == NULL)
  646. // return Error_Null;
  647. // vector<CSimpleStringA>::iterator it;
  648. // for (it = m_activeEntity.begin(); it != m_activeEntity.end(); ++it)
  649. // {
  650. // if(!strncmp(pszEntityName,*it,it->GetLength()))
  651. // {
  652. // m_activeEntity.erase(it);
  653. // break;
  654. // }
  655. // }
  656. // return Error_Succeed;
  657. //}
  658. void CSelfCheckerFSM::DoOnCreated(const char *pszEntityName,ErrorCodeEnum eOnStartErrorCode,const char *pszCallerEntity)
  659. {
  660. if (eOnStartErrorCode == Error_Succeed)
  661. {
  662. vector<CSimpleStringA>::iterator it,itAct;
  663. bool bFound = false, bActFound = false;
  664. Dbg("oncreated %s",pszEntityName);
  665. for (it = m_allEntity.begin(); it != m_allEntity.end(); ++it)
  666. {
  667. if(!strncmp(pszEntityName,*it,it->GetLength()))
  668. {
  669. Dbg("already exist %s",pszEntityName);
  670. bFound = true;
  671. break;
  672. }
  673. }
  674. if(!bFound)
  675. m_allEntity.push_back(pszEntityName);
  676. for (itAct = m_activeEntity.begin(); itAct != m_activeEntity.end(); ++itAct)
  677. {
  678. if(!strncmp(pszEntityName,*itAct,itAct->GetLength()))
  679. {
  680. Dbg("active entity already exist %s",pszEntityName);
  681. bActFound = true;
  682. break;
  683. }
  684. }
  685. if (!bActFound)
  686. {
  687. m_activeEntity.push_back(pszEntityName);
  688. }
  689. m_entCfgInfo[pszEntityName].entityRestartCount = 0;
  690. }
  691. }
  692. void CSelfCheckerFSM::DoOnClosed(const char *pszEntityName,EntityCloseCauseEnum eCloseCause,ErrorCodeEnum eOnCloseErrorCode,const char *pszCallerEntity)
  693. {
  694. //not close by selfchecker
  695. if (strncmp(pszCallerEntity,GetEntityBase()->GetEntityName(),strlen(pszCallerEntity)))
  696. {
  697. if (eCloseCause == CloseCause_Self || eCloseCause == CloseCause_Other)
  698. {
  699. vector<CSimpleStringA>::iterator it;
  700. for (it = m_activeEntity.begin(); it != m_activeEntity.end(); ++it)
  701. {
  702. if(!strncmp(pszEntityName,*it,it->GetLength()))
  703. {
  704. Dbg("onclosed %s",pszEntityName);
  705. m_activeEntity.erase(it);
  706. break;
  707. }
  708. }
  709. }
  710. }
  711. CAutoArray<CSimpleString> testAutoArray;
  712. GetAllLiveEntity(testAutoArray);
  713. }
  714. void CSelfCheckerFSM::DoOnException(const char *pszEntityName,const char *pszFunctionName,EntityStateEnum eState,EntityStateEnum eLastState,ErrorCodeEnum eErrorCode)
  715. {
  716. Dbg("OnException:%s,%s,%d,%d,%d",pszEntityName,pszFunctionName,eState,eLastState,eErrorCode);
  717. }
  718. void CSelfCheckerFSM::OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp)
  719. {
  720. CSmartPointer<ICallbackListener> spCallback;
  721. CSmartPointer<IReleasable> pData;
  722. pAsynWaitSp->GetCallback(spCallback, pData);
  723. //LOG_ASSERT(pData);
  724. callback_entry *entry = dynamic_cast<callback_entry*>((IReleasable*)pData.GetRawPointer());
  725. entry->ErrorResult = pAsynWaitSp->AsyncGetAnswer();
  726. callback_entry *new_entry = new callback_entry();
  727. new_entry->EntityName = entry->EntityName;
  728. new_entry->ErrorResult = entry->ErrorResult;
  729. new_entry->op = entry->op;
  730. new_entry->state = entry->state;
  731. m_entRunInfo[new_entry->EntityName].eTest = new_entry->ErrorResult; //add test result oilyang 20150616
  732. //m_entRunInfo[new_entry->EntityName].eState = 9; //add test result oilyang 20150616
  733. //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);
  734. if (new_entry->op == Test_ShakeHand && new_entry->ErrorResult != Error_Succeed)
  735. Dbg("oiltmp shakehand %s,(r)%d,(state)%d",(LPCTSTR)new_entry->EntityName,new_entry->ErrorResult,new_entry->state);
  736. if (new_entry->ErrorResult != Error_Succeed)
  737. {
  738. ErrorCodeEnum eErr;
  739. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  740. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  741. CEntityRunInfo ieInfo;
  742. eErr = pFunc->GetEntityRunInfo("IEBrowser",ieInfo);
  743. bool bIEStarted = false;
  744. if (eErr == Error_Succeed && ieInfo.eState != EntityState_NoStart)
  745. bIEStarted = true;
  746. if (_strnicmp("MediaController", (const char*)new_entry->EntityName, strlen("MediaController")) == 0
  747. && !bIEStarted)
  748. {
  749. Dbg("On loading stage,don't process MediaController exception.");
  750. }
  751. else
  752. //ExceptionErrorProcess(new_entry->EntityName,new_entry->ErrorResult);
  753. Proc((const char*)new_entry->EntityName,ProcType_Shake,new_entry->ErrorResult);
  754. }
  755. else
  756. {
  757. CSmartPointer<IEntityFunction> spEntityFunction = GetEntityBase()->GetFunction();
  758. CSmartPointer<IConfigInfo> spConfig;
  759. ErrorCodeEnum eErr = spEntityFunction->OpenConfig(Config_Run, spConfig);
  760. if (eErr != Error_Succeed) {
  761. Dbg("open run cfg file failed!");
  762. return;
  763. }
  764. spConfig->WriteConfigValueInt(new_entry->EntityName,"OsRestart",0);
  765. spConfig->WriteConfigValueInt(new_entry->EntityName,"PowerRestart",0);
  766. }
  767. }
  768. void CSelfCheckerFSM::LogErrInfo(const char* msgHead,const char* msgBody,const int errCode)
  769. {
  770. //oiltest to redifine this
  771. Dbg("%s,%s,%d",msgHead,msgBody,errCode);
  772. }
  773. void CSelfCheckerFSM::LogActionProcess(const char *pszEntityName,ErrorCodeEnum errCode,TestActionEnum eAct)
  774. {
  775. Dbg("LogActionProcess:entity[%s],errCode[%d],eAction[%d]",pszEntityName,errCode,eAct);
  776. CSmartPointer<IEntityFunction> spEntityFunction = GetEntityBase()->GetFunction();
  777. CSmartPointer<IConfigInfo> spConfig;
  778. ErrorCodeEnum eErr = spEntityFunction->OpenConfig(Config_Run, spConfig);
  779. if (eErr != Error_Succeed) {
  780. Dbg("open run cfg file failed!");
  781. return;
  782. }
  783. int osTimes,powerTimes;
  784. osTimes = powerTimes = 0;
  785. spConfig->ReadConfigValueInt(pszEntityName,"OsRestart",osTimes);
  786. spConfig->ReadConfigValueInt(pszEntityName,"PowerRestart",powerTimes);
  787. switch(eAct)
  788. {
  789. case ACTION_ENTITY_RESTART:
  790. if (osTimes > m_maxOsRestart || powerTimes > m_maxPowerRestart)
  791. {
  792. Dbg("restart too much,give up[%d][%d].",osTimes,powerTimes);
  793. break;
  794. }
  795. //if not the KEY entity,don't upgrade to restart computer
  796. //if (!IsKeyEntity(pszEntityName))
  797. break;
  798. osTimes++;
  799. powerTimes++;
  800. spConfig->WriteConfigValueInt(pszEntityName,"OsRestart",osTimes);
  801. spConfig->WriteConfigValueInt(pszEntityName,"PowerRestart",powerTimes);
  802. //for simple and effective,use power restart only
  803. LogEvent(Severity_Middle,LOG_EVT_SELFCHECK_POWER_RESTART,pszEntityName);
  804. m_entCfgInfo[pszEntityName].bWaitRestart = true;
  805. break;
  806. default:
  807. break;
  808. }
  809. }
  810. #ifdef RVC_OS_WIN
  811. ULONGLONG subtractTime(const FILETIME &a, const FILETIME &b)
  812. {
  813. LARGE_INTEGER la, lb;
  814. la.LowPart = a.dwLowDateTime;
  815. la.HighPart = a.dwHighDateTime;
  816. lb.LowPart = b.dwLowDateTime;
  817. lb.HighPart = b.dwHighDateTime;
  818. return la.QuadPart - lb.QuadPart;
  819. }
  820. float getUsage(HANDLE hProcess,FILETIME *prevSysKernel, FILETIME *prevSysUser,
  821. FILETIME *prevProcKernel, FILETIME *prevProcUser,
  822. bool firstRun = false)
  823. {
  824. FILETIME sysIdle, sysKernel, sysUser;
  825. FILETIME procCreation, procExit, procKernel, procUser;
  826. if (!GetSystemTimes(&sysIdle, &sysKernel, &sysUser) ||
  827. !GetProcessTimes(hProcess, &procCreation, &procExit, &procKernel, &procUser))
  828. {
  829. // can't get time info so return
  830. return -1.;
  831. }
  832. // check for first call
  833. if (firstRun)
  834. {
  835. // save time info before return
  836. prevSysKernel->dwLowDateTime = sysKernel.dwLowDateTime;
  837. prevSysKernel->dwHighDateTime = sysKernel.dwHighDateTime;
  838. prevSysUser->dwLowDateTime = sysUser.dwLowDateTime;
  839. prevSysUser->dwHighDateTime = sysUser.dwHighDateTime;
  840. prevProcKernel->dwLowDateTime = procKernel.dwLowDateTime;
  841. prevProcKernel->dwHighDateTime = procKernel.dwHighDateTime;
  842. prevProcUser->dwLowDateTime = procUser.dwLowDateTime;
  843. prevProcUser->dwHighDateTime = procUser.dwHighDateTime;
  844. return -1.;
  845. }
  846. ULONGLONG sysKernelDiff = subtractTime(sysKernel, *prevSysKernel);
  847. ULONGLONG sysUserDiff = subtractTime(sysUser, *prevSysUser);
  848. ULONGLONG procKernelDiff = subtractTime(procKernel, *prevProcKernel);
  849. ULONGLONG procUserDiff = subtractTime(procUser, *prevProcUser);
  850. ULONGLONG sysTotal = sysKernelDiff + sysUserDiff;
  851. ULONGLONG procTotal = procKernelDiff + procUserDiff;
  852. return (float)((100.0 * procTotal) / sysTotal);
  853. }
  854. #else
  855. //oiltestlinux
  856. #endif //RVC_OS_WIN
  857. void CSelfCheckerFSM::CheckEntityResouce(const char *pszEntityName,CEntityRunInfo &info)
  858. {
  859. if (info.eState != EntityState_Idle)
  860. return;
  861. #ifdef RVC_OS_WIN
  862. HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_QUERY_LIMITED_INFORMATION,FALSE,info.dwProcessID);
  863. if (hProcess == NULL)
  864. {
  865. Dbg("OpenProcess %s failed %d.",pszEntityName,GetLastError());
  866. return;
  867. }
  868. //GetSystemInfo
  869. PIO_COUNTERS pIOCounters = new IO_COUNTERS;
  870. BOOL ret = GetProcessIoCounters(hProcess,pIOCounters);
  871. if (ret == 0)
  872. {
  873. Dbg("GetProcessIoCounters %s failed %d.",pszEntityName,GetLastError());
  874. }
  875. PROCESS_MEMORY_COUNTERS pmc;
  876. const int showSize = 20;
  877. if (GetProcessMemoryInfo(hProcess,&pmc,sizeof(pmc)))
  878. {
  879. if ((pmc.WorkingSetSize/MILLION > showSize) && (pmc.PeakWorkingSetSize/MILLION > showSize)
  880. && (pmc.PagefileUsage/MILLION > showSize) && (pmc.PeakPagefileUsage/MILLION > showSize))
  881. {
  882. m_entRunInfo[pszEntityName].memoryHighCount++;
  883. if (m_entRunInfo[pszEntityName].memoryHighCount > ((60000 / MAX_CPU_CHECK_TIME)) * 2)//more than 2 minutes
  884. {
  885. m_entRunInfo[pszEntityName].memoryHighCount = 0;
  886. Dbg("%s,WorkingSetSize %u, Peak %u,PageFileUsage %u, Peak %u", (LPCTSTR)pszEntityName, pmc.WorkingSetSize / MILLION, pmc.PeakWorkingSetSize / MILLION, pmc.PagefileUsage / MILLION, pmc.PeakPagefileUsage / MILLION);
  887. }
  888. }
  889. }
  890. //Dbg can't support the ULONGLONG...oilyang 20140730
  891. //Dbg("Entity %s:",pszEntityName);
  892. //Dbg("read op %u,write op %u",pIOCounters->ReadOperationCount,pIOCounters->WriteOperationCount);
  893. //Dbg("read transfer %u,write transfer %u",pIOCounters->ReadTransferCount,pIOCounters->WriteTransferCount);
  894. //Dbg("other op %u,other transfer %u",pIOCounters->OtherOperationCount,pIOCounters->OtherTransferCount);
  895. CloseHandle(hProcess);
  896. #else
  897. return;//oiltestlinux
  898. #endif //RVC_OS_WIN
  899. }
  900. void CSelfCheckerFSM::CalcEntityCpuUsage(const char *pszEntityName, CEntityRunInfo &info,bool bFirst)
  901. {
  902. if (info.eState != EntityState_Idle)
  903. return;
  904. #ifdef RVC_OS_WIN
  905. HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_QUERY_LIMITED_INFORMATION, FALSE, info.dwProcessID);
  906. if (hProcess == NULL)
  907. {
  908. Dbg("OpenProcess %s failed %d.", pszEntityName, GetLastError());
  909. return;
  910. }
  911. float ret = getUsage(hProcess, &(m_entRunInfo[pszEntityName].prevSysKernel), &(m_entRunInfo[pszEntityName].prevSysUser)
  912. , &(m_entRunInfo[pszEntityName].prevProcKernel), &(m_entRunInfo[pszEntityName].prevProcUser),bFirst);
  913. if (!bFirst && ret > 2 && ret < 100)//where a entity have been restarted,the bFirst flag maybe wrong,the 'ret' can be big than 100!
  914. {
  915. Dbg("entity %s,cpu ratio:%f", pszEntityName, ret);
  916. m_entRunInfo[pszEntityName].cpuRatio = ret;
  917. }
  918. CloseHandle(hProcess);
  919. #else
  920. return;//oiltestlinux
  921. #endif //RVC_OS_WIN
  922. }
  923. void CSelfCheckerFSM::GetSystemMemoryStatus()
  924. {
  925. #ifdef RVC_OS_WIN
  926. // Use to convert bytes to KB
  927. #define DIV 1024
  928. // Specify the width of the field in which to print the numbers.
  929. // The asterisk in the format specifier "%*I64d" takes an integer
  930. // argument and uses it to pad and right justify the number.
  931. #define WIDTH 7
  932. MEMORYSTATUSEX statex;
  933. statex.dwLength = sizeof (statex);
  934. GlobalMemoryStatusEx (&statex);
  935. if (statex.dwMemoryLoad > m_memHighPercent)
  936. {
  937. Dbg("memory used: %*ld .", WIDTH, statex.dwMemoryLoad);
  938. LogWarn(Severity_Low, Error_Resource, LOG_EVT_SELFCHECK_MEMORY_TOO_HIGH, "Free memory is few.");
  939. }
  940. //Dbg ("(physical)%*I64d,(phy free)%*I64d,(paging)%*I64d,(pg free)%*I64d,(virtaul)%*I64d,(vt free)%*I64d",
  941. // WIDTH, statex.ullTotalPhys/DIV,WIDTH, statex.ullAvailPhys/DIV,WIDTH, statex.ullTotalPageFile/DIV
  942. // ,WIDTH, statex.ullAvailPageFile/DIV,WIDTH, statex.ullTotalVirtual/DIV,WIDTH, statex.ullAvailVirtual/DIV);
  943. // Show the amount of extended memory available.
  944. //Dbg ("There are %*I64d free Kbytes of extended memory.\n",WIDTH, statex.ullAvailExtendedVirtual/DIV);
  945. #else
  946. //oiltestlinux
  947. #endif
  948. }
  949. void CSelfCheckerFSM::GetSystemCPUStatus()
  950. {
  951. #ifdef RVC_OS_WIN
  952. #define _WIN32_WINNT 0x0601
  953. FILETIME idleTime,kernelTime,userTime;
  954. BOOL ret = GetSystemTimes(&idleTime,&kernelTime,&userTime);
  955. if (ret == 0)
  956. {
  957. Dbg("GetSystemCPUStatus.GetSystemTimes failed(%d).",GetLastError());
  958. return;
  959. }
  960. __int64 xIdle,xKernel,xUser;
  961. xIdle = idleTime.dwHighDateTime;
  962. xIdle <<= 32;
  963. xIdle |= idleTime.dwLowDateTime;
  964. xKernel = kernelTime.dwHighDateTime;
  965. xKernel <<= 32;
  966. xKernel |= kernelTime.dwLowDateTime;
  967. xUser = userTime.dwHighDateTime;
  968. xUser <<= 32;
  969. xUser |= userTime.dwLowDateTime;
  970. //Dbg("%u,%u,%u,%u,%u,%u",idleTime.dwHighDateTime,idleTime.dwLowDateTime,kernelTime.dwHighDateTime,kernelTime.dwLowDateTime,userTime.dwHighDateTime,userTime.dwLowDateTime);
  971. if (m_xIdlePre != 0)
  972. {
  973. __int64 xI,xK,xU;
  974. xI = xIdle - m_xIdlePre;
  975. xK = xKernel - m_xKernelPre;
  976. xU = xUser - m_xUserPre;
  977. int ratio = 0;
  978. if ((xK +xU) != 0)
  979. ratio = (xK - xI + xU) * 100 / (xK + xU);
  980. if (ratio > 50)//oiltmp@20170919 need to read from configure file?maybe or not
  981. Dbg("cpu %d",ratio);
  982. if (ratio > m_cpuHighPercent)
  983. {
  984. CSimpleStringA cpuHighEntitys("");
  985. char cpuRatioBuf[16];
  986. ZeroMemory(cpuRatioBuf, sizeof(cpuRatioBuf));
  987. map<CSimpleStringA, EntityRunInfo>::iterator it;
  988. for (it = m_entRunInfo.begin(); it != m_entRunInfo.end(); ++it)
  989. {
  990. if (it->second.cpuRatio > 0 && it->second.cpuRatio < 100)
  991. {
  992. itoa(it->second.cpuRatio, cpuRatioBuf, 10);
  993. cpuHighEntitys.Append(it->first + ":" + cpuRatioBuf + "||");
  994. }
  995. }
  996. Dbg("cpu ratio:%s",(const char*)cpuHighEntitys);
  997. LogWarn(Severity_Low, Error_Resource, LOG_EVT_SELFCHECK_CPU_TOO_HIGH, (const char*)cpuHighEntitys);
  998. }
  999. }
  1000. m_xIdlePre = xIdle;
  1001. m_xKernelPre = xKernel;
  1002. m_xUserPre = xUser;
  1003. int warnLevel;
  1004. CSimpleStringA strList("");
  1005. #else
  1006. //oiltestlinux
  1007. #endif //RVC_OS_WIN
  1008. }
  1009. void CSelfCheckerFSM::GetSystemDiskStatus()
  1010. {
  1011. #ifdef RVC_OS_WIN
  1012. ULARGE_INTEGER ulAvailFree,ulTotalBytes,ulTotalFree;
  1013. BOOL ret = GetDiskFreeSpaceEx(NULL,&ulAvailFree,&ulTotalBytes,&ulTotalFree);
  1014. if (ret == 0)
  1015. {
  1016. Dbg("GetSystemDiskStatus.GetDiskFreeSpaceEx failed(%d).",GetLastError());
  1017. return;
  1018. }
  1019. //Dbg("%d,%d,%d",(ulAvailFree.QuadPart/MILLION)*100,ulTotalBytes.QuadPart,(ulTotalBytes.QuadPart/MILLION));
  1020. DWORD dwAvFree = ulAvailFree.QuadPart/MILLION;
  1021. DWORD dwTotal = ulTotalBytes.QuadPart/MILLION;
  1022. DWORD dwTotalFree = ulTotalFree.QuadPart/MILLION;
  1023. int ratio = dwTotalFree*100/dwTotal;
  1024. if ((100 - ratio) > m_diskHighPercent)
  1025. {
  1026. Dbg("The disk has %d MB(%d%) available.\n", dwTotalFree, ratio);
  1027. //oilyang@20200526 根据wq建议,降低磁盘空间偏少的告警频率
  1028. SYSTEMTIME localTime;
  1029. GetLocalTime(&localTime);
  1030. if (m_diskLastWarnHour != localTime.wHour)
  1031. {
  1032. m_diskLastWarnHour = localTime.wHour;
  1033. CSmartPointer<IConfigInfo> spConfigRun;
  1034. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfigRun);
  1035. if (eErr == Error_Succeed) {
  1036. spConfigRun->WriteConfigValueInt("WarnRecord", "disk", m_diskLastWarnHour);
  1037. }
  1038. LogWarn(Severity_Low, Error_Resource, LOG_EVT_SELFCHECK_HARDDISK_TOO_HIGH, "Harddisk free space is few.");
  1039. }
  1040. }
  1041. #else
  1042. //oiltestlinux
  1043. #endif //RVC_OS_WIN
  1044. }
  1045. bool CSelfCheckerFSM::IsKeyEntity(const char *pszEntityName)
  1046. {
  1047. vector<CSimpleStringA>::iterator it;
  1048. for (it = m_vKeyEntity.begin(); it != m_vKeyEntity.end(); ++it)
  1049. {
  1050. if (!_strnicmp(pszEntityName,*it,strlen(pszEntityName)))
  1051. return true;
  1052. }
  1053. return false;
  1054. }
  1055. int CSelfCheckerFSM::AddEntityState(const char *pszEntityName,EntityStateEnum eState)
  1056. {
  1057. if (eState == EntityState_Starting)
  1058. {
  1059. m_entRunInfo[pszEntityName].bGetLoadOpt = false;
  1060. m_entRunInfo[pszEntityName].bRestarting = false;
  1061. m_entRunInfo[pszEntityName].loadOpt = 99;
  1062. m_entRunInfo[pszEntityName].eState = eState;
  1063. m_entRunInfo[pszEntityName].eTest = Error_Succeed;
  1064. }
  1065. else
  1066. m_entRunInfo[pszEntityName].eState = eState;
  1067. Dbg("ADDDDD %s,%d,%d,%d",pszEntityName,m_entRunInfo[pszEntityName].eState,m_entRunInfo[pszEntityName].eTest,eState);
  1068. if (eState == EntityState_Idle)
  1069. {
  1070. m_entRunInfo[pszEntityName].eTest = Error_Succeed;
  1071. m_entRunInfo[pszEntityName].memoryHighCount = 0;
  1072. }
  1073. m_entRunInfo[pszEntityName].cpuRatio = 0;
  1074. return 0;
  1075. }
  1076. ErrorCodeEnum CSelfCheckerFSM::GetEntityErrorList(int &warmLevel,CSimpleStringA &strList)
  1077. {
  1078. map<CSimpleStringA,EntityRunInfo>::iterator it;
  1079. CSimpleStringA tmpStr("");
  1080. bool bLost = false;
  1081. for (it = m_entRunInfo.begin(); it != m_entRunInfo.end(); ++it)
  1082. {
  1083. if (m_entRunInfo[it->first].eState == EntityState_Lost)
  1084. bLost = true;
  1085. char buf[16],bufTest[16];
  1086. ZeroMemory(buf,16);
  1087. ZeroMemory(bufTest, 16);
  1088. //Dbg("oiltest20160425[%s],%d,%d", (const char*)it->first, m_entRunInfo[it->first].eState, m_entRunInfo[it->first].eTest);
  1089. if (m_entRunInfo[it->first].eState == EntityState_Lost || m_entRunInfo[it->first].eState == EntityState_Close
  1090. || m_entRunInfo[it->first].eState == EntityState_Killed || m_entRunInfo[it->first].eTest != Error_Succeed)
  1091. {
  1092. tmpStr += it->first;
  1093. tmpStr += "=";
  1094. if (m_entRunInfo[it->first].eState == EntityState_Lost || m_entRunInfo[it->first].eState == EntityState_Close
  1095. || m_entRunInfo[it->first].eState == EntityState_Killed)
  1096. {
  1097. _itoa(m_entRunInfo[it->first].eState, buf, 10);
  1098. tmpStr += buf;
  1099. }
  1100. if (m_entRunInfo[it->first].eTest != Error_Succeed)
  1101. {
  1102. Dbg("[%s],%d,%d", (const char*)it->first, m_entRunInfo[it->first].eState, m_entRunInfo[it->first].eTest);
  1103. _itoa(m_entRunInfo[it->first].eTest, bufTest, 10);
  1104. tmpStr += ",(selfcheck code):";
  1105. tmpStr += bufTest;
  1106. }
  1107. tmpStr += ";";
  1108. }
  1109. }
  1110. if (tmpStr.GetLength() < 2)
  1111. m_warmLevel = warmLevel = 0;
  1112. if (bLost)
  1113. m_warmLevel = warmLevel = 3;
  1114. m_warmLevel = warmLevel = 1;//for temp set 20150617
  1115. strList = tmpStr;
  1116. if (strList.GetLength() > 2)
  1117. Dbg("warnlevel:%d,ErrorList [%s]", m_warmLevel,(LPCTSTR)strList);
  1118. return Error_Succeed;
  1119. }
  1120. int CSelfCheckerFSM::Proc(string entity, ProcType eType, DWORD dwCode, const char *pszMessage)
  1121. {
  1122. ConnectToHealthManager();
  1123. if (!m_entRunInfo[entity.c_str()].bGetLoadOpt)
  1124. {
  1125. if (m_pHealthClient != NULL)
  1126. {
  1127. HealthManagerService_GetEntityCfgInfo_Req req;
  1128. HealthManagerService_GetEntityCfgInfo_Ans ans;
  1129. req.name = entity.c_str();
  1130. ErrorCodeEnum errCode = m_pHealthClient->GetEntityCfgInfo(req, ans, 10000);
  1131. if (errCode == Error_Succeed)
  1132. {
  1133. m_entRunInfo[entity.c_str()].bGetLoadOpt = true;
  1134. Dbg("to get entity cfg info suc:%d", ans.loadOpt);
  1135. SetEntityCfgInfo(entity.c_str(), ans.loadOpt);
  1136. }
  1137. }
  1138. }
  1139. map<string, EntityCfg, EntityNameCompare>::iterator it;
  1140. if ((it = m_mapEntity.find(entity.c_str())) == m_mapEntity.end())
  1141. {
  1142. Dbg("can't find entity %s configure setting,using default setting.",entity.c_str());
  1143. //Error_TimeOut:
  1144. //Error_Unexpect:
  1145. //Error_InvalidState:
  1146. if (eType == ProcType_Shake && (dwCode == Error_TimeOut || dwCode == Error_Unexpect || dwCode == Error_InvalidState))
  1147. ExceptionErrorProcessXml(eType,entity.c_str(), ACTION_ENTITY_RESTART,true);
  1148. else if (eType == ProcType_Warn)
  1149. ExceptionErrorProcessXml(eType, entity.c_str(), dwCode, true, pszMessage);
  1150. else
  1151. Dbg("What's this:type:%d,receive code:%x,msg:%s, from entity %s.", eType, dwCode, pszMessage, entity.c_str());
  1152. return -1;
  1153. }
  1154. vector<ProcItem>::iterator vIt, vEnd;
  1155. if (eType == ProcType_Shake)
  1156. {
  1157. vIt = it->second.vShake.begin();
  1158. vEnd = it->second.vShake.end();
  1159. }
  1160. else if (eType == ProcType_Warn)
  1161. {
  1162. vIt = it->second.vWarn.begin();
  1163. vEnd = it->second.vWarn.end();
  1164. }
  1165. for (; vIt != vEnd; vIt++)
  1166. {
  1167. if (vIt->code == dwCode)
  1168. {
  1169. if (vIt->upgradecount > 0)
  1170. {
  1171. Dbg("action size:%d,upgradecount:%d", vIt->proctime.size(), vIt->upgradecount);
  1172. UINT64 happentime = GetTickCountRVC();
  1173. if (vIt->proctime.size() < vIt->upgradecount - 1)//just add record,do nothing
  1174. {
  1175. vIt->proctime.push_back(happentime);
  1176. Dbg("just add record");
  1177. return 0;
  1178. }
  1179. else
  1180. {
  1181. //to find the 1st record happened in last upgradetime minute
  1182. //and remove the record happened far ago(upgradetime minutes before)
  1183. vector<UINT64>::iterator ittime, itFisrtInPeriod, xxxIt;
  1184. bool bFar = false;
  1185. int count = 0;
  1186. for (ittime = vIt->proctime.begin(); ittime != vIt->proctime.end(); ittime++)
  1187. {
  1188. itFisrtInPeriod = ittime;
  1189. UINT64 difftime = happentime - *ittime;
  1190. if (difftime / (1000 * 60) < vIt->upgradetime)
  1191. break;
  1192. else
  1193. {
  1194. count++;
  1195. Dbg("the %d th action",count);
  1196. bFar = true;
  1197. }
  1198. }
  1199. if (!bFar)
  1200. {
  1201. //to do upgrade action
  1202. Dbg("to do upgrade action");
  1203. ExceptionErrorProcessXml(eType,entity.c_str(), vIt->upgradeaction);
  1204. vIt->proctime.clear();
  1205. return 0;
  1206. }
  1207. else
  1208. {
  1209. if (count == 1 && vIt->proctime.size() == 1)
  1210. vIt->proctime.clear();
  1211. else
  1212. vIt->proctime.erase(vIt->proctime.begin(), itFisrtInPeriod);
  1213. for (xxxIt = vIt->proctime.begin(); xxxIt != vIt->proctime.end(); xxxIt++)
  1214. {
  1215. cout << *xxxIt << " # ";
  1216. }
  1217. cout << endl;
  1218. vIt->proctime.push_back(happentime);
  1219. for (xxxIt = vIt->proctime.begin(); xxxIt != vIt->proctime.end(); xxxIt++)
  1220. {
  1221. cout << *xxxIt << " * ";
  1222. }
  1223. Dbg("after clear,add record");
  1224. return 0;
  1225. }
  1226. }
  1227. }
  1228. Dbg("Entity %s receive %d,to do action:%d", entity.c_str(), dwCode, vIt->action);
  1229. ExceptionErrorProcessXml(eType,entity.c_str(), vIt->action,true, pszMessage);
  1230. return 0;
  1231. }
  1232. }
  1233. Dbg("can't find corresponding action of entity %s,type:%d,code:%x",entity.c_str(),eType,dwCode);
  1234. Dbg("use default process...");
  1235. if (eType == ProcType_Shake && (dwCode == Error_TimeOut || dwCode == Error_Unexpect || dwCode == Error_InvalidState))
  1236. ExceptionErrorProcessXml(eType, entity.c_str(), ACTION_ENTITY_RESTART, true);
  1237. else if (eType == ProcType_Warn)
  1238. ExceptionErrorProcessXml(eType, entity.c_str(), dwCode, true, pszMessage);
  1239. return -1;
  1240. }
  1241. bool CSelfCheckerFSM::ReadXmlFile(const char *szFileName)
  1242. {//读取Xml文件,并遍历
  1243. //MessageBox(0, 0, 0, 0);
  1244. LOG_FUNCTION();
  1245. tinyxml2::XMLDocument *doc = new tinyxml2::XMLDocument();
  1246. XMLError err = doc->LoadFile(szFileName);
  1247. if (err != XML_SUCCESS)
  1248. {
  1249. Dbg("open file %s failed.GetLastError:%d",szFileName,GetLastError());
  1250. return false;
  1251. }
  1252. //doc->GetDocument();
  1253. string out = "";
  1254. XMLNode *pF = doc->FirstChild();
  1255. XMLElement *pRoot = doc->RootElement();
  1256. //pF->FirstChildElement();
  1257. if (pRoot == NULL)
  1258. {
  1259. Dbg("Get root element failed.");
  1260. return false;
  1261. }
  1262. else
  1263. pF = pRoot->FirstChild();
  1264. while (pF != NULL)
  1265. {
  1266. if (pF->ToElement() == NULL)
  1267. {
  1268. pF = pF->FirstChild();
  1269. continue;
  1270. }
  1271. const char *pName = pF->ToElement()->Name();
  1272. if (!strncmp(pName, "SelfCheckerConfig", strlen("SelfCheckerConfig")))
  1273. {
  1274. pF = pF->FirstChild();
  1275. continue;
  1276. }
  1277. else if (!strncmp(pName, "Entity", strlen("Entity")))
  1278. {
  1279. EntityCfg entity;
  1280. const char *attrName = pF->ToElement()->Attribute("name");
  1281. out += const_cast<char*>(attrName);
  1282. out += "\r\n";
  1283. XMLNode *pChild = pF->FirstChild();
  1284. while (pChild != NULL)
  1285. {
  1286. if (!strncmp(pChild->Value(), "shakehandproc", strlen("shakehandproc")))
  1287. {
  1288. XMLNode *pProc = pChild->FirstChild();
  1289. while (pProc != NULL)
  1290. {
  1291. ProcItem item;
  1292. const char *code, *action, *upgradeaction, *upgradetime, *upgradecount;
  1293. code = action = upgradeaction = upgradetime = upgradecount = NULL;
  1294. if (pProc->ToElement() != NULL)
  1295. {
  1296. code = pProc->ToElement()->Attribute("code");
  1297. action = pProc->ToElement()->Attribute("action");
  1298. upgradeaction = pProc->ToElement()->Attribute("upgradeaction");
  1299. upgradetime = pProc->ToElement()->Attribute("upgradetime");
  1300. upgradecount = pProc->ToElement()->Attribute("upgradecount");
  1301. }
  1302. if (code != NULL)
  1303. {
  1304. item.code = CodeStrToInt(code);
  1305. Dbg("oiltest code:%s,%d", code, item.code);
  1306. out += const_cast<char*>(code);
  1307. out += " , ";
  1308. }
  1309. if (action != NULL)
  1310. {
  1311. item.action = ActionStrToInt(action);
  1312. out += const_cast<char*>(action);
  1313. out += " , ";
  1314. }
  1315. if (upgradeaction != NULL)
  1316. {
  1317. item.upgradeaction = ActionStrToInt(upgradeaction);
  1318. out += const_cast<char*>(upgradeaction);
  1319. }
  1320. if (upgradetime != NULL)
  1321. {
  1322. item.upgradetime = atoi(upgradetime);
  1323. }
  1324. if (upgradecount != NULL)
  1325. {
  1326. item.upgradecount = atoi(upgradecount);
  1327. }
  1328. else
  1329. item.upgradecount = 0;
  1330. entity.vShake.push_back(item);
  1331. out += "; ";
  1332. pProc = pProc->NextSibling();
  1333. }
  1334. }
  1335. else if (!strncmp(pChild->Value(), "eventproc", strlen("eventproc")))
  1336. {
  1337. XMLNode *pProc = pChild->FirstChild();
  1338. while (pProc != NULL)
  1339. {
  1340. ProcItem item;
  1341. const char *code, *action, *upgradeaction, *upgradetime, *upgradecount;
  1342. code = action = upgradeaction = upgradetime = upgradecount = NULL;
  1343. if (pProc->ToElement() != NULL)
  1344. {
  1345. code = pProc->ToElement()->Attribute("code");
  1346. action = pProc->ToElement()->Attribute("action");
  1347. upgradeaction = pProc->ToElement()->Attribute("upgradeaction");
  1348. upgradetime = pProc->ToElement()->Attribute("upgradetime");
  1349. upgradecount = pProc->ToElement()->Attribute("upgradecount");
  1350. }
  1351. if (code != NULL)
  1352. {
  1353. item.code = CodeStrToInt(code);
  1354. out += const_cast<char*>(code);
  1355. out += ",";
  1356. }
  1357. if (action != NULL)
  1358. {
  1359. item.action = ActionStrToInt(action);
  1360. out += const_cast<char*>(action);
  1361. out += ",";
  1362. }
  1363. if (upgradeaction != NULL)
  1364. {
  1365. item.upgradeaction = ActionStrToInt(upgradeaction);
  1366. out += const_cast<char*>(upgradeaction);
  1367. }
  1368. if (upgradetime != NULL)
  1369. {
  1370. item.upgradetime = atoi(upgradetime);
  1371. }
  1372. if (upgradecount != NULL)
  1373. {
  1374. item.upgradecount = atoi(upgradecount);
  1375. }
  1376. else
  1377. item.upgradecount = 0;
  1378. entity.vWarn.push_back(item);
  1379. out += "; ";
  1380. pProc = pProc->NextSibling();
  1381. }
  1382. }
  1383. pChild = pChild->NextSibling();
  1384. }
  1385. m_mapEntity[attrName] = entity;
  1386. Dbg("add %s,vShake size:%d,vWarn size:%d", attrName, entity.vShake.size(), entity.vWarn.size());
  1387. }
  1388. out += "\r\n";
  1389. pF = pF->NextSibling();
  1390. }
  1391. //cout << out.c_str() << endl;
  1392. return true;
  1393. }
  1394. ErrorCodeEnum CSelfCheckerFSM::ExceptionErrorProcessXml(ProcType eType, const char *pszEntityName, DWORD dwAction, bool bDefault,const char *pszMessage)
  1395. {
  1396. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  1397. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  1398. CSmartPointer<IAsynWaitSp> spWait;
  1399. ErrorCodeEnum eErrCode = Error_Unexpect;
  1400. switch (dwAction)
  1401. {
  1402. case ACTION_EXAMINE:
  1403. break;
  1404. case ACTION_RESET:
  1405. break;
  1406. case ACTION_CLOSE:
  1407. eErrCode = pFuncPrivilege->CloseEntity(pszEntityName, spWait);
  1408. if (eErrCode == Error_Succeed)
  1409. {
  1410. }
  1411. break;
  1412. case ACTION_ENTITY_RESTART:
  1413. {
  1414. if (m_entCfgInfo[pszEntityName].bWaitRestart)
  1415. {
  1416. if (!bDefault)
  1417. {
  1418. Dbg("waiting restart...");
  1419. break;
  1420. }
  1421. }
  1422. if (m_entRunInfo[pszEntityName].loadOpt == 99)
  1423. {
  1424. Dbg("not configure? name:[%s]", pszEntityName);
  1425. break;
  1426. }
  1427. //oilyang@20200407 if being restarted by selfchecker,break
  1428. if (m_entRunInfo[pszEntityName].bRestarting)
  1429. {
  1430. Dbg("%s is being restarted by selfchecker.", pszEntityName);
  1431. break;
  1432. }
  1433. //oilyang@20200403
  1434. //for fwb test,PinPad&CardSwiper can't be stop immediately
  1435. if (_strnicmp("PinPad", pszEntityName, strlen("PinPad")) == 0
  1436. || _strnicmp("CardSwiper", pszEntityName, strlen("CardSwiper")) == 0
  1437. || _strnicmp("Sensors", pszEntityName, strlen("Sensors")) == 0
  1438. || _strnicmp("IDCertificate", pszEntityName, strlen("IDCertificate")) == 0
  1439. || _strnicmp("FingerPrint", pszEntityName, strlen("FingerPrint")) == 0
  1440. || _strnicmp("DeviceControl", pszEntityName, strlen("DeviceControl")) == 0)
  1441. eErrCode = pFuncPrivilege->TerminateEntity(pszEntityName, spWait);
  1442. else
  1443. eErrCode = pFuncPrivilege->StopEntity(pszEntityName, spWait);
  1444. if (eErrCode == Error_Succeed)
  1445. {
  1446. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1447. if (eErrCode != Error_Succeed)
  1448. {
  1449. Dbg("spwait stop %s failed(%d).", pszEntityName, eErrCode);
  1450. eErrCode = pFuncPrivilege->TerminateEntity(pszEntityName, spWait);
  1451. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1452. if (eErrCode != Error_Succeed)
  1453. {
  1454. Dbg("spwait terminate %s failed(%d).", pszEntityName, eErrCode);
  1455. break;
  1456. }
  1457. }
  1458. }
  1459. else
  1460. {
  1461. Dbg("Stop %s failed(%d).", pszEntityName, eErrCode);
  1462. break;
  1463. }
  1464. Sleep(2000);
  1465. CSimpleStringA csIEUrl;
  1466. if (_strnicmp("IEBrowser", pszEntityName, strlen("IEBrowser")) == 0)
  1467. {
  1468. GetEntityBase()->GetFunction()->GetSysVar("IEUrl", csIEUrl);
  1469. Dbg("Url:[%s]", (const char*)csIEUrl);
  1470. eErrCode = pFuncPrivilege->StartEntity(pszEntityName, csIEUrl, spWait);
  1471. }
  1472. else
  1473. eErrCode = pFuncPrivilege->StartEntity(pszEntityName, NULL, spWait);
  1474. if (eErrCode == Error_Succeed)
  1475. {
  1476. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1477. if (eErrCode != Error_Succeed)
  1478. {
  1479. Dbg("spwait start %s failed(%d).", pszEntityName, eErrCode);
  1480. break;
  1481. }
  1482. Dbg("Start entity %s suc.", pszEntityName);
  1483. }
  1484. else
  1485. {
  1486. Dbg("(re)Start %s failed(%d).", pszEntityName, eErrCode);
  1487. break;
  1488. }
  1489. }
  1490. break;
  1491. case ACTION_OS_RESTART:
  1492. Dbg("test os restart");
  1493. if (m_entRunInfo[pszEntityName].loadOpt == 1 || m_entRunInfo[pszEntityName].loadOpt == 2)
  1494. LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_OS_RESTART, pszEntityName);
  1495. break;
  1496. case ACTION_POWER_RESTART:
  1497. Dbg("test power restart");
  1498. if (m_entRunInfo[pszEntityName].loadOpt == 1 || m_entRunInfo[pszEntityName].loadOpt == 2)
  1499. LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_POWER_RESTART, pszEntityName);
  1500. break;
  1501. default:
  1502. //oilyang@20200526 As all the LogWarn & LogError have beed collect to ELK platform,no need to throw LowWarn repeatly
  1503. //if (eType == ProcType_Warn)
  1504. //LogWarn(Severity_High, Error_Unexpect,(ErrorCodeEnum)dwAction,pszMessage);
  1505. break;
  1506. }
  1507. return eErrCode;
  1508. }
  1509. void CSelfCheckerFSM::UpgradeActionProcess(const char *pszEntityName, const char *pAction)
  1510. {
  1511. return;
  1512. }
  1513. ErrorCodeEnum CSelfCheckerFSM::ConnectToHealthManager()
  1514. {
  1515. LOG_FUNCTION();
  1516. if (m_pHealthClient == NULL)
  1517. {
  1518. m_pHealthClient = new HealthManagerClient(GetEntityBase());
  1519. ErrorCodeEnum ErrorConn = m_pHealthClient->Connect();
  1520. if (ErrorConn != Error_Succeed) {
  1521. //m_pHealthClient->SafeDelete();
  1522. m_pHealthClient = NULL;
  1523. Dbg("Connect to Healthmanager failed.%d", ErrorConn);
  1524. return Error_Unexpect;
  1525. }
  1526. else
  1527. {
  1528. Dbg("HealthManager connected.");
  1529. }
  1530. }
  1531. return Error_Succeed;
  1532. }
  1533. HealthManagerClient::HealthManagerClient(CEntityBase *pEntity) :HealthManagerService_ClientBase(pEntity)
  1534. {
  1535. }