HealthManagerFSM.cpp 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  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. #else
  16. #include <unistd.h>
  17. #include <fcntl.h>
  18. #include <errno.h>
  19. #endif //RVC_OS_WIN
  20. #include "mod_healthmanager.h"
  21. #include "publicFunExport.h"
  22. using namespace std;
  23. const int MAX_AYSNC_TIMEOUT = 60000;
  24. const int MAX_IGNORE_TIMEOUT = 100;
  25. //TODO: CrossPlaform [Gifur@2025730]
  26. unsigned long long GetLastErrorRVC() {
  27. #if defined(RVC_OS_WIN)
  28. return GetLastError();
  29. #else
  30. return errno;
  31. #endif //RVC_OS_WIN
  32. }
  33. enum EntityOP
  34. {
  35. OP_STOP_ENTITY,
  36. OP_START_ENTITY,
  37. OP_PAUSE_ENTITY,
  38. OP_TERMINATE_ENTITY,
  39. OP_CONTINUE_ENTITY,
  40. };
  41. ErrorCodeEnum CHealthManagerFSM::Initial()
  42. {
  43. m_netList.Init(0);
  44. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  45. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  46. CSmartPointer<IAsynWaitSp> spWait;
  47. ErrorCodeEnum err;
  48. GetEntityBase()->GetFunction()->GetSystemStaticInfo(m_sysInfo);
  49. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("machinetype[%s],terminalID[%s]", (LPCTSTR)m_sysInfo.strMachineType, (LPCTSTR)m_sysInfo.strTerminalID);
  50. CSmartPointer<IConfigInfo> spConfigCen;
  51. GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen);
  52. spConfigCen->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "WKUpdatePeriod", m_wkUpdatePeriod);
  53. if (m_wkUpdatePeriod <= 0 || m_wkUpdatePeriod > 365)
  54. m_wkUpdatePeriod = 30;//default
  55. spConfigCen->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "DoNotUpdateWKDaily", m_iDoNotUpdateWKDaily);
  56. spConfigCen->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "MaxWaitForPinPad", m_maxWaitForPinPad);
  57. if (m_maxWaitForPinPad <= 0 || m_maxWaitForPinPad > 5000)
  58. m_maxWaitForPinPad = 5000;//default
  59. CSimpleStringA csTmpTS("");
  60. GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTmpTS);
  61. if (csTmpTS.Compare("N") != 0)
  62. GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "X");
  63. SP::Module::Net::GetINETMacAddresses(m_netList);
  64. return Error_Succeed;
  65. }
  66. ErrorCodeEnum CHealthManagerFSM::OnInit(void)
  67. {
  68. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Complied at: %s %s", __DATE__, __TIME__);
  69. return Initial();
  70. }
  71. ErrorCodeEnum CHealthManagerFSM::OnExit(void)
  72. {
  73. return Error_Succeed;
  74. }
  75. void CHealthManagerFSM::s0_on_entry(void)
  76. {
  77. LOG_FUNCTION();
  78. m_fsmState = HM_FSM_INIT;
  79. m_ullElapseFromOSStart = SP::Module::Comm::RVCGetTickCount();
  80. m_elapseTimeFromOSStart = m_ullElapseFromOSStart / 1000;
  81. CSimpleStringA xMsg = CSimpleStringA::Format("{\"Decripstion\":\"Entity start\",\"version\":\"%s\",\"elapseTime\":\"%d\"}", m_sysInfo.InstallVersion.ToString().GetData(), m_elapseTimeFromOSStart);
  82. LogWarn(Severity_Low, Error_Unexpect, HealthManager_UserErrorCode_Enter_SafeLoad_State, xMsg.GetData());
  83. FSMEvent* pEvt = new FSMEvent(USER_EVT_WAIT_DEAMON_FINISHED);
  84. pEvt->param1 = 0;
  85. PostEventFIFO(pEvt);
  86. }
  87. void CHealthManagerFSM::s0_on_exit(void)
  88. {
  89. }
  90. unsigned int CHealthManagerFSM::s0_on_event(FSMEvent* pEvt)
  91. {
  92. int ret = 0;
  93. switch(pEvt->iEvt)
  94. {
  95. case USER_EVT_WAIT_DEAMON_FINISHED:
  96. ret = pEvt->param1;
  97. pEvt->SetHandled();
  98. break;
  99. default:
  100. break;
  101. }
  102. return ret;
  103. }
  104. //Idle(Operating finished)
  105. void CHealthManagerFSM::s4_on_entry()
  106. {
  107. m_fsmState = HM_FSM_STATE_IDLE;
  108. }
  109. void CHealthManagerFSM::s4_on_exit()
  110. {
  111. LOG_FUNCTION();
  112. }
  113. unsigned int CHealthManagerFSM::s4_on_event(FSMEvent* pEvt)
  114. {
  115. LOG_FUNCTION();
  116. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("s4 event %d,%d",pEvt->iEvt,pEvt->param1);
  117. switch(pEvt->iEvt)
  118. {
  119. case USER_EVT_ACCESSAUTH_FINISHED:
  120. {
  121. pEvt->SetHandled();
  122. CSimpleStringA csTermStage;
  123. ErrorCodeEnum eErrCode;
  124. eErrCode = GetEntityBase()->GetFunction()->GetSysVar("TerminalStage",csTermStage);
  125. DbgWithLink(LOG_LEVEL_DEBUG,LOG_TYPE_SYSTEM)("after accessauth to get termstage %s",(LPCTSTR)csTermStage);
  126. //oilyang@20220614 添加密钥更新逻辑
  127. if (csTermStage[0] == 'A')
  128. {
  129. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("after auth suc,to call WKUpdatePeriodTask");
  130. WKUpdatePeriodTask* pTask = new WKUpdatePeriodTask(this);
  131. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  132. }
  133. LogTermInfoTask* task = new LogTermInfoTask(this);
  134. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  135. if (m_iAccessAuth != VtmLoad_AccessAuth_Suc)
  136. PostProcessAfterUpgrade();
  137. }
  138. break;
  139. case USER_EVT_MAITAIN:
  140. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("to maintain...");
  141. m_stateBeforeMaintain = m_fsmState;
  142. pEvt->SetHandled();
  143. break;
  144. case USER_EVT_ENTER_CUSTOMER_MANAGER:
  145. pEvt->SetHandled();
  146. break;
  147. case USER_EVT_VTMLOADER_FINISHED:
  148. {
  149. pEvt->SetHandled();
  150. if (pEvt->param1 == 1)
  151. {
  152. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501V1").setResultCode("RTA510E")("VtmLoader load SIPphone entity failed, to Set TerminalStage M.");
  153. SetVtmLoadResult(VtmLoad_MediaLoadFail);
  154. return pEvt->param1;
  155. }
  156. else if (pEvt->param1 == 2)
  157. {
  158. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501V1").setResultCode("RTA510F")("VtmLoader load SYNCSTART(boot cfg = 2) entity failed, to Set TerminalStage C.");
  159. SetVtmLoadResult(VtmLoad_OtherSyncEntityLoadFail);
  160. return pEvt->param1;
  161. }
  162. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501A1")("VtmLoader load entitys ok.");
  163. if (m_iAccessAuth == VtmLoad_AccessAuth_Init)
  164. {
  165. WaitToCallAccessAuthTask* pTask = new WaitToCallAccessAuthTask(this);
  166. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  167. }
  168. }
  169. break;
  170. default:
  171. break;
  172. }
  173. return 0;
  174. }
  175. //Fault
  176. void CHealthManagerFSM::s5_on_entry()
  177. {
  178. LOG_FUNCTION();
  179. LogTermInfoTask* task = new LogTermInfoTask(this);
  180. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  181. m_fsmState = HM_FSM_STATE_FAULT;
  182. PostProcessAfterUpgrade();
  183. }
  184. void CHealthManagerFSM::s5_on_exit()
  185. {
  186. LOG_FUNCTION();
  187. }
  188. unsigned int CHealthManagerFSM::s5_on_event(FSMEvent* pEvt)
  189. {
  190. LOG_FUNCTION();
  191. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("s5(Fault) event %d,%d",pEvt->iEvt,pEvt->param1);
  192. switch(pEvt->iEvt)
  193. {
  194. case USER_EVT_MAITAIN:
  195. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("to maintain...");
  196. m_stateBeforeMaintain = m_fsmState;
  197. pEvt->SetHandled();
  198. break;
  199. case USER_EVT_ENTER_CUSTOMER_MANAGER:
  200. pEvt->SetHandled();
  201. break;
  202. case USER_EVT_ACCESSAUTH_FINISHED:
  203. pEvt->SetHandled();
  204. if (pEvt->param1 == 1)
  205. {
  206. return 1;
  207. }
  208. break;
  209. default:
  210. break;
  211. }
  212. return 0;
  213. }
  214. //Maintaining
  215. void CHealthManagerFSM::s6_on_entry()
  216. {
  217. LOG_FUNCTION();
  218. m_preFsmState = m_fsmState;
  219. m_fsmState = HM_FSM_STATE_MAINTAINING;
  220. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  221. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  222. if (pFuncPrivilege == NULL)
  223. {
  224. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("display screen NoPrivilege");
  225. return;
  226. }
  227. ErrorCodeEnum eErr = pFuncPrivilege->DisplayBlueScreen("暂停服务");
  228. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("display blue screen %d",eErr);
  229. }
  230. void CHealthManagerFSM::s6_on_exit()
  231. {
  232. LOG_FUNCTION();
  233. }
  234. unsigned int CHealthManagerFSM::s6_on_event(FSMEvent* pEvt)
  235. {
  236. LOG_FUNCTION();
  237. int ret = 0;
  238. switch(pEvt->iEvt)
  239. {
  240. case USER_EVT_MAITAIN_FINISHED:
  241. pEvt->SetHandled();
  242. {
  243. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  244. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  245. if (pFuncPrivilege == NULL)
  246. {
  247. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("un-display screen NoPrivilege");
  248. return 1;
  249. }
  250. ErrorCodeEnum eErr = pFuncPrivilege->UndisplayBlueScreen();
  251. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("un-display blue screen %d",eErr);
  252. if (m_stateBeforeMaintain == HM_FSM_STATE_IDLE)
  253. {
  254. }
  255. ret = m_preFsmState;
  256. }
  257. break;
  258. case USER_EVT_ENTER_CUSTOMER_MANAGER:
  259. pEvt->SetHandled();
  260. break;
  261. default:
  262. break;
  263. }
  264. return ret;
  265. }
  266. //In Customer Manager System
  267. void CHealthManagerFSM::s11_on_entry()
  268. {
  269. LOG_FUNCTION();
  270. m_preFsmState = m_fsmState;
  271. m_fsmState = HM_FSM_STATE_CMS;
  272. }
  273. void CHealthManagerFSM::s11_on_exit()
  274. {
  275. LOG_FUNCTION();
  276. }
  277. unsigned int CHealthManagerFSM::s11_on_event(FSMEvent* pEvt)
  278. {
  279. LOG_FUNCTION();
  280. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("s11(In CMS) event %d",pEvt->iEvt);
  281. int ret = 0;
  282. switch (pEvt->iEvt)
  283. {
  284. case USER_EVT_MAITAIN:
  285. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("to maintain...");
  286. m_stateBeforeMaintain = m_fsmState;
  287. pEvt->SetHandled();
  288. break;
  289. case USER_EVT_SWITCH_BACK_TO_RVC:
  290. pEvt->SetHandled();
  291. ret = m_preFsmState;
  292. break;
  293. default:
  294. break;
  295. }
  296. return ret;
  297. }
  298. //0:auth suc or have already authed;1:auth failed;
  299. int CHealthManagerFSM::AccessAuthDoWork()
  300. {
  301. LOG_FUNCTION();
  302. CheckIfPinPadOK();
  303. m_bInAccessAuthDoWork = true;
  304. CSimpleStringA csTermStage("");
  305. ErrorCodeEnum eErrCode = GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTermStage);
  306. if (eErrCode == Error_Succeed)
  307. {
  308. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("before accessauth get TerminalStage %s", csTermStage.GetData());
  309. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  310. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  311. CEntityRunInfo acInfo;
  312. eErrCode = pFunc->GetEntityRunInfo("AccessAuthorization", acInfo);
  313. if (eErrCode == Error_Succeed)
  314. {
  315. switch (acInfo.eState)
  316. {
  317. case EntityState_NoStart:
  318. {
  319. CSmartPointer<IAsynWaitSp> spWaitAC;
  320. eErrCode = pFuncPrivilege->StartEntity("AccessAuthorization", NULL, spWaitAC);
  321. eErrCode = spWaitAC->WaitAnswer(MAX_AYSNC_TIMEOUT);
  322. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start accessauth %d.", eErrCode);
  323. }
  324. break;
  325. case EntityState_Idle:
  326. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("AccessAuth state idle.");
  327. break;
  328. default:
  329. break;
  330. }
  331. if (m_pACClient == NULL)
  332. {
  333. m_pACClient = new AccessAuthService_ClientBase(this->GetEntityBase());
  334. eErrCode = m_pACClient->Connect();
  335. if (eErrCode != Error_Succeed) {
  336. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("accessauth connected failed:%s", SpStrError(eErrCode));
  337. m_pACClient->SafeDelete();
  338. m_pACClient = NULL;
  339. m_bInAccessAuthDoWork = false;
  340. return 1;
  341. }
  342. else {
  343. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("accessauth connected.");
  344. }
  345. }
  346. }
  347. else
  348. {
  349. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("Get AccessAuth RunInfo failed(%s).", SpStrError(eErrCode));
  350. m_bInAccessAuthDoWork = false;
  351. return 1;
  352. }
  353. if (m_pACClient != NULL)
  354. {
  355. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to call accessauth regist");
  356. CSystemRunInfo sysRunInfo;
  357. if (GetEntityBase()->GetFunction()->GetSystemRunInfo(sysRunInfo) != Error_Succeed || sysRunInfo.eAppBootState == AppBootState_StartEntity)
  358. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->RefreshAppBootState(AppBootState_CallAccessAuth);
  359. m_ullAuthStart = SP::Module::Comm::RVCGetTickCount();
  360. eErrCode = (*m_pACClient)(EntityResource::getLink().upgradeLink())->Regist();
  361. m_bHasAuthEver = true;
  362. if (eErrCode == Error_Succeed)
  363. {
  364. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501A4")("call AccessAuth's Regist return succeed");
  365. do {
  366. if (m_iAccessAuth != VtmLoad_AccessAuth_Init)
  367. break;
  368. Sleep(1000);
  369. } while (1);//wait for accessauth send result
  370. m_bFirstAccessAuth = false;
  371. m_bInAccessAuthDoWork = false;
  372. return 0;
  373. }
  374. else
  375. {
  376. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501A4").setResultCode("RTA5102")("call accessauth Regist failed:%s", SpStrError(eErrCode));
  377. m_bInAccessAuthDoWork = false;
  378. return 1;
  379. }
  380. }
  381. else
  382. {
  383. m_bInAccessAuthDoWork = false;
  384. return 1;
  385. }
  386. }
  387. else {
  388. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("Get TerminalStage failed(%s).", SpStrError(eErrCode));
  389. }
  390. m_bInAccessAuthDoWork = false;
  391. return 1;
  392. }
  393. void CHealthManagerFSM::SetVtmLoadResult(int bResult)
  394. {
  395. m_iAccessAuth = bResult;
  396. ErrorCodeEnum eErrCode;
  397. if (bResult == VtmLoad_AccessAuth_Suc)
  398. {
  399. eErrCode = GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "A");
  400. m_ullAccessAuthCost = SP::Module::Comm::RVCGetTickCount() - m_ullAuthStart;
  401. }
  402. else if (bResult == VtmLoad_AccessAuth_servFail) //准入服务端返回失败
  403. {
  404. eErrCode = GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "S");
  405. m_ullAccessAuthCost = SP::Module::Comm::RVCGetTickCount() - m_ullAuthStart;
  406. }
  407. else if (bResult == VtmLoad_MediaLoadFail) //音视频校验不通过
  408. {
  409. eErrCode = GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "M");
  410. }
  411. else //其他失败
  412. {
  413. eErrCode = GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "C");
  414. if (bResult != VtmLoad_OtherSyncEntityLoadFail)//if haven't call Regist(), no need to calulate the AccessAuth cost
  415. m_ullAccessAuthCost = SP::Module::Comm::RVCGetTickCount() - m_ullAuthStart;
  416. }
  417. if (eErrCode != Error_Succeed)
  418. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("set TerminalStage %d,failed:%s", bResult, SpStrError(eErrCode));
  419. else
  420. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("set TerminalStage %d", bResult);
  421. }
  422. void CHealthManagerFSM::ToReAccessAuth(bool bEver)
  423. {
  424. Sleep(1500);//for function "AccessAuthDoWork" to quit while
  425. if (m_bFirstAccessAuth)
  426. return;
  427. ToCallAccessAuthDoWork();
  428. }
  429. ErrorCodeEnum CHealthManagerFSM::AsyncStartEntity(const char *entity_name, const char *cmdline, void *pData)
  430. {
  431. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  432. ErrorCodeEnum errCode;
  433. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  434. if (pFuncPrivilege != NULL) {
  435. CSmartPointer<IAsynWaitSp> spWait;
  436. errCode = pFuncPrivilege->StartEntity(entity_name, cmdline, spWait);
  437. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("start entity %s,errCode:%s", entity_name, SpStrError(errCode));
  438. if (errCode == Error_Succeed) {
  439. callback_entry *entry = new callback_entry();
  440. entry->pRawData = pData;
  441. entry->EntityName = entity_name;
  442. entry->ErrorResult = Error_Unexpect;
  443. entry->op = OP_START_ENTITY;
  444. if (spWait != NULL)
  445. spWait->SetCallback(this, entry);
  446. }
  447. return errCode;
  448. } else {
  449. return Error_NoPrivilege;
  450. }
  451. }
  452. ErrorCodeEnum CHealthManagerFSM::AsyncStopEntity(const char *entity_name, void *pData)
  453. {
  454. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  455. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  456. if (pFuncPrivilege != NULL) {
  457. CSmartPointer<IAsynWaitSp> spWait;
  458. ErrorCodeEnum Error = pFuncPrivilege->StopEntity(entity_name, spWait);
  459. if (Error == Error_Succeed) {
  460. callback_entry *entry = new callback_entry();
  461. entry->pRawData = pData;
  462. entry->EntityName = entity_name;
  463. entry->ErrorResult = Error_Unexpect;
  464. entry->op = OP_STOP_ENTITY;
  465. if (spWait != NULL)
  466. spWait->SetCallback(this, entry);
  467. }
  468. return Error;
  469. } else {
  470. return Error_NoPrivilege;
  471. }
  472. }
  473. ErrorCodeEnum CHealthManagerFSM::AsyncPauseEntity(const char *entity_name, void *pData)
  474. {
  475. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  476. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  477. if (pFuncPrivilege != NULL) {
  478. CSmartPointer<IAsynWaitSp> spWait;
  479. ErrorCodeEnum Error = pFuncPrivilege->PauseEntity(entity_name, spWait);
  480. if (Error == Error_Succeed) {
  481. callback_entry *entry = new callback_entry();
  482. entry->pRawData = pData;
  483. entry->EntityName = entity_name;
  484. entry->ErrorResult = Error_Unexpect;
  485. entry->op = OP_PAUSE_ENTITY;
  486. if (spWait != NULL)
  487. spWait->SetCallback(this, entry);
  488. }
  489. return Error;
  490. } else {
  491. return Error_NoPrivilege;
  492. }
  493. }
  494. ErrorCodeEnum CHealthManagerFSM::AsyncContinueEntity(const char *entity_name, void *pData)
  495. {
  496. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  497. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  498. if (pFuncPrivilege != NULL) {
  499. CSmartPointer<IAsynWaitSp> spWait;
  500. ErrorCodeEnum Error = pFuncPrivilege->ContinueEntity(entity_name, spWait);
  501. if (Error == Error_Succeed) {
  502. callback_entry *entry = new callback_entry();
  503. entry->pRawData = pData;
  504. entry->EntityName = entity_name;
  505. entry->ErrorResult = Error_Unexpect;
  506. entry->op = OP_CONTINUE_ENTITY;
  507. if (spWait != NULL)
  508. spWait->SetCallback(this, entry);
  509. }
  510. return Error;
  511. } else {
  512. return Error_NoPrivilege;
  513. }
  514. }
  515. ErrorCodeEnum CHealthManagerFSM::AsyncTerminateEntity(const char *entity_name, void *pData)
  516. {
  517. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  518. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  519. if (pFuncPrivilege != NULL) {
  520. CSmartPointer<IAsynWaitSp> spWait;
  521. ErrorCodeEnum Error = pFuncPrivilege->TerminateEntity(entity_name, spWait);
  522. if (Error == Error_Succeed) {
  523. callback_entry *entry = new callback_entry();
  524. entry->pRawData = pData;
  525. entry->EntityName = entity_name;
  526. entry->ErrorResult = Error_Unexpect;
  527. entry->op = OP_TERMINATE_ENTITY;
  528. if (spWait != NULL)
  529. spWait->SetCallback(this, entry);
  530. }
  531. return Error;
  532. } else {
  533. return Error_NoPrivilege;
  534. }
  535. }
  536. void CHealthManagerFSM::OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp)
  537. {
  538. }
  539. int CHealthManagerFSM::QuitFrameworkAndSaveInfo(RebootTriggerEnum eTrigger, RebootWayEnum eWay)
  540. {
  541. m_bRebooting = true;
  542. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  543. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  544. if (pFuncPrivilege == NULL) {
  545. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("has no privilege");
  546. return (int)(Error_NoPrivilege);
  547. }
  548. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("quit framework and info %d,%d.", eTrigger, eWay);
  549. const auto result = pFuncPrivilege->Reboot(eTrigger, eWay);
  550. return (int)result;
  551. }
  552. void CHealthManagerFSM::PostProcessAfterUpgrade()
  553. {
  554. LOG_FUNCTION();
  555. if (IfInUpgradeProcess())
  556. {
  557. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("exist upgrade flag file,to decide if restart framework.");
  558. //存在升级后的启动文件
  559. CSmartPointer<IConfigInfo> spConfigRun;
  560. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfigRun);
  561. if (eErr == Error_Succeed)
  562. {
  563. int restartOSTime = 0;
  564. spConfigRun->ReadConfigValueInt("Run", "UpgradeRestartOSTimes", restartOSTime);
  565. if(restartOSTime==1){
  566. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("升级切换已重启过系统");
  567. //重启过的系统过的升级,在重试一定次数后等guardian 10分钟回退
  568. int xTimes = 0;
  569. spConfigRun->ReadConfigValueInt("Run", "UpgradeRestartTimes", xTimes);
  570. if (xTimes < 3)
  571. {
  572. xTimes++;
  573. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("写入: UpgradeRestartTimes:%d", xTimes);
  574. spConfigRun->WriteConfigValueInt("Run", "UpgradeRestartTimes", xTimes);
  575. QuitFrameworkAndSaveInfo(RebootTrigger_Resource, RebootWay_Framework);
  576. }
  577. }else{
  578. //未重启过操作系统
  579. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("升级切换未重启过系统");
  580. int xTimes = 0;
  581. spConfigRun->ReadConfigValueInt("Run", "UpgradeRestartTimes", xTimes);
  582. if (xTimes < 3)
  583. {
  584. xTimes++;
  585. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("写入: UpgradeRestartTimes:%d", xTimes);
  586. spConfigRun->WriteConfigValueInt("Run", "UpgradeRestartTimes", xTimes);
  587. //oilyang@20211130 change from 3 to 2
  588. if (xTimes == 2)
  589. {
  590. //重启操作系统前把重启框架次数重置,重启OS次数置为1
  591. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("准备尝试重启系统后再切换升级");
  592. spConfigRun->WriteConfigValueInt("Run", "UpgradeRestartTimes", 0);
  593. spConfigRun->WriteConfigValueInt("Run", "UpgradeRestartOSTimes", 1);
  594. Sleep(2000);
  595. QuitFrameworkAndSaveInfo(RebootTrigger_Resource, RebootWay_OS);
  596. }
  597. else
  598. QuitFrameworkAndSaveInfo(RebootTrigger_Resource, RebootWay_Framework);
  599. }
  600. }
  601. }
  602. }
  603. }
  604. CSimpleStringA CHealthManagerFSM::GetOsVersion()
  605. {
  606. #if defined(RVC_OS_WIN)
  607. CSimpleStringA runInfoPath;
  608. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
  609. if (eErr != Error_Succeed) {
  610. DbgWithLink(LOG_LEVEL_ERROR,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("GetPath runinfo error=%s.", SpStrError(eErr));
  611. return "";
  612. }
  613. runInfoPath += "\\runcfg\\osverion";
  614. ifstream is;
  615. is.open(runInfoPath.GetData(), ios::binary);
  616. if (!is.is_open())
  617. {
  618. DWORD dwErr = GetLastError();
  619. DbgWithLink(LOG_LEVEL_ERROR,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("open runcfg\\osverion file failed. [%d]", dwErr);
  620. return "";
  621. }
  622. string line;
  623. while(!is.eof()){
  624. getline(is, line);
  625. int start = line.find("版本");
  626. if (start != string::npos)
  627. //return CSimpleStringA(line.substr(start + 5, line.length() - start - 7).c_str());
  628. return CSimpleStringA(line.c_str());
  629. else
  630. continue;
  631. }
  632. return "";
  633. #else
  634. std::map<std::string, std::string> osInfo;
  635. const char filePath[] = "/etc/os-version";
  636. char tmp[33];
  637. memset(tmp, 0, 33);
  638. inifile_read_str_s("Version", "SystemName", "unknown", tmp, 32, filePath);
  639. osInfo["SystemName"] = tmp;
  640. memset(tmp, 0, 33);
  641. inifile_read_str_s("Version", "ProductType", "unknown", tmp, 32, filePath);
  642. osInfo["ProductType"] = tmp;
  643. memset(tmp, 0, 33);
  644. inifile_read_str_s("Version", "MajorVersion", "unknown", tmp, 32, filePath);
  645. osInfo["MajorVersion"] = tmp;
  646. memset(tmp, 0, 33);
  647. inifile_read_str_s("Version", "MinorVersion", "unknown", tmp, 32, filePath);
  648. osInfo["MinorVersion"] = tmp;
  649. memset(tmp, 0, 33);
  650. inifile_read_str_s("Version", "OsBuild", "unknown", tmp, 32, filePath);
  651. osInfo["OsBuild"] = tmp;
  652. return generateJsonStr(osInfo).second.c_str();
  653. #endif
  654. }
  655. DWORD GetDualTime(SYSTEMTIME& t1, SYSTEMTIME& t2)
  656. {
  657. //assume t2 > t1...
  658. //oiltest for simple
  659. int s1, s2;
  660. s1 = (t1.wMinute * 60 + t1.wSecond) * 1000 + t1.wMilliseconds;
  661. s2 = (t2.wMinute * 60 + t2.wSecond) * 1000 + t2.wMilliseconds;
  662. return s2 - s1;
  663. }
  664. void CHealthManagerFSM::ToLogWarnTermAboutInfo()
  665. {
  666. LOG_FUNCTION();
  667. bool bTmpEtyNewStart = m_bEntityNewStart;
  668. if (m_bEntityNewStart)
  669. {
  670. SYSTEMTIME shellStartTime;
  671. m_ullTotalCost = 0;
  672. m_bEntityNewStart = false;
  673. CAutoArray<CSimpleStringA> strEntityNames;
  674. CAutoArray<int> strEntityIdx;
  675. CAutoArray<CEntityStartInfo> Infos;
  676. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetAllEntityStartInfo(strEntityNames, strEntityIdx, Infos);
  677. for (int i = 0; i < Infos.GetCount(); ++i)
  678. {
  679. if (strEntityIdx[i] == 0)
  680. {
  681. shellStartTime = Infos[i].startTime;
  682. ULONGLONG dwElapseNow = SP::Module::Comm::RVCGetTickCount();
  683. m_ullTotalCost = dwElapseNow - m_ullElapseFromOSStart;
  684. LogWarn(Severity_Low, Error_Debug, LOG_TRACE_ENTITY_START_TIME,
  685. SP::Module::Util::generateConsumeTimeJson("total", SP::Module::Util::formatTime(shellStartTime).c_str(), m_ullTotalCost).GetData());
  686. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("EntityStartCost")(SP::Module::Util::generateConsumeTimeJson("total", SP::Module::Util::formatTime(shellStartTime).c_str(), m_ullTotalCost).GetData());
  687. //break;
  688. }
  689. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s,%d", strEntityNames[i].GetData(), GetDualTime(Infos[i].startTime, Infos[i].startEndTime));
  690. if (strEntityNames[i].Compare("SIPPhone") == 0)
  691. m_ullSIPPhoneCost = GetDualTime(Infos[i].startTime, Infos[i].startEndTime);
  692. else if (strEntityNames[i].Compare("TokenKeeper") == 0)
  693. m_ullTokenKeeperCost = GetDualTime(Infos[i].startTime, Infos[i].startEndTime);
  694. }
  695. std::map<std::string, std::string> termStartInfo;
  696. termStartInfo["SIPPhoneCost"] = CSimpleStringA::Format("%d", m_ullSIPPhoneCost);
  697. termStartInfo["TokenKeeperCost"] = CSimpleStringA::Format("%d", m_ullTokenKeeperCost);
  698. termStartInfo["WaitForPinPadCost"] = CSimpleStringA::Format("%d", m_ullWaitForPinPad);
  699. termStartInfo["TotalCost"] = CSimpleStringA::Format("%d", m_ullTotalCost);
  700. termStartInfo["AccessAuthCost"] = CSimpleStringA::Format("%d", m_ullAccessAuthCost);
  701. termStartInfo["AccessAuthResult"] = CSimpleStringA::Format("%d", m_iAccessAuth);
  702. termStartInfo["OSElapseTime"] = CSimpleStringA::Format("%d", m_elapseTimeFromOSStart);
  703. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("TerminalStartCost")("%s", generateJsonStr(termStartInfo).second.c_str());
  704. LogWarn(Severity_Low, Error_Debug, HealthManager_UserErrorCode_TerminalAppLoadInfo, generateJsonStr(termStartInfo).second.c_str());
  705. }
  706. QueryAndSaveDNS();
  707. QueryAndSendCPUInfo();
  708. QueryAndSendDisplayInfo();
  709. CSimpleStringA csOSVerion(""), csWarnMsg("");
  710. std::map<std::string, std::string> termInfo;
  711. termInfo["version"] = m_sysInfo.InstallVersion.ToString();
  712. if (m_iAccessAuth == VtmLoad_AccessAuth_Suc)
  713. {
  714. termInfo["AccessAuth"] = "T";
  715. }
  716. else
  717. {
  718. termInfo["AccessAuth"] = "F";
  719. CSimpleStringA tmpAuthErrMsg("");
  720. if (GetEntityBase()->GetFunction()->GetSysVar("AuthErrMsg", tmpAuthErrMsg) == Error_Succeed)
  721. termInfo["AuthErrMsg"] = tmpAuthErrMsg;
  722. }
  723. csOSVerion = GetOsVersion();
  724. if (!csOSVerion.IsNullOrEmpty())
  725. termInfo["OSVersion"] = csOSVerion;
  726. termInfo["Harddisk"] = QueryHarddiskInfo();
  727. #if defined(RVC_OS_WIN)
  728. termInfo["OSType"] = "Windows";
  729. termInfo["AsiaInfo"] = CheckProcessExistByName("NTRtScan.exe") ? "Y" : "N";
  730. termInfo["UniAccess"] = CheckProcessExistByName("UniAccessAgent.exe") ? "Y" : "N";
  731. termInfo["RuiYan"] = CheckProcessExistByName("RuiYan.exe") ? "Y" : "N";
  732. termInfo["Symantec"] = CheckProcessExistByName("SavUI.exe") ? "Y" : "N";
  733. #else
  734. termInfo["OSType"] = "UOS";
  735. #endif
  736. CSmartPointer<IConfigInfo> spConfigRun;
  737. GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfigRun);
  738. //CAutoArray<SP::Module::Net::NetworkAdapterItem> netList;
  739. if (m_netList.GetCount() == 0)
  740. SP::Module::Net::GetINETMacAddresses(m_netList);
  741. CSimpleStringA csMac(""), csIP(""), csDNS("");
  742. for (int i = 0; i < m_netList.GetCount(); i++) {
  743. if (!csMac.IsNullOrEmpty()) {
  744. csMac += ";";
  745. }
  746. csMac += m_netList[i].mac.c_str();
  747. if (!csIP.IsNullOrEmpty()) {
  748. csIP += ";";
  749. }
  750. csIP += m_netList[i].ip.c_str();
  751. }
  752. for (int i = 0; i < m_dns.GetCount(); i++) {
  753. if (!csDNS.IsNullOrEmpty()) {
  754. csDNS += ";";
  755. }
  756. csDNS += m_dns[i].c_str();
  757. }
  758. termInfo["MACs"] = csMac;
  759. termInfo["IPs"] = csIP;
  760. termInfo["DNSs"] = csDNS;
  761. char xOSTime[64] = {0};
  762. char elapseTime[64] = {0};//使用机器启动时间秒数
  763. ULONGLONG dwElapse = SP::Module::Comm::RVCGetTickCount();
  764. DWORD elapseTimeTemp = dwElapse / 1000;
  765. //TODO: CrossPlaform [Gifur@2025729]
  766. #if defined(RVC_OS_WIN)
  767. termInfo["OSTime"] = itoa(m_elapseTimeFromOSStart, xOSTime, 10);
  768. termInfo["elapseTime"] = itoa(elapseTimeTemp, elapseTime, 10);
  769. #else
  770. termInfo["OSTime"] = _itoa(m_elapseTimeFromOSStart, xOSTime, 10);
  771. termInfo["elapseTime"] = _itoa(elapseTimeTemp, elapseTime, 10);
  772. #endif
  773. CSimpleStringA csRunPath("");
  774. GetEntityBase()->GetFunction()->GetPath("Run", csRunPath);
  775. termInfo["AppPath"] = csRunPath;
  776. std::pair<bool, std::string> strResult;
  777. strResult = generateJsonStr(termInfo);
  778. spConfigRun->ReadConfigValue("Run", "WarnMsg", csWarnMsg);
  779. //oilyang@20210323 discard the following rule of throwing LogWarn.Always throw LogWarn
  780. //oilyang@20201201 log warn every time if content of msg has changed
  781. if (bTmpEtyNewStart)
  782. {
  783. LogWarn(Severity_Low, Error_Unexpect, LOG_WARN_HEALTH_UPLOAD_INFO_ABOUT_TERM, strResult.second.c_str());
  784. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutTerm")(strResult.second.c_str());
  785. }
  786. else
  787. {
  788. LogWarn(Severity_Low, Error_Unexpect, LOG_WARN_HEALTH_UPLOAD_INFO_ABOUT_TERM, strResult.second.c_str());
  789. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutTerm")(strResult.second.c_str());
  790. }
  791. }
  792. void CHealthManagerFSM::ToCallAccessAuthDoWork()
  793. {
  794. if (!m_bInAccessAuthDoWork)
  795. {
  796. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("To Call AccessAuthDoWork");
  797. AccessAuthTask* pTask = new AccessAuthTask(this);
  798. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  799. }
  800. }
  801. bool CHealthManagerFSM::IfInUpgradeProcess()
  802. {
  803. CSimpleStringA csRunCfgPath(""), csFileName("");
  804. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("RunCfg", csRunCfgPath);
  805. csFileName = csRunCfgPath + SPLIT_SLASH_STR + "starttime.dat";
  806. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("csFileName:%s", csFileName.GetData());
  807. //TODO: CrossPlaform [Gifur@2025730]
  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. }