HealthManagerFSM.cpp 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329
  1. #include "stdafx.h"
  2. #include <fstream>
  3. #include <string>
  4. #include <algorithm>
  5. #include <regex>
  6. #include "SpUtility.h"
  7. #include "iniutil.h"
  8. #if defined(RVC_OS_WIN)
  9. #include <TlHelp32.h>
  10. #include <iphlpapi.h>
  11. #include <ws2tcpip.h>
  12. #include <Winsock2.h>
  13. #include <io.h>
  14. #include "CSystemStatus.h"
  15. #pragma comment(lib, "IPHLPAPI.lib")
  16. #pragma comment(lib, "libpublicFun.lib")
  17. #else
  18. #include <unistd.h>
  19. #include <fcntl.h>
  20. #include <errno.h>
  21. #endif //RVC_OS_WIN
  22. #include "mod_healthmanager.h"
  23. #include "publicFunExport.h"
  24. using namespace std;
  25. const int MAX_AYSNC_TIMEOUT = 60000;
  26. const int MAX_IGNORE_TIMEOUT = 100;
  27. unsigned long long GetLastErrorRVC() {
  28. #if defined(RVC_OS_WIN)
  29. return GetLastError();
  30. #else
  31. return errno;
  32. #endif //RVC_OS_WIN
  33. }
  34. enum EntityOP
  35. {
  36. OP_STOP_ENTITY,
  37. OP_START_ENTITY,
  38. OP_PAUSE_ENTITY,
  39. OP_TERMINATE_ENTITY,
  40. OP_CONTINUE_ENTITY,
  41. };
  42. ErrorCodeEnum CHealthManagerFSM::Initial()
  43. {
  44. m_netList.Init(0);
  45. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  46. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  47. CSmartPointer<IAsynWaitSp> spWait;
  48. ErrorCodeEnum err;
  49. GetEntityBase()->GetFunction()->GetSystemStaticInfo(m_sysInfo);
  50. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("machinetype[%s],terminalID[%s]", (LPCTSTR)m_sysInfo.strMachineType, (LPCTSTR)m_sysInfo.strTerminalID);
  51. CSmartPointer<IConfigInfo> spConfigCen;
  52. GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen);
  53. spConfigCen->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "WKUpdatePeriod", m_wkUpdatePeriod);
  54. if (m_wkUpdatePeriod <= 0 || m_wkUpdatePeriod > 365)
  55. m_wkUpdatePeriod = 30;//default
  56. spConfigCen->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "DoNotUpdateWKDaily", m_iDoNotUpdateWKDaily);
  57. spConfigCen->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "MaxWaitForPinPad", m_maxWaitForPinPad);
  58. if (m_maxWaitForPinPad <= 0 || m_maxWaitForPinPad > 5000)
  59. m_maxWaitForPinPad = 5000;//default
  60. CSimpleStringA csTmpTS("");
  61. GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTmpTS);
  62. if (csTmpTS.Compare("N") != 0)
  63. GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "X");
  64. SP::Module::Net::GetINETMacAddresses(m_netList);
  65. return Error_Succeed;
  66. }
  67. ErrorCodeEnum CHealthManagerFSM::OnInit(void)
  68. {
  69. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Complied at: %s %s", __DATE__, __TIME__);
  70. return Initial();
  71. }
  72. ErrorCodeEnum CHealthManagerFSM::OnExit(void)
  73. {
  74. return Error_Succeed;
  75. }
  76. void CHealthManagerFSM::s0_on_entry(void)
  77. {
  78. LOG_FUNCTION();
  79. m_fsmState = HM_FSM_INIT;
  80. m_ullElapseFromOSStart = SP::Module::Comm::RVCGetTickCount();
  81. m_elapseTimeFromOSStart = m_ullElapseFromOSStart / 1000;
  82. CSimpleStringA xMsg = CSimpleStringA::Format("{\"Decripstion\":\"Entity start\",\"version\":\"%s\",\"elapseTime\":\"%d\"}", m_sysInfo.InstallVersion.ToString().GetData(), m_elapseTimeFromOSStart);
  83. LogWarn(Severity_Low, Error_Unexpect, HealthManager_UserErrorCode_Enter_SafeLoad_State, xMsg.GetData());
  84. FSMEvent* pEvt = new FSMEvent(USER_EVT_WAIT_DEAMON_FINISHED);
  85. pEvt->param1 = 0;
  86. PostEventFIFO(pEvt);
  87. }
  88. void CHealthManagerFSM::s0_on_exit(void)
  89. {
  90. }
  91. unsigned int CHealthManagerFSM::s0_on_event(FSMEvent* pEvt)
  92. {
  93. int ret = 0;
  94. switch(pEvt->iEvt)
  95. {
  96. case USER_EVT_WAIT_DEAMON_FINISHED:
  97. ret = pEvt->param1;
  98. pEvt->SetHandled();
  99. break;
  100. default:
  101. break;
  102. }
  103. return ret;
  104. }
  105. //Idle(Operating finished)
  106. void CHealthManagerFSM::s4_on_entry()
  107. {
  108. m_fsmState = HM_FSM_STATE_IDLE;
  109. }
  110. void CHealthManagerFSM::s4_on_exit()
  111. {
  112. LOG_FUNCTION();
  113. }
  114. unsigned int CHealthManagerFSM::s4_on_event(FSMEvent* pEvt)
  115. {
  116. LOG_FUNCTION();
  117. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("s4 event %d,%d",pEvt->iEvt,pEvt->param1);
  118. switch(pEvt->iEvt)
  119. {
  120. case USER_EVT_ACCESSAUTH_FINISHED:
  121. {
  122. pEvt->SetHandled();
  123. CSimpleStringA csTermStage;
  124. ErrorCodeEnum eErrCode;
  125. eErrCode = GetEntityBase()->GetFunction()->GetSysVar("TerminalStage",csTermStage);
  126. DbgWithLink(LOG_LEVEL_DEBUG,LOG_TYPE_SYSTEM)("after accessauth to get termstage %s",(LPCTSTR)csTermStage);
  127. //oilyang@20220614 添加密钥更新逻辑
  128. if (csTermStage[0] == 'A')
  129. {
  130. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("after auth suc,to call WKUpdatePeriodTask");
  131. WKUpdatePeriodTask* pTask = new WKUpdatePeriodTask(this);
  132. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  133. }
  134. LogTermInfoTask* task = new LogTermInfoTask(this);
  135. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  136. if (m_iAccessAuth != VtmLoad_AccessAuth_Suc)
  137. PostProcessAfterUpgrade();
  138. }
  139. break;
  140. case USER_EVT_MAITAIN:
  141. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("to maintain...");
  142. m_stateBeforeMaintain = m_fsmState;
  143. pEvt->SetHandled();
  144. break;
  145. case USER_EVT_ENTER_CUSTOMER_MANAGER:
  146. pEvt->SetHandled();
  147. break;
  148. case USER_EVT_VTMLOADER_FINISHED:
  149. {
  150. pEvt->SetHandled();
  151. if (pEvt->param1 == 1)
  152. {
  153. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501V1").setResultCode("RTA510E")("VtmLoader load SIPphone entity failed, to Set TerminalStage M.");
  154. SetVtmLoadResult(VtmLoad_MediaLoadFail);
  155. return pEvt->param1;
  156. }
  157. else if (pEvt->param1 == 2)
  158. {
  159. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501V1").setResultCode("RTA510F")("VtmLoader load SYNCSTART(boot cfg = 2) entity failed, to Set TerminalStage C.");
  160. SetVtmLoadResult(VtmLoad_OtherSyncEntityLoadFail);
  161. return pEvt->param1;
  162. }
  163. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501A1")("VtmLoader load entitys ok.");
  164. if (m_iAccessAuth == VtmLoad_AccessAuth_Init)
  165. {
  166. WaitToCallAccessAuthTask* pTask = new WaitToCallAccessAuthTask(this);
  167. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  168. }
  169. }
  170. break;
  171. default:
  172. break;
  173. }
  174. return 0;
  175. }
  176. //Fault
  177. void CHealthManagerFSM::s5_on_entry()
  178. {
  179. LOG_FUNCTION();
  180. LogTermInfoTask* task = new LogTermInfoTask(this);
  181. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  182. m_fsmState = HM_FSM_STATE_FAULT;
  183. PostProcessAfterUpgrade();
  184. }
  185. void CHealthManagerFSM::s5_on_exit()
  186. {
  187. LOG_FUNCTION();
  188. }
  189. unsigned int CHealthManagerFSM::s5_on_event(FSMEvent* pEvt)
  190. {
  191. LOG_FUNCTION();
  192. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("s5(Fault) event %d,%d",pEvt->iEvt,pEvt->param1);
  193. switch(pEvt->iEvt)
  194. {
  195. case USER_EVT_MAITAIN:
  196. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("to maintain...");
  197. m_stateBeforeMaintain = m_fsmState;
  198. pEvt->SetHandled();
  199. break;
  200. case USER_EVT_ENTER_CUSTOMER_MANAGER:
  201. pEvt->SetHandled();
  202. break;
  203. case USER_EVT_ACCESSAUTH_FINISHED:
  204. pEvt->SetHandled();
  205. if (pEvt->param1 == 1)
  206. {
  207. return 1;
  208. }
  209. break;
  210. default:
  211. break;
  212. }
  213. return 0;
  214. }
  215. //Maintaining
  216. void CHealthManagerFSM::s6_on_entry()
  217. {
  218. LOG_FUNCTION();
  219. m_preFsmState = m_fsmState;
  220. m_fsmState = HM_FSM_STATE_MAINTAINING;
  221. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  222. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  223. if (pFuncPrivilege == NULL)
  224. {
  225. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("display screen NoPrivilege");
  226. return;
  227. }
  228. ErrorCodeEnum eErr = pFuncPrivilege->DisplayBlueScreen("暂停服务");
  229. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("display blue screen %d",eErr);
  230. }
  231. void CHealthManagerFSM::s6_on_exit()
  232. {
  233. LOG_FUNCTION();
  234. }
  235. unsigned int CHealthManagerFSM::s6_on_event(FSMEvent* pEvt)
  236. {
  237. LOG_FUNCTION();
  238. int ret = 0;
  239. switch(pEvt->iEvt)
  240. {
  241. case USER_EVT_MAITAIN_FINISHED:
  242. pEvt->SetHandled();
  243. {
  244. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  245. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  246. if (pFuncPrivilege == NULL)
  247. {
  248. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("un-display screen NoPrivilege");
  249. return 1;
  250. }
  251. ErrorCodeEnum eErr = pFuncPrivilege->UndisplayBlueScreen();
  252. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("un-display blue screen %d",eErr);
  253. if (m_stateBeforeMaintain == HM_FSM_STATE_IDLE)
  254. {
  255. }
  256. ret = m_preFsmState;
  257. }
  258. break;
  259. case USER_EVT_ENTER_CUSTOMER_MANAGER:
  260. pEvt->SetHandled();
  261. break;
  262. default:
  263. break;
  264. }
  265. return ret;
  266. }
  267. //In Customer Manager System
  268. void CHealthManagerFSM::s11_on_entry()
  269. {
  270. LOG_FUNCTION();
  271. m_preFsmState = m_fsmState;
  272. m_fsmState = HM_FSM_STATE_CMS;
  273. }
  274. void CHealthManagerFSM::s11_on_exit()
  275. {
  276. LOG_FUNCTION();
  277. }
  278. unsigned int CHealthManagerFSM::s11_on_event(FSMEvent* pEvt)
  279. {
  280. LOG_FUNCTION();
  281. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("s11(In CMS) event %d",pEvt->iEvt);
  282. int ret = 0;
  283. switch (pEvt->iEvt)
  284. {
  285. case USER_EVT_MAITAIN:
  286. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("to maintain...");
  287. m_stateBeforeMaintain = m_fsmState;
  288. pEvt->SetHandled();
  289. break;
  290. case USER_EVT_SWITCH_BACK_TO_RVC:
  291. pEvt->SetHandled();
  292. ret = m_preFsmState;
  293. break;
  294. default:
  295. break;
  296. }
  297. return ret;
  298. }
  299. //0:auth suc or have already authed;1:auth failed;
  300. int CHealthManagerFSM::AccessAuthDoWork()
  301. {
  302. LOG_FUNCTION();
  303. CheckIfPinPadOK();
  304. m_bInAccessAuthDoWork = true;
  305. CSimpleStringA csTermStage("");
  306. ErrorCodeEnum eErrCode = GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTermStage);
  307. if (eErrCode == Error_Succeed)
  308. {
  309. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("before accessauth get TerminalStage %s", csTermStage.GetData());
  310. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  311. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  312. CEntityRunInfo acInfo;
  313. eErrCode = pFunc->GetEntityRunInfo("AccessAuthorization", acInfo);
  314. if (eErrCode == Error_Succeed)
  315. {
  316. switch (acInfo.eState)
  317. {
  318. case EntityState_NoStart:
  319. {
  320. CSmartPointer<IAsynWaitSp> spWaitAC;
  321. eErrCode = pFuncPrivilege->StartEntity("AccessAuthorization", NULL, spWaitAC);
  322. eErrCode = spWaitAC->WaitAnswer(MAX_AYSNC_TIMEOUT);
  323. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start accessauth %d.", eErrCode);
  324. }
  325. break;
  326. case EntityState_Idle:
  327. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("AccessAuth state idle.");
  328. break;
  329. default:
  330. break;
  331. }
  332. if (m_pACClient == NULL)
  333. {
  334. m_pACClient = new AccessAuthService_ClientBase(this->GetEntityBase());
  335. eErrCode = m_pACClient->Connect();
  336. if (eErrCode != Error_Succeed) {
  337. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("accessauth connected failed:%s", SpStrError(eErrCode));
  338. m_pACClient->SafeDelete();
  339. m_pACClient = NULL;
  340. m_bInAccessAuthDoWork = false;
  341. return 1;
  342. }
  343. else {
  344. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("accessauth connected.");
  345. }
  346. }
  347. }
  348. else
  349. {
  350. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("Get AccessAuth RunInfo failed(%s).", SpStrError(eErrCode));
  351. m_bInAccessAuthDoWork = false;
  352. return 1;
  353. }
  354. if (m_pACClient != NULL)
  355. {
  356. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to call accessauth regist");
  357. CSystemRunInfo sysRunInfo;
  358. if (GetEntityBase()->GetFunction()->GetSystemRunInfo(sysRunInfo) != Error_Succeed || sysRunInfo.eAppBootState == AppBootState_StartEntity)
  359. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->RefreshAppBootState(AppBootState_CallAccessAuth);
  360. m_ullAuthStart = SP::Module::Comm::RVCGetTickCount();
  361. eErrCode = (*m_pACClient)(EntityResource::getLink().upgradeLink())->Regist();
  362. m_bHasAuthEver = true;
  363. if (eErrCode == Error_Succeed)
  364. {
  365. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501A4")("call AccessAuth's Regist return succeed");
  366. do {
  367. if (m_iAccessAuth != VtmLoad_AccessAuth_Init)
  368. break;
  369. Sleep(1000);
  370. } while (1);//wait for accessauth send result
  371. m_bFirstAccessAuth = false;
  372. m_bInAccessAuthDoWork = false;
  373. return 0;
  374. }
  375. else
  376. {
  377. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501A4").setResultCode("RTA5102")("call accessauth Regist failed:%s", SpStrError(eErrCode));
  378. m_bInAccessAuthDoWork = false;
  379. return 1;
  380. }
  381. }
  382. else
  383. {
  384. m_bInAccessAuthDoWork = false;
  385. return 1;
  386. }
  387. }
  388. else {
  389. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("Get TerminalStage failed(%s).", SpStrError(eErrCode));
  390. }
  391. m_bInAccessAuthDoWork = false;
  392. return 1;
  393. }
  394. void CHealthManagerFSM::SetVtmLoadResult(int bResult)
  395. {
  396. m_iAccessAuth = bResult;
  397. ErrorCodeEnum eErrCode;
  398. if (bResult == VtmLoad_AccessAuth_Suc)
  399. {
  400. eErrCode = GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "A");
  401. m_ullAccessAuthCost = SP::Module::Comm::RVCGetTickCount() - m_ullAuthStart;
  402. }
  403. else if (bResult == VtmLoad_AccessAuth_servFail) //准入服务端返回失败
  404. {
  405. eErrCode = GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "S");
  406. m_ullAccessAuthCost = SP::Module::Comm::RVCGetTickCount() - m_ullAuthStart;
  407. }
  408. else if (bResult == VtmLoad_MediaLoadFail) //音视频校验不通过
  409. {
  410. eErrCode = GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "M");
  411. }
  412. else //其他失败
  413. {
  414. eErrCode = GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "C");
  415. if (bResult != VtmLoad_OtherSyncEntityLoadFail)//if haven't call Regist(), no need to calulate the AccessAuth cost
  416. m_ullAccessAuthCost = SP::Module::Comm::RVCGetTickCount() - m_ullAuthStart;
  417. }
  418. if (eErrCode != Error_Succeed)
  419. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("set TerminalStage %d,failed:%s", bResult, SpStrError(eErrCode));
  420. else
  421. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("set TerminalStage %d", bResult);
  422. }
  423. void CHealthManagerFSM::ToReAccessAuth(bool bEver)
  424. {
  425. Sleep(1500);//for function "AccessAuthDoWork" to quit while
  426. if (m_bFirstAccessAuth)
  427. return;
  428. ToCallAccessAuthDoWork();
  429. }
  430. ErrorCodeEnum CHealthManagerFSM::AsyncStartEntity(const char *entity_name, const char *cmdline, void *pData)
  431. {
  432. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  433. ErrorCodeEnum errCode;
  434. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  435. if (pFuncPrivilege != NULL) {
  436. CSmartPointer<IAsynWaitSp> spWait;
  437. errCode = pFuncPrivilege->StartEntity(entity_name, cmdline, spWait);
  438. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("start entity %s,errCode:%s", entity_name, SpStrError(errCode));
  439. if (errCode == Error_Succeed) {
  440. callback_entry *entry = new callback_entry();
  441. entry->pRawData = pData;
  442. entry->EntityName = entity_name;
  443. entry->ErrorResult = Error_Unexpect;
  444. entry->op = OP_START_ENTITY;
  445. if (spWait != NULL)
  446. spWait->SetCallback(this, entry);
  447. }
  448. return errCode;
  449. } else {
  450. return Error_NoPrivilege;
  451. }
  452. }
  453. ErrorCodeEnum CHealthManagerFSM::AsyncStopEntity(const char *entity_name, void *pData)
  454. {
  455. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  456. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  457. if (pFuncPrivilege != NULL) {
  458. CSmartPointer<IAsynWaitSp> spWait;
  459. ErrorCodeEnum Error = pFuncPrivilege->StopEntity(entity_name, spWait);
  460. if (Error == Error_Succeed) {
  461. callback_entry *entry = new callback_entry();
  462. entry->pRawData = pData;
  463. entry->EntityName = entity_name;
  464. entry->ErrorResult = Error_Unexpect;
  465. entry->op = OP_STOP_ENTITY;
  466. if (spWait != NULL)
  467. spWait->SetCallback(this, entry);
  468. }
  469. return Error;
  470. } else {
  471. return Error_NoPrivilege;
  472. }
  473. }
  474. ErrorCodeEnum CHealthManagerFSM::AsyncPauseEntity(const char *entity_name, void *pData)
  475. {
  476. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  477. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  478. if (pFuncPrivilege != NULL) {
  479. CSmartPointer<IAsynWaitSp> spWait;
  480. ErrorCodeEnum Error = pFuncPrivilege->PauseEntity(entity_name, spWait);
  481. if (Error == Error_Succeed) {
  482. callback_entry *entry = new callback_entry();
  483. entry->pRawData = pData;
  484. entry->EntityName = entity_name;
  485. entry->ErrorResult = Error_Unexpect;
  486. entry->op = OP_PAUSE_ENTITY;
  487. if (spWait != NULL)
  488. spWait->SetCallback(this, entry);
  489. }
  490. return Error;
  491. } else {
  492. return Error_NoPrivilege;
  493. }
  494. }
  495. ErrorCodeEnum CHealthManagerFSM::AsyncContinueEntity(const char *entity_name, void *pData)
  496. {
  497. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  498. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  499. if (pFuncPrivilege != NULL) {
  500. CSmartPointer<IAsynWaitSp> spWait;
  501. ErrorCodeEnum Error = pFuncPrivilege->ContinueEntity(entity_name, spWait);
  502. if (Error == Error_Succeed) {
  503. callback_entry *entry = new callback_entry();
  504. entry->pRawData = pData;
  505. entry->EntityName = entity_name;
  506. entry->ErrorResult = Error_Unexpect;
  507. entry->op = OP_CONTINUE_ENTITY;
  508. if (spWait != NULL)
  509. spWait->SetCallback(this, entry);
  510. }
  511. return Error;
  512. } else {
  513. return Error_NoPrivilege;
  514. }
  515. }
  516. ErrorCodeEnum CHealthManagerFSM::AsyncTerminateEntity(const char *entity_name, void *pData)
  517. {
  518. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  519. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  520. if (pFuncPrivilege != NULL) {
  521. CSmartPointer<IAsynWaitSp> spWait;
  522. ErrorCodeEnum Error = pFuncPrivilege->TerminateEntity(entity_name, spWait);
  523. if (Error == Error_Succeed) {
  524. callback_entry *entry = new callback_entry();
  525. entry->pRawData = pData;
  526. entry->EntityName = entity_name;
  527. entry->ErrorResult = Error_Unexpect;
  528. entry->op = OP_TERMINATE_ENTITY;
  529. if (spWait != NULL)
  530. spWait->SetCallback(this, entry);
  531. }
  532. return Error;
  533. } else {
  534. return Error_NoPrivilege;
  535. }
  536. }
  537. void CHealthManagerFSM::OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp)
  538. {
  539. }
  540. int CHealthManagerFSM::QuitFrameworkAndSaveInfo(RebootTriggerEnum eTrigger, RebootWayEnum eWay)
  541. {
  542. m_bRebooting = true;
  543. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  544. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  545. if (pFuncPrivilege == NULL) {
  546. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("has no privilege");
  547. return (int)(Error_NoPrivilege);
  548. }
  549. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("quit framework and info %d,%d.", eTrigger, eWay);
  550. const auto result = pFuncPrivilege->Reboot(eTrigger, eWay);
  551. return (int)result;
  552. }
  553. void CHealthManagerFSM::PostProcessAfterUpgrade()
  554. {
  555. LOG_FUNCTION();
  556. if (IfInUpgradeProcess())
  557. {
  558. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("exist upgrade flag file,to decide if restart framework.");
  559. //存在升级后的启动文件
  560. CSmartPointer<IConfigInfo> spConfigRun;
  561. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfigRun);
  562. if (eErr == Error_Succeed)
  563. {
  564. int restartOSTime = 0;
  565. spConfigRun->ReadConfigValueInt("Run", "UpgradeRestartOSTimes", restartOSTime);
  566. if(restartOSTime==1){
  567. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("升级切换已重启过系统");
  568. //重启过的系统过的升级,在重试一定次数后等guardian 10分钟回退
  569. int xTimes = 0;
  570. spConfigRun->ReadConfigValueInt("Run", "UpgradeRestartTimes", xTimes);
  571. if (xTimes < 3)
  572. {
  573. xTimes++;
  574. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("写入: UpgradeRestartTimes:%d", xTimes);
  575. spConfigRun->WriteConfigValueInt("Run", "UpgradeRestartTimes", xTimes);
  576. QuitFrameworkAndSaveInfo(RebootTrigger_Resource, RebootWay_Framework);
  577. }
  578. }else{
  579. //未重启过操作系统
  580. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("升级切换未重启过系统");
  581. int xTimes = 0;
  582. spConfigRun->ReadConfigValueInt("Run", "UpgradeRestartTimes", xTimes);
  583. if (xTimes < 3)
  584. {
  585. xTimes++;
  586. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("写入: UpgradeRestartTimes:%d", xTimes);
  587. spConfigRun->WriteConfigValueInt("Run", "UpgradeRestartTimes", xTimes);
  588. //oilyang@20211130 change from 3 to 2
  589. if (xTimes == 2)
  590. {
  591. //重启操作系统前把重启框架次数重置,重启OS次数置为1
  592. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("准备尝试重启系统后再切换升级");
  593. spConfigRun->WriteConfigValueInt("Run", "UpgradeRestartTimes", 0);
  594. spConfigRun->WriteConfigValueInt("Run", "UpgradeRestartOSTimes", 1);
  595. Sleep(2000);
  596. QuitFrameworkAndSaveInfo(RebootTrigger_Resource, RebootWay_OS);
  597. }
  598. else
  599. QuitFrameworkAndSaveInfo(RebootTrigger_Resource, RebootWay_Framework);
  600. }
  601. }
  602. }
  603. }
  604. }
  605. CSimpleStringA CHealthManagerFSM::GetOsVersion()
  606. {
  607. #if defined(RVC_OS_WIN)
  608. CSimpleStringA runInfoPath;
  609. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
  610. if (eErr != Error_Succeed) {
  611. DbgWithLink(LOG_LEVEL_ERROR,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("GetPath runinfo error=%s.", SpStrError(eErr));
  612. return "";
  613. }
  614. runInfoPath += "\\runcfg\\osverion";
  615. ifstream is;
  616. is.open(runInfoPath.GetData(), ios::binary);
  617. if (!is.is_open())
  618. {
  619. DWORD dwErr = GetLastError();
  620. DbgWithLink(LOG_LEVEL_ERROR,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("open runcfg\\osverion file failed. [%d]", dwErr);
  621. return "";
  622. }
  623. string line;
  624. while(!is.eof()){
  625. getline(is, line);
  626. int start = line.find("版本");
  627. if (start != string::npos)
  628. //return CSimpleStringA(line.substr(start + 5, line.length() - start - 7).c_str());
  629. return CSimpleStringA(line.c_str());
  630. else
  631. continue;
  632. }
  633. return "";
  634. #else
  635. std::map<std::string, std::string> osInfo;
  636. const char filePath[] = "/etc/os-version";
  637. char tmp[33];
  638. memset(tmp, 0, 33);
  639. inifile_read_str_s("Version", "SystemName", "unknown", tmp, 32, filePath);
  640. osInfo["SystemName"] = tmp;
  641. memset(tmp, 0, 33);
  642. inifile_read_str_s("Version", "ProductType", "unknown", tmp, 32, filePath);
  643. osInfo["ProductType"] = tmp;
  644. memset(tmp, 0, 33);
  645. inifile_read_str_s("Version", "MajorVersion", "unknown", tmp, 32, filePath);
  646. osInfo["MajorVersion"] = tmp;
  647. memset(tmp, 0, 33);
  648. inifile_read_str_s("Version", "MinorVersion", "unknown", tmp, 32, filePath);
  649. osInfo["MinorVersion"] = tmp;
  650. memset(tmp, 0, 33);
  651. inifile_read_str_s("Version", "OsBuild", "unknown", tmp, 32, filePath);
  652. osInfo["OsBuild"] = tmp;
  653. return generateJsonStr(osInfo).second.c_str();
  654. #endif
  655. }
  656. DWORD GetDualTime(SYSTEMTIME& t1, SYSTEMTIME& t2)
  657. {
  658. //assume t2 > t1...
  659. //oiltest for simple
  660. int s1, s2;
  661. s1 = (t1.wMinute * 60 + t1.wSecond) * 1000 + t1.wMilliseconds;
  662. s2 = (t2.wMinute * 60 + t2.wSecond) * 1000 + t2.wMilliseconds;
  663. return s2 - s1;
  664. }
  665. void CHealthManagerFSM::ToLogWarnTermAboutInfo()
  666. {
  667. LOG_FUNCTION();
  668. bool bTmpEtyNewStart = m_bEntityNewStart;
  669. if (m_bEntityNewStart)
  670. {
  671. SYSTEMTIME shellStartTime;
  672. m_ullTotalCost = 0;
  673. m_bEntityNewStart = false;
  674. CAutoArray<CSimpleStringA> strEntityNames;
  675. CAutoArray<int> strEntityIdx;
  676. CAutoArray<CEntityStartInfo> Infos;
  677. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetAllEntityStartInfo(strEntityNames, strEntityIdx, Infos);
  678. for (int i = 0; i < Infos.GetCount(); ++i)
  679. {
  680. if (strEntityIdx[i] == 0)
  681. {
  682. shellStartTime = Infos[i].startTime;
  683. ULONGLONG dwElapseNow = SP::Module::Comm::RVCGetTickCount();
  684. m_ullTotalCost = dwElapseNow - m_ullElapseFromOSStart;
  685. LogWarn(Severity_Low, Error_Debug, LOG_TRACE_ENTITY_START_TIME,
  686. SP::Module::Util::generateConsumeTimeJson("total", SP::Module::Util::formatTime(shellStartTime).c_str(), m_ullTotalCost).GetData());
  687. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("EntityStartCost")(SP::Module::Util::generateConsumeTimeJson("total", SP::Module::Util::formatTime(shellStartTime).c_str(), m_ullTotalCost).GetData());
  688. //break;
  689. }
  690. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s,%d", strEntityNames[i].GetData(), GetDualTime(Infos[i].startTime, Infos[i].startEndTime));
  691. if (strEntityNames[i].Compare("SIPPhone") == 0)
  692. m_ullSIPPhoneCost = GetDualTime(Infos[i].startTime, Infos[i].startEndTime);
  693. else if (strEntityNames[i].Compare("TokenKeeper") == 0)
  694. m_ullTokenKeeperCost = GetDualTime(Infos[i].startTime, Infos[i].startEndTime);
  695. }
  696. std::map<std::string, std::string> termStartInfo;
  697. termStartInfo["SIPPhoneCost"] = CSimpleStringA::Format("%d", m_ullSIPPhoneCost);
  698. termStartInfo["TokenKeeperCost"] = CSimpleStringA::Format("%d", m_ullTokenKeeperCost);
  699. termStartInfo["WaitForPinPadCost"] = CSimpleStringA::Format("%d", m_ullWaitForPinPad);
  700. termStartInfo["TotalCost"] = CSimpleStringA::Format("%d", m_ullTotalCost);
  701. termStartInfo["AccessAuthCost"] = CSimpleStringA::Format("%d", m_ullAccessAuthCost);
  702. termStartInfo["AccessAuthResult"] = CSimpleStringA::Format("%d", m_iAccessAuth);
  703. termStartInfo["OSElapseTime"] = CSimpleStringA::Format("%d", m_elapseTimeFromOSStart);
  704. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("TerminalStartCost")("%s", generateJsonStr(termStartInfo).second.c_str());
  705. LogWarn(Severity_Low, Error_Debug, HealthManager_UserErrorCode_TerminalAppLoadInfo, generateJsonStr(termStartInfo).second.c_str());
  706. }
  707. QueryAndSaveDNS();
  708. QueryAndSendCPUInfo();
  709. QueryAndSendDisplayInfo();
  710. CSimpleStringA csOSVerion(""), csWarnMsg("");
  711. std::map<std::string, std::string> termInfo;
  712. termInfo["version"] = m_sysInfo.InstallVersion.ToString();
  713. if (m_iAccessAuth == VtmLoad_AccessAuth_Suc)
  714. {
  715. termInfo["AccessAuth"] = "T";
  716. }
  717. else
  718. {
  719. termInfo["AccessAuth"] = "F";
  720. CSimpleStringA tmpAuthErrMsg("");
  721. if (GetEntityBase()->GetFunction()->GetSysVar("AuthErrMsg", tmpAuthErrMsg) == Error_Succeed)
  722. termInfo["AuthErrMsg"] = tmpAuthErrMsg;
  723. }
  724. csOSVerion = GetOsVersion();
  725. if (!csOSVerion.IsNullOrEmpty())
  726. termInfo["OSVersion"] = csOSVerion;
  727. termInfo["Harddisk"] = QueryHarddiskInfo();
  728. #if defined(RVC_OS_WIN)
  729. termInfo["OSType"] = "Windows";
  730. termInfo["AsiaInfo"] = CheckProcessExistByName("NTRtScan.exe") ? "Y" : "N";
  731. termInfo["UniAccess"] = CheckProcessExistByName("UniAccessAgent.exe") ? "Y" : "N";
  732. termInfo["RuiYan"] = CheckProcessExistByName("RuiYan.exe") ? "Y" : "N";
  733. termInfo["Symantec"] = CheckProcessExistByName("SavUI.exe") ? "Y" : "N";
  734. #else
  735. termInfo["OSType"] = "UOS";
  736. #endif
  737. CSmartPointer<IConfigInfo> spConfigRun;
  738. GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfigRun);
  739. //CAutoArray<SP::Module::Net::NetworkAdapterItem> netList;
  740. if (m_netList.GetCount() == 0)
  741. SP::Module::Net::GetINETMacAddresses(m_netList);
  742. CSimpleStringA csMac(""), csIP(""), csDNS("");
  743. for (int i = 0; i < m_netList.GetCount(); i++) {
  744. if (!csMac.IsNullOrEmpty()) {
  745. csMac += ";";
  746. }
  747. csMac += m_netList[i].mac.c_str();
  748. if (!csIP.IsNullOrEmpty()) {
  749. csIP += ";";
  750. }
  751. csIP += m_netList[i].ip.c_str();
  752. }
  753. for (int i = 0; i < m_dns.GetCount(); i++) {
  754. if (!csDNS.IsNullOrEmpty()) {
  755. csDNS += ";";
  756. }
  757. csDNS += m_dns[i].c_str();
  758. }
  759. termInfo["MACs"] = csMac;
  760. termInfo["IPs"] = csIP;
  761. termInfo["DNSs"] = csDNS;
  762. char xOSTime[64] = {0};
  763. char elapseTime[64] = {0};//使用机器启动时间秒数
  764. ULONGLONG dwElapse = SP::Module::Comm::RVCGetTickCount();
  765. DWORD elapseTimeTemp = dwElapse / 1000;
  766. //TODO: CrossPlaform [Gifur@2025729]
  767. #if defined(RVC_OS_WIN)
  768. termInfo["OSTime"] = itoa(m_elapseTimeFromOSStart, xOSTime, 10);
  769. termInfo["elapseTime"] = itoa(elapseTimeTemp, elapseTime, 10);
  770. #else
  771. termInfo["OSTime"] = _itoa(m_elapseTimeFromOSStart, xOSTime, 10);
  772. termInfo["elapseTime"] = _itoa(elapseTimeTemp, elapseTime, 10);
  773. #endif
  774. CSimpleStringA csRunPath("");
  775. GetEntityBase()->GetFunction()->GetPath("Run", csRunPath);
  776. termInfo["AppPath"] = csRunPath;
  777. std::pair<bool, std::string> strResult;
  778. strResult = generateJsonStr(termInfo);
  779. spConfigRun->ReadConfigValue("Run", "WarnMsg", csWarnMsg);
  780. //oilyang@20210323 discard the following rule of throwing LogWarn.Always throw LogWarn
  781. //oilyang@20201201 log warn every time if content of msg has changed
  782. if (bTmpEtyNewStart)
  783. {
  784. LogWarn(Severity_Low, Error_Unexpect, LOG_WARN_HEALTH_UPLOAD_INFO_ABOUT_TERM, strResult.second.c_str());
  785. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutTerm")(strResult.second.c_str());
  786. }
  787. else
  788. {
  789. LogWarn(Severity_Low, Error_Unexpect, LOG_WARN_HEALTH_UPLOAD_INFO_ABOUT_TERM, strResult.second.c_str());
  790. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutTerm")(strResult.second.c_str());
  791. }
  792. }
  793. void CHealthManagerFSM::ToCallAccessAuthDoWork()
  794. {
  795. if (!m_bInAccessAuthDoWork)
  796. {
  797. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("To Call AccessAuthDoWork");
  798. AccessAuthTask* pTask = new AccessAuthTask(this);
  799. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  800. }
  801. }
  802. bool CHealthManagerFSM::IfInUpgradeProcess()
  803. {
  804. CSimpleStringA csRunCfgPath(""), csFileName("");
  805. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("RunCfg", csRunCfgPath);
  806. csFileName = csRunCfgPath + SPLIT_SLASH_STR + "starttime.dat";
  807. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("csFileName:%s", csFileName.GetData());
  808. #if defined(RVC_OS_WIN)
  809. if (_access((const char*)csFileName, 0) == 0) {
  810. #else
  811. if (access((const char*)csFileName, F_OK) == 0) {
  812. #endif
  813. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("升级切换中");
  814. return true;
  815. }
  816. else
  817. return false;
  818. }
  819. void CHealthManagerFSM::WaitToCallAccessAuthDoWork()
  820. {
  821. //WaitForSingleObject
  822. bool bHaveShowMsg = false;
  823. while (1)
  824. {
  825. CSimpleStringA csHavePath("N");
  826. GetEntityBase()->GetFunction()->GetSysVar("AccessHavePath", csHavePath);
  827. if (csHavePath.Compare("Y") == 0 || csHavePath.Compare("E") == 0)
  828. {
  829. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501A2")("AccessAuth entity ok.");
  830. AccessAuthTask* pTask = new AccessAuthTask(this);
  831. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  832. break;
  833. }
  834. else
  835. {
  836. Sleep(5000);
  837. LogWarn(Severity_High, Error_Unexpect, HealthManager_UserErrorCode_WaitForAccessAuthEntityIdle, "等待准入实体准备好");
  838. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501A2").setResultCode("RTA5107")("等待准入实体准备好");
  839. }
  840. }
  841. }
  842. void CHealthManagerFSM::WKUpdatePeriod()
  843. {
  844. if (m_sysInfo.strTerminalID.GetLength() < 7)
  845. {
  846. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("wrong terminalNo:[%s]", m_sysInfo.strTerminalID.GetData());
  847. return;
  848. }
  849. auto pEntity = ((CHealthManagerEntity*)m_pEntity);
  850. //oilyang@20220413 control update working key by CenterSetting
  851. if (m_iDoNotUpdateWKDaily == 1)
  852. {
  853. // 没有密码键盘 或 集中配置告知无需更新,无需更新
  854. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)
  855. (CSimpleStringA::Format("DoNotUpdateWKDaily:%d, ignore update wk"
  856. , m_iDoNotUpdateWKDaily));
  857. return;
  858. }
  859. // 检查上次密钥同步时间(一天只同步一次)
  860. CSmartPointer<IConfigInfo> pConfigRun;
  861. m_pEntity->GetFunction()->OpenConfig(Config_Run, pConfigRun);
  862. int nWKLastSyncTime(0);
  863. pConfigRun->ReadConfigValueInt("Main", "WKSyncSuccTime", nWKLastSyncTime);
  864. int nWKSyncFailCount(0);
  865. pConfigRun->ReadConfigValueInt("Main", "WKSyncFailCount", nWKSyncFailCount);
  866. SYSTEMTIME stSyncTime = CSmallDateTime(nWKLastSyncTime).ToSystemTime();
  867. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)
  868. ("last WK sync time: %04d-%02d-%02d %02d:%02d:%02d",
  869. stSyncTime.wYear, stSyncTime.wMonth, stSyncTime.wDay,
  870. stSyncTime.wHour, stSyncTime.wMinute, stSyncTime.wSecond);
  871. SYSTEMTIME stNow = {};
  872. GetLocalTimeRVC(stNow);
  873. int lastUpdateDays = sumday(stSyncTime.wYear, stSyncTime.wMonth, stSyncTime.wDay);
  874. int todayDays = sumday(stNow.wYear, stNow.wMonth, stNow.wDay);
  875. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("lastUpdateDays:%d,todayDays:%d,x:%d", lastUpdateDays,todayDays, todayDays-lastUpdateDays);
  876. //if ((nWKLastSyncTime > 0 && stSyncTime.wYear == stNow.wYear
  877. // && stSyncTime.wMonth == stNow.wMonth && stSyncTime.wDay == stNow.wDay
  878. // && nWKSyncFailCount == 0)) // 最近一次同步成功,才能跳过
  879. if (todayDays - lastUpdateDays < m_wkUpdatePeriod)
  880. {
  881. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)
  882. ("WK has been updated, last sync time: %s", (const char*)CSmallDateTime(nWKLastSyncTime).ToTimeString());
  883. }
  884. else
  885. {
  886. //if have exceed the time,we should update working key in the next peroid
  887. if (todayDays - lastUpdateDays < m_wkUpdatePeriod * 2)
  888. {
  889. int xTerm = atoi(m_sysInfo.strTerminalID.SubString(m_sysInfo.strTerminalID.GetLength() - 7, 7));
  890. if ((todayDays % m_wkUpdatePeriod) != (xTerm % m_wkUpdatePeriod))
  891. {
  892. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("todayDays:%d, xTerm:%d, m_wkUpdatePeriod:%d", todayDays, xTerm, m_wkUpdatePeriod);
  893. return;
  894. }
  895. }
  896. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("begin update WK now");
  897. ErrorCodeEnum eErrCode = Error_Succeed;
  898. if (m_pACClient == NULL)
  899. {
  900. m_pACClient = new AccessAuthService_ClientBase(this->GetEntityBase());
  901. eErrCode = m_pACClient->Connect();
  902. if (eErrCode != Error_Succeed) {
  903. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("accessauth connected failed:%d", eErrCode);
  904. m_pACClient->SafeDelete();
  905. m_pACClient = NULL;
  906. m_bInAccessAuthDoWork = false;
  907. return;
  908. }
  909. else {
  910. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("accessauth connected.");
  911. }
  912. }
  913. eErrCode = (*m_pACClient)(EntityResource::getLink().upgradeLink())->UpdateWK();
  914. if(Error_Succeed == eErrCode)
  915. {
  916. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501K1")("accessauth updatewk succ.");
  917. pConfigRun->WriteConfigValue("Main", "WKSyncSuccTime",
  918. (const char*) CSimpleStringA::Format("0x%08X", (DWORD)CSmallDateTime::GetNow()));
  919. pConfigRun->WriteConfigValueInt("Main", "WKSyncFailCount", 0);
  920. }
  921. else
  922. {
  923. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501K1").setResultCode("RTA5103")("accessauth updatewk failed.");
  924. nWKSyncFailCount++;
  925. pConfigRun->WriteConfigValueInt("Main", "WKSyncFailCount", nWKSyncFailCount);
  926. }
  927. }
  928. }
  929. int CHealthManagerFSM::sumday(int year, int month, int day)
  930. {
  931. int days[2][13] = { {0,31,59,90,120,151,181,212,243,273,304,334,365},{0,31,60,91,121,152,182,213,244,274,305,335,366} };
  932. int iLeapYear = 0;
  933. if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
  934. iLeapYear = 1;
  935. int yearday = year * 365 + year / 4 - year / 100 + year / 400;
  936. int monthday = days[iLeapYear][month - 1];
  937. return yearday + monthday + day;
  938. }
  939. void CHealthManagerFSM::QueryHardwareInfo(SpReqAnsContext<HealthManagerService_QueryHardwareInfo_Req, HealthManagerService_QueryHardwareInfo_Ans>::Pointer ctx)
  940. {
  941. CSystemStaticInfo info;
  942. GetEntityBase()->GetFunction()->GetSystemStaticInfo(info);
  943. //CAutoArray<SP::Module::Net::NetworkAdapterItem> netList;
  944. if (m_netList.GetCount() == 0)
  945. SP::Module::Net::GetINETMacAddresses(m_netList);
  946. CAutoArray<CSimpleStringA> ipAddrs, macAddrs;
  947. for (int i = 0; i < m_netList.GetCount(); i++) {
  948. CSimpleStringA tmpip = m_netList[i].ip.c_str();
  949. CSimpleStringA tmpmac = m_netList[i].mac.c_str();
  950. ipAddrs.Append(&tmpip, 0, 1);
  951. macAddrs.Append(&tmpmac, 0, 1);
  952. }
  953. ctx->Ans.ip = ipAddrs;
  954. ctx->Ans.mac = macAddrs;
  955. ctx->Ans.machineType = info.strMachineType;
  956. ctx->Ans.site = info.strSite;
  957. ctx->Ans.terminalNo = info.strTerminalID;
  958. ctx->Ans.termLimit = "";
  959. ctx->Ans.termVersion = info.InstallVersion.ToString();
  960. //oilyang@20241220 (win)不再获取操作系统信息
  961. ctx->Ans.reserved3 = "";
  962. ctx->Ans.reserved4 = "";
  963. //oilyang@20241220 标准版搜狗输入法推全行已久,默认给1,即走标准输入法。待郭丹下线业务端依赖逻辑后废弃此字段使用
  964. ctx->Ans.reserved2 = 1;
  965. //reserved1
  966. #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
  967. ctx->Ans.reserved1 = 1;
  968. #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
  969. ctx->Ans.reserved1 = 2;
  970. #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
  971. ctx->Ans.reserved1 = 3;
  972. #elif defined(DEVOPS_ON_DEV)/*DevOps流水线编译,Dev环境*/
  973. ctx->Ans.reserved1 = 0;
  974. #else/*本地编译等非DevOps环境编译的版本*/
  975. ctx->Ans.reserved1 = 0;
  976. #endif
  977. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501Q1")("termNo:%s,termVersion:%s,env:%d,machineType:%s", ctx->Ans.terminalNo.GetData(), ctx->Ans.termVersion.GetData(), ctx->Ans.reserved1
  978. , ctx->Ans.machineType.GetData());
  979. ctx->Answer(Error_Succeed);
  980. }
  981. bool CHealthManagerFSM::CheckProcessExistByName(CSimpleStringA procName)
  982. {
  983. if (procName.IsNullOrEmpty())
  984. return false;
  985. #ifdef RVC_OS_WIN
  986. HANDLE hSnapshot;
  987. //find if have "NTRtScan.exe"
  988. hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  989. if (hSnapshot)
  990. {
  991. PROCESSENTRY32 pe;
  992. pe.dwSize = sizeof(pe);
  993. if (Process32First(hSnapshot, &pe))
  994. {
  995. do {
  996. if (_stricmp(&pe.szExeFile[0], procName.GetData()) == 0)
  997. {
  998. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("find %s on this machine.", procName.GetData());
  999. return true;
  1000. }
  1001. } while (Process32Next(hSnapshot, &pe));
  1002. }
  1003. CloseHandle(hSnapshot);
  1004. }
  1005. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("can't find %s on this machine.", procName.GetData());
  1006. return false;
  1007. #else
  1008. return false;
  1009. #endif
  1010. }
  1011. void CHealthManagerFSM::QueryAndSaveDNS()
  1012. {
  1013. for (int i = 0; i < m_dns.GetCount(); ++i)
  1014. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("before to get, the m_dns[%s]", m_dns[i].c_str());
  1015. m_dns.Clear();
  1016. CSimpleStringA runInfoPath, csDNSKeyword;
  1017. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
  1018. if (eErr != Error_Succeed) {
  1019. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetPath runinfo error=%d.", eErr);
  1020. return;
  1021. }
  1022. runInfoPath = runInfoPath + SPLIT_SLASH_STR + "runcfg" + SPLIT_SLASH_STR + "dns";
  1023. #if defined(RVC_OS_WIN)
  1024. CSimpleStringA csCmd;
  1025. csCmd = CSimpleStringA::Format("cmd /c ipconfig /all >%s", runInfoPath.GetData());
  1026. WinExec((LPCSTR)csCmd, SW_HIDE);
  1027. csDNSKeyword = "DNS 服务器";
  1028. #else
  1029. std::string sucContent, failedContent;
  1030. CSimpleStringA strCmd;
  1031. strCmd = CSimpleStringA::Format("cat /etc/resolv.conf | grep \"nameserver\" >%s", runInfoPath.GetData());
  1032. bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
  1033. csDNSKeyword = "nameserver";
  1034. #endif //RVC_OS_WIN
  1035. ifstream is;
  1036. is.open(runInfoPath.GetData(), ios::binary);
  1037. if (!is.is_open())
  1038. {
  1039. DWORD dwErr = GetLastError();
  1040. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("open %s file failed. [%d]", runInfoPath.GetData(), dwErr);
  1041. return;
  1042. }
  1043. string line;
  1044. while (!is.eof()) {
  1045. getline(is, line);
  1046. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("line:%s", line.c_str());
  1047. size_t start = line.find(csDNSKeyword.GetData());
  1048. if (start != string::npos)
  1049. {
  1050. #if defined(RVC_OS_WIN)
  1051. int dnsStart = line.find(": ");
  1052. if (dnsStart != string::npos)
  1053. {
  1054. string xDns = SP::Utility::ToTrim(line.substr(dnsStart + 1, line.length() - dnsStart - 1));
  1055. m_dns.Append(&xDns, 0, 1);
  1056. }
  1057. #else
  1058. string xDns = SP::Utility::ToTrim(line.substr(start + csDNSKeyword.GetLength() + 1, line.length() - start - csDNSKeyword.GetLength() - 1));
  1059. m_dns.Append(&xDns, 0, 1);
  1060. #endif
  1061. }
  1062. else
  1063. continue;
  1064. }
  1065. return;
  1066. }
  1067. void CHealthManagerFSM::QueryAndSendCPUInfo()
  1068. {
  1069. #if defined(RVC_OS_WIN)
  1070. if (!m_cpuInfo.IsNullOrEmpty())
  1071. {
  1072. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("have queried cpu info, no need to query again, current cpuinfo:%s", m_cpuInfo.GetData());
  1073. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutCPU")(m_cpuInfo.GetData());
  1074. return;
  1075. }
  1076. SYSTEM_INFO si;
  1077. GetSystemInfo(&si);
  1078. std::map<std::string, std::string> map_cpuInfo;
  1079. map_cpuInfo.insert(std::make_pair("dwProcessorType", CSimpleStringA::Format("%d", si.dwProcessorType)));
  1080. map_cpuInfo.insert(std::make_pair("wProcessorLevel", CSimpleStringA::Format("%d", si.wProcessorLevel)));
  1081. map_cpuInfo.insert(std::make_pair("wProcessorArchitecture", CSimpleStringA::Format("%d", si.wProcessorArchitecture)));
  1082. map_cpuInfo.insert(std::make_pair("wProcessorRevision", CSimpleStringA::Format("%d", si.wProcessorRevision)));
  1083. map_cpuInfo.insert(std::make_pair("dwNumberOfProcessors", CSimpleStringA::Format("%d", si.dwNumberOfProcessors)));
  1084. m_cpuInfo = generateJsonStr(map_cpuInfo).second.c_str();
  1085. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutCPU")(m_cpuInfo.GetData());
  1086. #else
  1087. ifstream cpuinfo("/proc/cpuinfo");
  1088. if (!cpuinfo.is_open()) {
  1089. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("opening /proc/cpuinfo error:%s", strerror(GetLastErrorRVC()));
  1090. return;
  1091. }
  1092. std::map<std::string, std::string> map_cpuInfo;
  1093. string line;
  1094. while (std::getline(cpuinfo, line)) {
  1095. auto elems = SP::Utility::Split(line, ':');
  1096. if (elems.size() > 1) {
  1097. map_cpuInfo[SP::Utility::ToTrim(elems[0])] = SP::Utility::ToTrim(elems[1]);
  1098. if (line.find("CPU revision") != string::npos)
  1099. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutCPU")(generateJsonStr(map_cpuInfo).second.c_str());
  1100. }
  1101. }
  1102. #endif //RVC_OS_WIN
  1103. return;
  1104. }
  1105. void CHealthManagerFSM::QueryAndSendDisplayInfo()
  1106. {
  1107. std::map<std::string, std::string> primaryInfo;
  1108. std::map<std::string, std::string> secondaryInfo;
  1109. std::map<std::string, std::string> displayInfo;
  1110. #if defined(RVC_OS_WIN)
  1111. DISPLAY_DEVICE devDevice;
  1112. devDevice.cb = sizeof(DISPLAY_DEVICE);
  1113. //获取系统中的所有显示设备
  1114. EnumDisplayDevices(NULL, ENUM_CURRENT_SETTINGS, &devDevice, 0);
  1115. bool bPrimary = false;
  1116. // 遍历显示设备列表
  1117. for (int i = 0; EnumDisplayDevices(NULL, i, &devDevice, 0) != 0; i++)
  1118. {
  1119. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("devDevice.StateFlags:%d", devDevice.StateFlags);
  1120. bPrimary = false;
  1121. //if connected
  1122. if (devDevice.StateFlags & DISPLAY_DEVICE_ACTIVE)
  1123. {
  1124. if (devDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
  1125. bPrimary = true;
  1126. // 获取显示设备的分辨率
  1127. DEVMODE devMode;
  1128. devMode.dmSize = sizeof(DEVMODE);
  1129. EnumDisplaySettings(devDevice.DeviceName, ENUM_CURRENT_SETTINGS, &devMode);
  1130. if (bPrimary)
  1131. {
  1132. primaryInfo["dmDeviceName"] = CSimpleStringA::Format("%s", devMode.dmDeviceName);
  1133. primaryInfo["dmPelsWidth"] = CSimpleStringA::Format("%d", devMode.dmPelsWidth);
  1134. primaryInfo["dmPelsHeight"] = CSimpleStringA::Format("%d", devMode.dmPelsHeight);
  1135. primaryInfo["dmDisplayOrientation"] = CSimpleStringA::Format("%d", devMode.dmDisplayOrientation);
  1136. primaryInfo["dmDisplayFixedOutput"] = CSimpleStringA::Format("%d", devMode.dmDisplayFixedOutput);
  1137. primaryInfo["dmPosition.x"] = CSimpleStringA::Format("%d", devMode.dmPosition.x);
  1138. primaryInfo["dmPosition.y"] = CSimpleStringA::Format("%d", devMode.dmPosition.y);
  1139. }
  1140. else
  1141. {
  1142. secondaryInfo["dmDeviceName"] = CSimpleStringA::Format("%s", devMode.dmDeviceName);
  1143. secondaryInfo["dmPelsWidth"] = CSimpleStringA::Format("%d", devMode.dmPelsWidth);
  1144. secondaryInfo["dmPelsHeight"] = CSimpleStringA::Format("%d", devMode.dmPelsHeight);
  1145. secondaryInfo["dmDisplayOrientation"] = CSimpleStringA::Format("%d", devMode.dmDisplayOrientation);
  1146. secondaryInfo["dmDisplayFixedOutput"] = CSimpleStringA::Format("%d", devMode.dmDisplayFixedOutput);
  1147. secondaryInfo["dmPosition.x"] = CSimpleStringA::Format("%d", devMode.dmPosition.x);
  1148. secondaryInfo["dmPosition.y"] = CSimpleStringA::Format("%d", devMode.dmPosition.y);
  1149. }
  1150. }
  1151. }
  1152. displayInfo["PrimaryText"] = generateJsonStr(primaryInfo).second.c_str();
  1153. displayInfo["SecondaryText"] = generateJsonStr(secondaryInfo).second.c_str();
  1154. #else
  1155. CSimpleStringA runInfoPath, csDNSKeyword;
  1156. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
  1157. if (eErr != Error_Succeed) {
  1158. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetPath runinfo error=%d.", eErr);
  1159. return;
  1160. }
  1161. runInfoPath = runInfoPath + SPLIT_SLASH_STR + "runcfg" + SPLIT_SLASH_STR + "monitor";
  1162. std::string sucContent, failedContent;
  1163. CSimpleStringA strCmd;
  1164. strCmd = CSimpleStringA::Format("xrandr | grep \" connected\" >%s", runInfoPath.GetData());
  1165. bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
  1166. if (!ret)
  1167. {
  1168. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("failedContent:%s", failedContent.c_str());
  1169. return;
  1170. }
  1171. ifstream is;
  1172. is.open(runInfoPath.GetData(), ios::binary);
  1173. if (!is.is_open())
  1174. {
  1175. DWORD dwErr = GetLastError();
  1176. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("open %s file failed. [%d]", runInfoPath.GetData(), dwErr);
  1177. return;
  1178. }
  1179. string line;
  1180. while (!is.eof()) {
  1181. getline(is, line);
  1182. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("line:%s", line.c_str());
  1183. if (line.find("connected") != string::npos)
  1184. {
  1185. if (line.find("primary") != string::npos)
  1186. displayInfo["PrimaryText"] = line;
  1187. else
  1188. displayInfo["SecondaryText"] = line;
  1189. }
  1190. }
  1191. #endif
  1192. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutDisplay")(generateJsonStr(displayInfo).second.c_str());
  1193. }
  1194. string CHealthManagerFSM::QueryHarddiskInfo()
  1195. {
  1196. CSimpleStringA csRunCfgPath("");
  1197. GetEntityBase()->GetFunction()->GetPath("RunCfg", csRunCfgPath);
  1198. csRunCfgPath = csRunCfgPath + SPLIT_SLASH_STR + "AccessAuthorization.ini";
  1199. char tmp[256];
  1200. memset(tmp, 0, 256);
  1201. inifile_read_str_s("system", "info", "", tmp, 255, csRunCfgPath);
  1202. auto elems = SP::Utility::Split(tmp, '|');
  1203. if (elems.size() > 2) {
  1204. return SP::Utility::ToTrim(elems[2]);
  1205. }
  1206. return "";
  1207. }
  1208. void CHealthManagerFSM::CheckIfPinPadOK()
  1209. {
  1210. //to check if PinPad is ok, wait for 5 seconds,then go on
  1211. //RVC.CardStore have no PinPad
  1212. if (m_sysInfo.strMachineType.Compare("RVC.CardStore", true) == 0)
  1213. {
  1214. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501A3")("RVC.CardStore have no PinPad");
  1215. return;
  1216. }
  1217. ULONGLONG ullWaitStart, ullWaitEnd;
  1218. ullWaitEnd = ullWaitStart = SP::Module::Comm::RVCGetTickCount();
  1219. PinPadService_ClientBase* pClient = new PinPadService_ClientBase(this->m_pEntity);
  1220. if (pClient != NULL)
  1221. {
  1222. ErrorCodeEnum eErrCode = pClient->Connect();
  1223. if (eErrCode == Error_Succeed)
  1224. {
  1225. do {
  1226. PinPadService_GetDevInfo_Req reqQ;
  1227. PinPadService_GetDevInfo_Ans ansQ;
  1228. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 1000);
  1229. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  1230. ullWaitEnd = SP::Module::Comm::RVCGetTickCount();
  1231. if (eErrCode == Error_DevNotAvailable)
  1232. {
  1233. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("pinpad open failed");
  1234. break;
  1235. }
  1236. else if (eErrCode == Error_Succeed)
  1237. break;
  1238. if (ullWaitEnd - ullWaitStart > m_maxWaitForPinPad)
  1239. break;
  1240. Sleep(500);
  1241. } while (true);
  1242. }
  1243. else
  1244. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("connect to pinpad failed.error code:%d", eErrCode);
  1245. }
  1246. else
  1247. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("new PinPadService_ClientBase failed.GetLastError:%d", GetLastErrorRVC());
  1248. m_ullWaitForPinPad = ullWaitEnd - ullWaitStart;
  1249. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501A3").setCostTime(m_ullWaitForPinPad)("finish (or time out) check PinPad");
  1250. return;
  1251. }
  1252. bool CHealthManagerFSM::CheckIfAccessAuthSuc()
  1253. {
  1254. if (m_iAccessAuth == VtmLoad_AccessAuth_Suc)
  1255. return true;
  1256. CSimpleStringA csTmpTS("");
  1257. GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTmpTS);
  1258. if (csTmpTS.Compare("A") == 0)
  1259. return true;
  1260. else
  1261. return false;
  1262. }