HealthManagerFSM.cpp 46 KB

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