SelfCheckerFSM.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. #include "stdafx.h"
  2. #define WIN32_LEAN_AND_MEAN
  3. #include <algorithm>
  4. #include "SelfCheckerFSM.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. ErrorCodeEnum CSelfCheckerFSM::OnInit()
  73. {
  74. m_xIdlePre = m_xKernelPre = m_xUserPre = 0;
  75. ErrorCodeEnum errCode = Initial();
  76. if (errCode != Error_Succeed)
  77. return Error_IO;
  78. return Error_Succeed;
  79. }
  80. ErrorCodeEnum CSelfCheckerFSM::OnExit()
  81. {
  82. return Error_Succeed;
  83. }
  84. void CSelfCheckerFSM::s0_on_entry()
  85. {
  86. LOG_FUNCTION();
  87. ErrorCodeEnum errCode;
  88. CAutoArray<WORD> tmpInstIDs;
  89. CAutoArray<CSimpleStringA> tmpNames;
  90. errCode = GetEntityBase()->GetFunction()->GetAllRegistedEntity(tmpNames, tmpInstIDs);
  91. if (errCode != Error_Succeed)
  92. {
  93. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Get started entity failed.[%d]",errCode);
  94. }
  95. for (int i = 0; i < tmpNames.GetCount(); ++i)
  96. {
  97. ErrorCodeEnum eErr;
  98. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  99. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  100. CEntityRunInfo runInfo;
  101. eErr = pFunc->GetEntityRunInfo(tmpNames[i], runInfo);
  102. if (runInfo.eState != EntityState_NoStart
  103. || tmpNames[i] == "Download" || tmpNames[i] == "UpgradeRun" || tmpNames[i] == "UpgradeManager")
  104. {
  105. m_allEntity.push_back(tmpNames[i]);
  106. }
  107. }
  108. FSMEvent* pEvt = new FSMEvent(USER_EVT_INIT);
  109. PostEventFIFO(pEvt);
  110. }
  111. void CSelfCheckerFSM::s0_on_exit()
  112. {
  113. }
  114. unsigned int CSelfCheckerFSM::s0_on_event(FSMEvent* pEvt)
  115. {
  116. LOG_FUNCTION();
  117. switch (pEvt->iEvt)
  118. {
  119. case USER_EVT_INIT:
  120. pEvt->SetHandled();
  121. break;
  122. default:
  123. break;
  124. }
  125. return 0;
  126. }
  127. void CSelfCheckerFSM::s1_on_entry()
  128. {
  129. LOG_FUNCTION();
  130. void* pTmpData = NULL;
  131. ITimerListener* pListener = new TimerOutHelper<CSelfCheckerFSM>(this, &CSelfCheckerFSM::OnNormalWorkTimerout, pTmpData);
  132. GetEntityBase()->GetFunction()->SetTimer(TIMER_ID_CHECK, pListener, MAX_CHECK_TIME);
  133. }
  134. void CSelfCheckerFSM::s1_on_exit()
  135. {
  136. LOG_FUNCTION();
  137. }
  138. unsigned int CSelfCheckerFSM::s1_on_event(FSMEvent* evt)
  139. {
  140. LOG_FUNCTION();
  141. return 0;
  142. }
  143. void CSelfCheckerFSM::s2_on_entry()
  144. {
  145. LOG_FUNCTION();
  146. }
  147. void CSelfCheckerFSM::s2_on_exit()
  148. {
  149. LOG_FUNCTION();
  150. }
  151. unsigned int CSelfCheckerFSM::s2_on_event(FSMEvent* evt)
  152. {
  153. LOG_FUNCTION();
  154. return 0;
  155. }
  156. void CSelfCheckerFSM::s3_on_entry()
  157. {
  158. LOG_FUNCTION();
  159. }
  160. void CSelfCheckerFSM::s3_on_exit()
  161. {
  162. LOG_FUNCTION();
  163. }
  164. unsigned int CSelfCheckerFSM::s3_on_event(FSMEvent* evt)
  165. {
  166. LOG_FUNCTION();
  167. return 0;
  168. }
  169. int ch2int(char ch)
  170. {
  171. if (ch >= '0' && ch <= '9')
  172. return ch - '0';
  173. else if (ch >= 'a' && ch <= 'f')
  174. return ch - 'a' + 10;
  175. else if (ch >= 'A' && ch <= 'F')
  176. return ch - 'A' + 10;
  177. return 0;
  178. }
  179. long hexstr2int(const char* str, int len)
  180. {
  181. long result = 0;
  182. for (int i = 0; i < len; ++i)
  183. {
  184. result += (ch2int(str[i]) << ((len - i - 1) * 4));
  185. }
  186. return result;
  187. }
  188. bool StrEqualNoCase(const char* s1, const char* s2, int len)
  189. {
  190. if (strlen(s1) != strlen(s2))
  191. return false;
  192. for (int i = 0; i < len; ++i)
  193. {
  194. if (toupper(s1[i]) != toupper(s2[i]))
  195. return false;
  196. }
  197. return true;
  198. }
  199. ErrorCodeEnum CSelfCheckerFSM::Initial()
  200. {
  201. ErrorCodeEnum err;
  202. CSmartPointer<IConfigInfo> spCenConfig;
  203. err = GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spCenConfig);
  204. if (err != Error_Succeed) {
  205. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("open cfg file failed!");
  206. return Error_IO;
  207. }
  208. m_restartNormal = 2;
  209. m_restartSpecial = 5;
  210. m_maxOsRestart = 5;
  211. m_maxPowerRestart = 5;
  212. do {
  213. int value(0);
  214. spCenConfig->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "RestartNormal", value);
  215. if (value != 0) m_restartNormal = value;
  216. } while (false);
  217. do {
  218. int value(0);
  219. spCenConfig->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "RestartSpecial", value);
  220. if (value != 0) m_restartSpecial = value;
  221. } while (false);
  222. do {
  223. int value(0);
  224. spCenConfig->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "MaxOsRestart", value);
  225. if (value != 0) m_maxOsRestart = value;
  226. } while (false);
  227. do {
  228. int value(0);
  229. spCenConfig->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "MaxPowerRestart", value);
  230. if (value != 0) m_maxPowerRestart = value;
  231. } while (false);
  232. //m_csKeyEntity = "PinPad";
  233. //do {
  234. // CSimpleStringA value(true);
  235. // spCenConfig->ReadConfigValue(GetEntityBase()->GetEntityName(), "KeyEntity", value);
  236. // if (!value.IsNullOrEmpty()) m_csKeyEntity = value;
  237. //} while (false);
  238. ifstream is;
  239. CSimpleStringA cfgPath(""), cfgXml("");
  240. err = GetEntityBase()->GetFunction()->GetPath("cfg", cfgPath);
  241. cfgXml = cfgPath + SPLIT_SLASH_STR + "SelfCheckerProc.xml";
  242. ReadXmlFile(cfgXml);
  243. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cfgxml[%s]", cfgXml);
  244. //auto list = m_csKeyEntity.Split(',');
  245. //for (int i = 0; i < list.GetCount(); ++i)
  246. //{
  247. // CSimpleStringA entity = list[i];
  248. // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", LPCTSTR(entity));
  249. // m_vKeyEntity.push_back(entity);
  250. //}
  251. err = GetEntityBase()->GetFunction()->GetSystemStaticInfo(m_sysInfo);
  252. if (err != Error_Succeed)
  253. {
  254. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Get System Static info failed(%d).",err);
  255. return Error_Unexpect;
  256. }
  257. CSmartPointer<IConfigInfo> spConfigRun;
  258. err = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfigRun);
  259. if (err == Error_Succeed) {
  260. spConfigRun->ReadConfigValueInt("WarnRecord", "disk", m_diskLastWarnHour);
  261. }
  262. m_activeEntity.push_back("Chromium");
  263. return Error_Succeed;
  264. }
  265. ErrorCodeEnum CSelfCheckerFSM::ExceptionErrorProcess(const char* pszEntityName, ErrorCodeEnum eCode)
  266. {
  267. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  268. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  269. CSmartPointer<IAsynWaitSp> spWait;
  270. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("proc:%s,%d", pszEntityName, eCode);
  271. //do nothing
  272. if (eCode == Error_Cancel)
  273. return Error_Succeed;
  274. bool bUpgrade = false;
  275. //need to do something
  276. ErrorCodeEnum eErrCode = Error_Succeed;
  277. if ((m_entCfgInfo.find(pszEntityName) != m_entCfgInfo.end())
  278. && ((m_entCfgInfo[pszEntityName]).hsInfo.find(eCode) != (m_entCfgInfo[pszEntityName]).hsInfo.end()))
  279. {
  280. TestActionEnum eAction = (m_entCfgInfo[pszEntityName]).hsInfo.find(eCode)->second;
  281. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("action:%d", eAction);
  282. switch (eAction)
  283. {
  284. case ACTION_EXAMINE:
  285. break;
  286. case ACTION_RESET:
  287. break;
  288. case ACTION_CLOSE:
  289. eErrCode = pFuncPrivilege->CloseEntity(pszEntityName, spWait);
  290. if (eErrCode == Error_Succeed)
  291. {
  292. }
  293. break;
  294. case ACTION_ENTITY_RESTART:
  295. {
  296. if (m_entCfgInfo[pszEntityName].bWaitRestart)
  297. {
  298. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("waiting restart...");
  299. break;
  300. }
  301. //if (m_entRunInfo[pszEntityName].loadOpt == 99)
  302. //{
  303. // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("not configure? name:[%s]", pszEntityName);
  304. // break;
  305. //}
  306. //LogErrInfo("restart ",pszEntityName,eCode);
  307. m_entCfgInfo[pszEntityName].entityRestartCount++;
  308. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("normalcount:%d,count:%d", m_restartNormal, m_entCfgInfo[pszEntityName].entityRestartCount);
  309. if (m_entCfgInfo[pszEntityName].entityRestartCount > m_restartNormal)
  310. {
  311. if ((!strnicmp(m_sysInfo.strMachineType.GetData(), "RVC.Pad", strlen("RVC.Pad")) && !strnicmp(m_sysInfo.strSite.GetData(), "cmb.FLB", strlen("cmb.FLB")))
  312. || (!strnicmp(m_sysInfo.strMachineType.GetData(), "RPM.Stand1S", strlen("RPM.Stand1S"))))
  313. {
  314. if (m_entRunInfo[pszEntityName].loadOpt == 0)
  315. m_entCfgInfo[pszEntityName].entityRestartCount = 0;
  316. }
  317. else
  318. {
  319. LogErrInfo(pszEntityName, " restart too many,upgrade process.", eCode);
  320. bUpgrade = true;
  321. m_entCfgInfo[pszEntityName].bWaitRestart = true;
  322. }
  323. eErrCode = Error_Succeed;
  324. break;
  325. }
  326. eErrCode = pFuncPrivilege->StopEntity(pszEntityName, spWait);
  327. if (eErrCode == Error_Succeed)
  328. {
  329. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  330. if (eErrCode != Error_Succeed)
  331. {
  332. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("spwait stop %s failed: %s.", pszEntityName, SpStrError(eErrCode));
  333. eErrCode = pFuncPrivilege->TerminateEntity(pszEntityName, spWait);
  334. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  335. if (eErrCode != Error_Succeed)
  336. {
  337. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("spwait terminate %s failed: %s.", pszEntityName, SpStrError(eErrCode));
  338. break;
  339. }
  340. }
  341. }
  342. else
  343. {
  344. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Stop %s failed(%d).", pszEntityName, eErrCode);
  345. break;
  346. }
  347. Sleep(2000);
  348. eErrCode = pFuncPrivilege->StartEntity(pszEntityName, NULL, spWait);
  349. if (eErrCode == Error_Succeed)
  350. {
  351. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  352. if (eErrCode != Error_Succeed)
  353. {
  354. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("spwait start %s failed(%d).", pszEntityName, eErrCode);
  355. break;
  356. }
  357. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Start entity %s suc.", pszEntityName);
  358. }
  359. else
  360. {
  361. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("(re)Start %s failed(%d).", pszEntityName, eErrCode);
  362. break;
  363. }
  364. }
  365. break;
  366. case ACTION_OS_RESTART:
  367. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("test os restart");
  368. if (m_entRunInfo[pszEntityName].loadOpt == 1 || m_entRunInfo[pszEntityName].loadOpt == 2)
  369. LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_OS_RESTART, pszEntityName);
  370. break;
  371. case ACTION_POWER_RESTART:
  372. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("test power restart");
  373. if (m_entRunInfo[pszEntityName].loadOpt == 1 || m_entRunInfo[pszEntityName].loadOpt == 2)
  374. LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_POWER_RESTART, pszEntityName);
  375. break;
  376. default:
  377. break;
  378. }
  379. if (bUpgrade)
  380. {
  381. LogActionProcess(pszEntityName, eCode, eAction);
  382. }
  383. }
  384. else
  385. {
  386. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s not configured,use default setting(%d)", LPCTSTR(pszEntityName), eCode);
  387. switch (eCode)
  388. {
  389. case Error_TimeOut:
  390. case Error_Unexpect:
  391. case Error_InvalidState:
  392. {
  393. eErrCode = pFuncPrivilege->StopEntity(pszEntityName, spWait);
  394. if (eErrCode == Error_Succeed)
  395. {
  396. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  397. if (eErrCode != Error_Succeed)
  398. {
  399. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("spwait stop %s failed: %s.", pszEntityName, SpStrError(eErrCode));
  400. eErrCode = pFuncPrivilege->TerminateEntity(pszEntityName, spWait);
  401. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  402. if (eErrCode != Error_Succeed)
  403. {
  404. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("spwait terminate %s failed: %s.", pszEntityName, SpStrError(eErrCode));
  405. break;
  406. }
  407. }
  408. }
  409. else
  410. {
  411. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Stop %s failed(%d).", pszEntityName, eErrCode);
  412. break;
  413. }
  414. Sleep(5000);
  415. eErrCode = pFuncPrivilege->StartEntity(pszEntityName, NULL, spWait);
  416. if (eErrCode == Error_Succeed)
  417. {
  418. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  419. if (eErrCode != Error_Succeed)
  420. {
  421. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("spwait start %s failed(%d).", pszEntityName, eErrCode);
  422. break;
  423. }
  424. }
  425. else
  426. {
  427. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("(re)Start %s failed(%d).", pszEntityName, eErrCode);
  428. break;
  429. }
  430. }
  431. break;
  432. default:
  433. break;
  434. }
  435. }
  436. return eErrCode;
  437. }
  438. ErrorCodeEnum CSelfCheckerFSM::CheckEntity(const char* pszEntityName, EntityTestEnum eTestType, bool bNormalCheck)
  439. {
  440. if (bNormalCheck)
  441. {
  442. //oilyang@20230426 ,常规自检时,针对"TerminalStage"做对应处理(自检分常规自检和即时自检)
  443. //"S":准入服务告知准入不过,不再进行实体自检
  444. //非"A":其他启动失败导致进关门页,不再对硬件以及其他没必要自检的实体进行自检
  445. CSimpleStringA tmpTerminalStage("");
  446. GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", tmpTerminalStage);
  447. if (tmpTerminalStage.Compare("S") == 0)
  448. return Error_Succeed;
  449. else if (tmpTerminalStage.Compare("A") != 0)
  450. {
  451. //the hardward entity and some other entity no need to test
  452. if (_strnicmp("PinPad", pszEntityName, strlen("PinPad")) == 0 || _strnicmp("CardIssuer", pszEntityName, strlen("CardIssuer")) == 0
  453. || _strnicmp("CardSwiper", pszEntityName, strlen("CardSwiper")) == 0 || _strnicmp("ContactlessCard", pszEntityName, strlen("ContactlessCard")) == 0
  454. || _strnicmp("IDCertificate", pszEntityName, strlen("IDCertificate")) == 0
  455. || _strnicmp("gpio", pszEntityName, strlen("gpio")) == 0 || _strnicmp("HSPScanner", pszEntityName, strlen("HSPScanner")) == 0
  456. || _strnicmp("FingerPrint", pszEntityName, strlen("FingerPrint")) == 0
  457. )
  458. return Error_Succeed;
  459. }
  460. }
  461. //oilyang@20170926 no need to check by self.Let the HealthManager entity to do it.
  462. //oilyang@20231106 no need to check VtmLoader
  463. if (pszEntityName != NULL && (strnicmp(pszEntityName, GetEntityBase()->GetEntityName(), strlen(GetEntityBase()->GetEntityName())) == 0
  464. || strnicmp(pszEntityName, "VtmLoader", strlen("VtmLoader")) == 0))
  465. return Error_Succeed;
  466. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  467. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  468. CSmartPointer<IAsynWaitSp> spWait;
  469. ErrorCodeEnum errCode;
  470. errCode = pFuncPrivilege->TestEntity(pszEntityName, eTestType, spWait);
  471. if (errCode == Error_Succeed)
  472. {
  473. callback_entry* entry = new callback_entry();
  474. entry->pRawData = NULL;
  475. entry->EntityName = pszEntityName;
  476. entry->ErrorResult = Error_Unexpect;
  477. entry->op = Test_ShakeHand;
  478. spWait->SetCallback(this, entry);
  479. }
  480. else
  481. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Test %s,%d", pszEntityName, errCode);
  482. return errCode;
  483. }
  484. void CSelfCheckerFSM::OnNormalWorkTimerout(void* pData)
  485. {
  486. if (!m_bFWBEntityAdd)
  487. {
  488. //oilyang@20220415 special process of RVC.PAD with FWB
  489. CSimpleStringA tmpFWBDevSN("");
  490. GetEntityBase()->GetFunction()->GetSysVar("FWBDevSN", tmpFWBDevSN);
  491. if (m_sysInfo.strMachineType.Compare("RVC.PAD", true) == 0 && !tmpFWBDevSN.IsNullOrEmpty())
  492. {
  493. AddFWBEntityToList();
  494. m_bFWBEntityAdd = true;
  495. }
  496. }
  497. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  498. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  499. CSmartPointer<IAsynWaitSp> spWait;
  500. ErrorCodeEnum errCode;
  501. int activeEnCount = m_activeEntity.size();
  502. vector<CSimpleStringA>::iterator it;
  503. //oiltmp 20131219
  504. //GetSystemCPUStatus();
  505. //GetSystemMemoryStatus();
  506. //GetSystemDiskStatus();
  507. for (it = m_activeEntity.begin(); it != m_activeEntity.end(); ++it)
  508. {
  509. errCode = CheckEntity(*it, Test_ShakeHand);
  510. CEntityRunInfo runInfo;
  511. pFunc->GetEntityRunInfo(*it, runInfo);
  512. //CheckEntityResouce(*it, runInfo);
  513. }
  514. GetEntityBase()->GetFunction()->ResetTimer(TIMER_ID_CHECK, MAX_CHECK_TIME);
  515. }
  516. void CSelfCheckerFSM::DoOnCreated(const char* pszEntityName, ErrorCodeEnum eOnStartErrorCode, const char* pszCallerEntity)
  517. {
  518. }
  519. void CSelfCheckerFSM::DoOnClosed(const char* pszEntityName, EntityCloseCauseEnum eCloseCause, ErrorCodeEnum eOnCloseErrorCode, const char* pszCallerEntity)
  520. {
  521. }
  522. void CSelfCheckerFSM::DoOnException(const char* pszEntityName, const char* pszFunctionName, EntityStateEnum eState, EntityStateEnum eLastState, ErrorCodeEnum eErrorCode)
  523. {
  524. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnException:%s,%s,%d,%d,%d", pszEntityName, pszFunctionName, eState, eLastState, eErrorCode);
  525. }
  526. void CSelfCheckerFSM::OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp)
  527. {
  528. CSmartPointer<ICallbackListener> spCallback;
  529. CSmartPointer<IReleasable> pData;
  530. pAsynWaitSp->GetCallback(spCallback, pData);
  531. //LOG_ASSERT(pData);
  532. callback_entry* entry = dynamic_cast<callback_entry*>((IReleasable*)pData.GetRawPointer());
  533. entry->ErrorResult = pAsynWaitSp->AsyncGetAnswer();
  534. callback_entry* new_entry = new callback_entry();
  535. new_entry->EntityName = entry->EntityName;
  536. new_entry->ErrorResult = entry->ErrorResult;
  537. new_entry->op = entry->op;
  538. new_entry->state = entry->state;
  539. m_entRunInfo[new_entry->EntityName].eTest = new_entry->ErrorResult; //add test result oilyang 20150616
  540. if (new_entry->op == Test_ShakeHand && new_entry->ErrorResult != Error_Succeed) {
  541. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("oiltmp shakehand %s turns out %s, entity state: %s", (LPCTSTR)new_entry->EntityName, SpStrError(new_entry->ErrorResult), SpStrEntityState((EntityStateEnum)new_entry->state));
  542. }
  543. if (new_entry->ErrorResult != Error_Succeed)
  544. {
  545. ErrorCodeEnum eErr;
  546. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  547. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  548. if (_strnicmp("MediaController", (const char*)new_entry->EntityName, strlen("MediaController")) == 0
  549. && !m_bEverInMainPage)
  550. {
  551. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("On loading stage,don't process MediaController exception.");
  552. }
  553. else
  554. Proc((const char*)new_entry->EntityName, ProcType_Shake, new_entry->ErrorResult);
  555. }
  556. else
  557. {
  558. CSmartPointer<IEntityFunction> spEntityFunction = GetEntityBase()->GetFunction();
  559. CSmartPointer<IConfigInfo> spConfig;
  560. ErrorCodeEnum eErr = spEntityFunction->OpenConfig(Config_Run, spConfig);
  561. if (eErr != Error_Succeed) {
  562. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("open run cfg file failed!");
  563. return;
  564. }
  565. spConfig->WriteConfigValueInt(new_entry->EntityName, "OsRestart", 0);
  566. spConfig->WriteConfigValueInt(new_entry->EntityName, "PowerRestart", 0);
  567. }
  568. }
  569. void CSelfCheckerFSM::LogErrInfo(const char* msgHead, const char* msgBody, const int errCode)
  570. {
  571. //oiltest to redifine this
  572. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s,%s,%d", msgHead, msgBody, errCode);
  573. }
  574. void CSelfCheckerFSM::LogActionProcess(const char* pszEntityName, ErrorCodeEnum errCode, TestActionEnum eAct)
  575. {
  576. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("LogActionProcess:entity[%s],errCode[%d],eAction[%d]", pszEntityName, errCode, eAct);
  577. CSmartPointer<IEntityFunction> spEntityFunction = GetEntityBase()->GetFunction();
  578. CSmartPointer<IConfigInfo> spConfig;
  579. ErrorCodeEnum eErr = spEntityFunction->OpenConfig(Config_Run, spConfig);
  580. if (eErr != Error_Succeed) {
  581. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("open run cfg file failed!");
  582. return;
  583. }
  584. int osTimes, powerTimes;
  585. osTimes = powerTimes = 0;
  586. spConfig->ReadConfigValueInt(pszEntityName, "OsRestart", osTimes);
  587. spConfig->ReadConfigValueInt(pszEntityName, "PowerRestart", powerTimes);
  588. switch (eAct)
  589. {
  590. case ACTION_ENTITY_RESTART:
  591. if (osTimes > m_maxOsRestart || powerTimes > m_maxPowerRestart)
  592. {
  593. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("restart too much,give up[%d][%d].", osTimes, powerTimes);
  594. break;
  595. }
  596. break;
  597. ///*TODO: cannot access (80374374@11/23/2023)*/
  598. osTimes++;
  599. powerTimes++;
  600. spConfig->WriteConfigValueInt(pszEntityName, "OsRestart", osTimes);
  601. spConfig->WriteConfigValueInt(pszEntityName, "PowerRestart", powerTimes);
  602. //for simple and effective,use power restart only
  603. LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_POWER_RESTART, pszEntityName);
  604. m_entCfgInfo[pszEntityName].bWaitRestart = true;
  605. break;
  606. default:
  607. break;
  608. }
  609. }
  610. void CSelfCheckerFSM::CheckEntityResouce(const char* pszEntityName, CEntityRunInfo& info)
  611. {
  612. if (info.eState != EntityState_Idle){
  613. return;
  614. }
  615. #ifdef RVC_OS_WIN
  616. //HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_QUERY_LIMITED_INFORMATION, FALSE, info.dwProcessID);
  617. //if (hProcess == NULL)
  618. //{
  619. // DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("OpenProcess %s failed %d.", pszEntityName, GetLastError());
  620. // return;
  621. //}
  622. ////GetSystemInfo
  623. //PIO_COUNTERS pIOCounters = new IO_COUNTERS;
  624. //BOOL ret = GetProcessIoCounters(hProcess, pIOCounters);
  625. //if (ret == 0)
  626. //{
  627. // DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("GetProcessIoCounters %s failed %d.", pszEntityName, GetLastError());
  628. //}
  629. //PROCESS_MEMORY_COUNTERS pmc;
  630. //const int showSize = 20;
  631. //if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc)))
  632. //{
  633. // if ((pmc.WorkingSetSize / MILLION > showSize) && (pmc.PeakWorkingSetSize / MILLION > showSize)
  634. // && (pmc.PagefileUsage / MILLION > showSize) && (pmc.PeakPagefileUsage / MILLION > showSize))
  635. // {
  636. // m_entRunInfo[pszEntityName].memoryHighCount++;
  637. // if (m_entRunInfo[pszEntityName].memoryHighCount > ((60000 / MAX_CPU_CHECK_TIME)) * 2)//more than 2 minutes
  638. // {
  639. // m_entRunInfo[pszEntityName].memoryHighCount = 0;
  640. // Dbg("%s,WorkingSetSize %u, Peak %u,PageFileUsage %u, Peak %u", (LPCTSTR)pszEntityName, pmc.WorkingSetSize / MILLION, pmc.PeakWorkingSetSize / MILLION, pmc.PagefileUsage / MILLION, pmc.PeakPagefileUsage / MILLION);
  641. // }
  642. // }
  643. //}
  644. //CloseHandle(hProcess);
  645. #else
  646. return;//oiltestlinux
  647. #endif //RVC_OS_WIN
  648. }
  649. //bool CSelfCheckerFSM::IsKeyEntity(const char* pszEntityName)
  650. //{
  651. // vector<CSimpleStringA>::iterator it;
  652. // for (it = m_vKeyEntity.begin(); it != m_vKeyEntity.end(); ++it)
  653. // {
  654. // if (!_strnicmp(pszEntityName, *it, strlen(pszEntityName)))
  655. // return true;
  656. // }
  657. // return false;
  658. //}
  659. int CSelfCheckerFSM::AddEntityState(const char* pszEntityName, EntityStateEnum eState)
  660. {
  661. if (eState == EntityState_Starting)
  662. {
  663. m_entRunInfo[pszEntityName].bGetLoadOpt = false;
  664. m_entRunInfo[pszEntityName].bRestarting = false;
  665. m_entRunInfo[pszEntityName].loadOpt = 99;
  666. m_entRunInfo[pszEntityName].eState = eState;
  667. m_entRunInfo[pszEntityName].eTest = Error_Succeed;
  668. }
  669. else
  670. m_entRunInfo[pszEntityName].eState = eState;
  671. if (eState == EntityState_Idle)
  672. {
  673. m_entRunInfo[pszEntityName].eTest = Error_Succeed;
  674. m_entRunInfo[pszEntityName].memoryHighCount = 0;
  675. }
  676. m_entRunInfo[pszEntityName].cpuRatio = 0;
  677. return 0;
  678. }
  679. ErrorCodeEnum CSelfCheckerFSM::GetEntityErrorList(int& warmLevel, CSimpleStringA& strList)
  680. {
  681. map<CSimpleStringA, EntityRunInfo>::iterator it;
  682. CSimpleStringA tmpStr("");
  683. bool bLost = false;
  684. for (it = m_entRunInfo.begin(); it != m_entRunInfo.end(); ++it)
  685. {
  686. if (m_entRunInfo[it->first].eState == EntityState_Lost)
  687. bLost = true;
  688. char buf[16], bufTest[16];
  689. ZeroMemory(buf, 16);
  690. ZeroMemory(bufTest, 16);
  691. if (m_entRunInfo[it->first].eState == EntityState_Lost || m_entRunInfo[it->first].eState == EntityState_Close
  692. || m_entRunInfo[it->first].eState == EntityState_Killed || m_entRunInfo[it->first].eTest != Error_Succeed)
  693. {
  694. tmpStr += it->first;
  695. tmpStr += "=";
  696. if (m_entRunInfo[it->first].eState == EntityState_Lost || m_entRunInfo[it->first].eState == EntityState_Close
  697. || m_entRunInfo[it->first].eState == EntityState_Killed)
  698. {
  699. _itoa(m_entRunInfo[it->first].eState, buf, 10);
  700. tmpStr += buf;
  701. }
  702. if (m_entRunInfo[it->first].eTest != Error_Succeed)
  703. {
  704. _itoa(m_entRunInfo[it->first].eTest, bufTest, 10);
  705. tmpStr += ",(selfcheck code):";
  706. tmpStr += bufTest;
  707. }
  708. tmpStr += ";";
  709. }
  710. }
  711. if (tmpStr.GetLength() < 2)
  712. m_warmLevel = warmLevel = 0;
  713. if (bLost)
  714. m_warmLevel = warmLevel = 3;
  715. m_warmLevel = warmLevel = 1;//for temp set 20150617
  716. strList = tmpStr;
  717. if (strList.GetLength() > 2)
  718. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("warnlevel:%d,ErrorList [%s]", m_warmLevel, (LPCTSTR)strList);
  719. return Error_Succeed;
  720. }
  721. int CSelfCheckerFSM::Proc(string entity, ProcType eType, DWORD dwCode, const char* pszMessage)
  722. {
  723. map<string, EntityCfg, EntityNameCompare>::iterator it;
  724. if ((it = m_mapEntity.find(entity.c_str())) == m_mapEntity.end())
  725. {
  726. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("can't find entity %s configure setting,using default setting.", entity.c_str());
  727. //Error_TimeOut:
  728. //Error_Unexpect:
  729. //Error_InvalidState:
  730. if (eType == ProcType_Shake && (dwCode == Error_TimeOut || dwCode == Error_Unexpect || dwCode == Error_InvalidState))
  731. ExceptionErrorProcessXml(eType, entity.c_str(), ACTION_ENTITY_RESTART, true);
  732. else if (eType == ProcType_Warn)
  733. ExceptionErrorProcessXml(eType, entity.c_str(), dwCode, true, pszMessage);
  734. else
  735. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("What's this:type:%d,receive code:%x,msg:%s, from entity %s.", eType, dwCode, pszMessage, entity.c_str());
  736. return -1;
  737. }
  738. vector<ProcItem>::iterator vIt, vEnd;
  739. if (eType == ProcType_Shake)
  740. {
  741. vIt = it->second.vShake.begin();
  742. vEnd = it->second.vShake.end();
  743. }
  744. else if (eType == ProcType_Warn)
  745. {
  746. vIt = it->second.vWarn.begin();
  747. vEnd = it->second.vWarn.end();
  748. }
  749. for (; vIt != vEnd; vIt++)
  750. {
  751. if (vIt->code == dwCode)
  752. {
  753. if (vIt->upgradecount > 0)
  754. {
  755. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("action size:%d,upgradecount:%d", vIt->proctime.size(), vIt->upgradecount);
  756. UINT64 happentime = SP::Module::Comm::RVCGetTickCount();
  757. if (vIt->proctime.size() < vIt->upgradecount - 1)//just add record,do nothing
  758. {
  759. vIt->proctime.push_back(happentime);
  760. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("just add record");
  761. return 0;
  762. }
  763. else
  764. {
  765. //to find the 1st record happened in last upgradetime minute
  766. //and remove the record happened far ago(upgradetime minutes before)
  767. vector<UINT64>::iterator ittime, itFisrtInPeriod, xxxIt;
  768. bool bFar = false;
  769. int count = 0;
  770. for (ittime = vIt->proctime.begin(); ittime != vIt->proctime.end(); ittime++)
  771. {
  772. itFisrtInPeriod = ittime;
  773. UINT64 difftime = happentime - *ittime;
  774. if (difftime / (1000 * 60) < vIt->upgradetime)
  775. break;
  776. else
  777. {
  778. count++;
  779. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("the %d th action", count);
  780. bFar = true;
  781. }
  782. }
  783. if (!bFar)
  784. {
  785. //to do upgrade action
  786. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to do upgrade action");
  787. ExceptionErrorProcessXml(eType, entity.c_str(), vIt->upgradeaction);
  788. vIt->proctime.clear();
  789. return 0;
  790. }
  791. else
  792. {
  793. if (count == 1 && vIt->proctime.size() == 1)
  794. vIt->proctime.clear();
  795. else
  796. vIt->proctime.erase(vIt->proctime.begin(), itFisrtInPeriod);
  797. for (xxxIt = vIt->proctime.begin(); xxxIt != vIt->proctime.end(); xxxIt++)
  798. {
  799. cout << *xxxIt << " # ";
  800. }
  801. cout << endl;
  802. vIt->proctime.push_back(happentime);
  803. for (xxxIt = vIt->proctime.begin(); xxxIt != vIt->proctime.end(); xxxIt++)
  804. {
  805. cout << *xxxIt << " * ";
  806. }
  807. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("after clear,add record");
  808. return 0;
  809. }
  810. }
  811. }
  812. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Entity %s receive %d,to do action:%d", entity.c_str(), dwCode, vIt->action);
  813. ExceptionErrorProcessXml(eType, entity.c_str(), vIt->action, true, pszMessage);
  814. return 0;
  815. }
  816. }
  817. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("can't find corresponding action of entity %s,type:%d,code:%x", entity.c_str(), eType, dwCode);
  818. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("use default process...");
  819. if (eType == ProcType_Shake && (dwCode == Error_TimeOut || dwCode == Error_Unexpect || dwCode == Error_InvalidState))
  820. ExceptionErrorProcessXml(eType, entity.c_str(), ACTION_ENTITY_RESTART, true);
  821. else if (eType == ProcType_Warn)
  822. ExceptionErrorProcessXml(eType, entity.c_str(), dwCode, true, pszMessage);
  823. return -1;
  824. }
  825. bool CSelfCheckerFSM::ReadXmlFile(const char* szFileName)
  826. {//读取Xml文件,并遍历
  827. //MessageBox(0, 0, 0, 0);
  828. LOG_FUNCTION();
  829. tinyxml2::XMLDocument* doc = new tinyxml2::XMLDocument();
  830. XMLError err = doc->LoadFile(szFileName);
  831. if (err != XML_SUCCESS)
  832. {
  833. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("open file %s failed.GetLastError:%d", szFileName, GetLastError());
  834. return false;
  835. }
  836. //doc->GetDocument();
  837. string out = "";
  838. XMLNode* pF = doc->FirstChild();
  839. XMLElement* pRoot = doc->RootElement();
  840. //pF->FirstChildElement();
  841. if (pRoot == NULL)
  842. {
  843. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Get root element failed.");
  844. return false;
  845. }
  846. else
  847. pF = pRoot->FirstChild();
  848. while (pF != NULL)
  849. {
  850. if (pF->ToElement() == NULL)
  851. {
  852. pF = pF->FirstChild();
  853. continue;
  854. }
  855. const char* pName = pF->ToElement()->Name();
  856. if (!strncmp(pName, "SelfCheckerConfig", strlen("SelfCheckerConfig")))
  857. {
  858. pF = pF->FirstChild();
  859. continue;
  860. }
  861. else if (!strncmp(pName, "Entity", strlen("Entity")))
  862. {
  863. EntityCfg entity;
  864. const char* attrName = pF->ToElement()->Attribute("name");
  865. out += const_cast<char*>(attrName);
  866. out += "\r\n";
  867. XMLNode* pChild = pF->FirstChild();
  868. while (pChild != NULL)
  869. {
  870. if (!strncmp(pChild->Value(), "shakehandproc", strlen("shakehandproc")))
  871. {
  872. XMLNode* pProc = pChild->FirstChild();
  873. while (pProc != NULL)
  874. {
  875. ProcItem item;
  876. const char* code, * action, * upgradeaction, * upgradetime, * upgradecount;
  877. code = action = upgradeaction = upgradetime = upgradecount = NULL;
  878. if (pProc->ToElement() != NULL)
  879. {
  880. code = pProc->ToElement()->Attribute("code");
  881. action = pProc->ToElement()->Attribute("action");
  882. upgradeaction = pProc->ToElement()->Attribute("upgradeaction");
  883. upgradetime = pProc->ToElement()->Attribute("upgradetime");
  884. upgradecount = pProc->ToElement()->Attribute("upgradecount");
  885. }
  886. if (code != NULL)
  887. {
  888. item.code = CodeStrToInt(code);
  889. out += const_cast<char*>(code);
  890. out += " , ";
  891. }
  892. if (action != NULL)
  893. {
  894. item.action = ActionStrToInt(action);
  895. out += const_cast<char*>(action);
  896. out += " , ";
  897. }
  898. if (upgradeaction != NULL)
  899. {
  900. item.upgradeaction = ActionStrToInt(upgradeaction);
  901. out += const_cast<char*>(upgradeaction);
  902. }
  903. if (upgradetime != NULL)
  904. {
  905. item.upgradetime = atoi(upgradetime);
  906. }
  907. if (upgradecount != NULL)
  908. {
  909. item.upgradecount = atoi(upgradecount);
  910. }
  911. else
  912. item.upgradecount = 0;
  913. entity.vShake.push_back(item);
  914. out += "; ";
  915. pProc = pProc->NextSibling();
  916. }
  917. }
  918. else if (!strncmp(pChild->Value(), "eventproc", strlen("eventproc")))
  919. {
  920. XMLNode* pProc = pChild->FirstChild();
  921. while (pProc != NULL)
  922. {
  923. ProcItem item;
  924. const char* code, * action, * upgradeaction, * upgradetime, * upgradecount;
  925. code = action = upgradeaction = upgradetime = upgradecount = NULL;
  926. if (pProc->ToElement() != NULL)
  927. {
  928. code = pProc->ToElement()->Attribute("code");
  929. action = pProc->ToElement()->Attribute("action");
  930. upgradeaction = pProc->ToElement()->Attribute("upgradeaction");
  931. upgradetime = pProc->ToElement()->Attribute("upgradetime");
  932. upgradecount = pProc->ToElement()->Attribute("upgradecount");
  933. }
  934. if (code != NULL)
  935. {
  936. item.code = CodeStrToInt(code);
  937. out += const_cast<char*>(code);
  938. out += ",";
  939. }
  940. if (action != NULL)
  941. {
  942. item.action = ActionStrToInt(action);
  943. out += const_cast<char*>(action);
  944. out += ",";
  945. }
  946. if (upgradeaction != NULL)
  947. {
  948. item.upgradeaction = ActionStrToInt(upgradeaction);
  949. out += const_cast<char*>(upgradeaction);
  950. }
  951. if (upgradetime != NULL)
  952. {
  953. item.upgradetime = atoi(upgradetime);
  954. }
  955. if (upgradecount != NULL)
  956. {
  957. item.upgradecount = atoi(upgradecount);
  958. }
  959. else
  960. item.upgradecount = 0;
  961. entity.vWarn.push_back(item);
  962. out += "; ";
  963. pProc = pProc->NextSibling();
  964. }
  965. }
  966. pChild = pChild->NextSibling();
  967. }
  968. m_mapEntity[attrName] = entity;
  969. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("add %s,vShake size:%d,vWarn size:%d", attrName, entity.vShake.size(), entity.vWarn.size());
  970. }
  971. out += "\r\n";
  972. pF = pF->NextSibling();
  973. }
  974. return true;
  975. }
  976. ErrorCodeEnum CSelfCheckerFSM::ExceptionErrorProcessXml(ProcType eType, const char* pszEntityName, DWORD dwAction, bool bDefault, const char* pszMessage)
  977. {
  978. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  979. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  980. CSmartPointer<IAsynWaitSp> spWait;
  981. ErrorCodeEnum eErrCode = Error_Unexpect;
  982. switch (dwAction)
  983. {
  984. case ACTION_EXAMINE:
  985. break;
  986. case ACTION_RESET:
  987. break;
  988. case ACTION_CLOSE:
  989. eErrCode = pFuncPrivilege->CloseEntity(pszEntityName, spWait);
  990. if (eErrCode == Error_Succeed)
  991. {
  992. }
  993. break;
  994. case ACTION_ENTITY_RESTART:
  995. {
  996. if (m_entCfgInfo[pszEntityName].bWaitRestart)
  997. {
  998. if (!bDefault)
  999. {
  1000. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("waiting restart...");
  1001. break;
  1002. }
  1003. }
  1004. //if (m_entRunInfo[pszEntityName].loadOpt == 99)
  1005. //{
  1006. // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("not configure? name:[%s]", pszEntityName);
  1007. // break;
  1008. //}
  1009. //oilyang@20200407 if being restarted by selfchecker,break
  1010. if (m_entRunInfo[pszEntityName].bRestarting)
  1011. {
  1012. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s is being restarted by selfchecker.", pszEntityName);
  1013. break;
  1014. }
  1015. //oilyang@20200403
  1016. //for fwb test,PinPad&CardSwiper can't be stop immediately
  1017. //huchen@20210220,SIPPhone can't be stop immediately
  1018. if (_strnicmp("PinPad", pszEntityName, strlen("PinPad")) == 0
  1019. || _strnicmp("CardSwiper", pszEntityName, strlen("CardSwiper")) == 0
  1020. //oilyang@20210220 for huchen add SIPPhone
  1021. || _strnicmp("SIPPhone", pszEntityName, strlen("SIPPhone")) == 0
  1022. || _strnicmp("IDCertificate", pszEntityName, strlen("IDCertificate")) == 0
  1023. || _strnicmp("FingerPrint", pszEntityName, strlen("FingerPrint")) == 0
  1024. || _strnicmp("DeviceControl", pszEntityName, strlen("DeviceControl")) == 0)
  1025. eErrCode = pFuncPrivilege->TerminateEntity(pszEntityName, spWait);
  1026. else
  1027. eErrCode = pFuncPrivilege->StopEntity(pszEntityName, spWait);
  1028. if (eErrCode == Error_Succeed)
  1029. {
  1030. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1031. if (eErrCode != Error_Succeed)
  1032. {
  1033. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("spwait stop %s failed: %s.", pszEntityName, SpStrError(eErrCode));
  1034. eErrCode = pFuncPrivilege->TerminateEntity(pszEntityName, spWait);
  1035. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1036. if (eErrCode != Error_Succeed)
  1037. {
  1038. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("spwait terminate %s failed: %s.", pszEntityName, SpStrError(eErrCode));
  1039. break;
  1040. }
  1041. }
  1042. }
  1043. else
  1044. {
  1045. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Stop %s failed(%d).", pszEntityName, eErrCode);
  1046. break;
  1047. }
  1048. Sleep(2000);
  1049. eErrCode = pFuncPrivilege->StartEntity(pszEntityName, NULL, spWait);
  1050. if (eErrCode == Error_Succeed)
  1051. {
  1052. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1053. if (eErrCode != Error_Succeed)
  1054. {
  1055. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("spwait start %s failed(%d).", pszEntityName, eErrCode);
  1056. break;
  1057. }
  1058. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Start entity %s suc.", pszEntityName);
  1059. }
  1060. else
  1061. {
  1062. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("(re)Start %s failed(%d).", pszEntityName, eErrCode);
  1063. break;
  1064. }
  1065. }
  1066. break;
  1067. case ACTION_OS_RESTART:
  1068. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("test os restart");
  1069. if (m_entRunInfo[pszEntityName].loadOpt == 1 || m_entRunInfo[pszEntityName].loadOpt == 2)
  1070. LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_OS_RESTART, pszEntityName);
  1071. break;
  1072. case ACTION_POWER_RESTART:
  1073. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("test power restart");
  1074. if (m_entRunInfo[pszEntityName].loadOpt == 1 || m_entRunInfo[pszEntityName].loadOpt == 2)
  1075. LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_POWER_RESTART, pszEntityName);
  1076. break;
  1077. default:
  1078. break;
  1079. }
  1080. return eErrCode;
  1081. }
  1082. void CSelfCheckerFSM::UpgradeActionProcess(const char* pszEntityName, const char* pAction)
  1083. {
  1084. return;
  1085. }
  1086. void CSelfCheckerFSM::SetEverEnterMainPageFlag(bool bValue)
  1087. {
  1088. m_bEverInMainPage = bValue;
  1089. }
  1090. void CSelfCheckerFSM::AddFWBEntityToList()
  1091. {
  1092. vector<CSimpleStringA>::iterator it, itAct;
  1093. bool bPinPadFound(false),bIDCertFound(false),bFingerPrintFound(false)
  1094. ,bActPinPadFound(false), bActIDCertFound(false), bActFingerPrintFound(false);
  1095. //template ?
  1096. for (it = m_allEntity.begin(); it != m_allEntity.end(); ++it)
  1097. {
  1098. if (!strnicmp("PinPad", *it, it->GetLength()))
  1099. bPinPadFound = true;
  1100. else if (!strnicmp("IDCertificate", *it, it->GetLength()))
  1101. bIDCertFound = true;
  1102. else if (!strnicmp("FingerPrint", *it, it->GetLength()))
  1103. bFingerPrintFound = true;
  1104. }
  1105. if (!bPinPadFound)
  1106. m_allEntity.push_back("PinPad");
  1107. if (!bIDCertFound)
  1108. m_allEntity.push_back("IDCertificate");
  1109. if (!bPinPadFound)
  1110. m_allEntity.push_back("FingerPrint");
  1111. for (itAct = m_activeEntity.begin(); itAct != m_activeEntity.end(); ++itAct)
  1112. {
  1113. if (!strnicmp("PinPad", *itAct, itAct->GetLength()))
  1114. bActPinPadFound = true;
  1115. else if (!strnicmp("IDCertificate", *itAct, itAct->GetLength()))
  1116. bActIDCertFound = true;
  1117. else if (!strnicmp("FingerPrint", *itAct, itAct->GetLength()))
  1118. bActFingerPrintFound = true;
  1119. }
  1120. if (!bActPinPadFound)
  1121. m_activeEntity.push_back("PinPad");
  1122. if (!bActIDCertFound)
  1123. m_activeEntity.push_back("IDCertificate");
  1124. if (!bActFingerPrintFound)
  1125. m_activeEntity.push_back("FingerPrint");
  1126. }
  1127. void CSelfCheckerFSM::GetEntityList(CSimpleStringA csList)
  1128. {
  1129. CAutoArray<CSimpleStringA> arrStageList;
  1130. arrStageList.Init(64);
  1131. arrStageList = csList.Split('|');
  1132. for (int i = 0; i < arrStageList.GetCount(); ++i)
  1133. {
  1134. CAutoArray<CSimpleStringA> arrEntity;
  1135. arrEntity.Init(2);
  1136. arrEntity = arrStageList[i].Split('=');
  1137. if (arrEntity.GetCount() < 2)
  1138. break;
  1139. //去重,防止前面已经加载了
  1140. if (find(m_activeEntity.begin(), m_activeEntity.end(), arrEntity[0].GetData()) != m_activeEntity.end())
  1141. continue;
  1142. m_activeEntity.push_back(arrEntity[0]);
  1143. m_entRunInfo[arrEntity[0]].bGetLoadOpt = true;
  1144. if (arrEntity[1].Compare("1") == 0)
  1145. {
  1146. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s config with loadopt 1", arrEntity[0].GetData());
  1147. m_entRunInfo[arrEntity[0]].loadOpt = 1;
  1148. }
  1149. else if (arrEntity[1].Compare("2") == 0)
  1150. {
  1151. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s config with loadopt 2", arrEntity[0].GetData());
  1152. m_entRunInfo[arrEntity[0]].loadOpt = 2;
  1153. }
  1154. else
  1155. m_entRunInfo[arrEntity[0]].loadOpt = 0;
  1156. }
  1157. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_activeEntity has %d entity", m_activeEntity.size());
  1158. }