SelfCheckerFSM.cpp 50 KB

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