HealthManagerFSM.cpp 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  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. termStartInfo["OSElapseTime"] = CSimpleStringA::Format("%d", m_elapseTimeFromOSStart);
  730. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("TerminalStartCost")("%s", generateJsonStr(termStartInfo).second.c_str());
  731. LogWarn(Severity_Low, Error_Debug, HealthManager_UserErrorCode_TerminalAppLoadInfo, generateJsonStr(termStartInfo).second.c_str());
  732. }
  733. QueryAndSaveDNS();
  734. QueryAndSendCPUInfo();
  735. QueryAndSendDisplayInfo();
  736. CSimpleStringA csOSVerion(""), csWarnMsg("");
  737. std::map<std::string, std::string> termInfo;
  738. termInfo["version"] = m_sysInfo.InstallVersion.ToString();
  739. if (m_iAccessAuth == VtmLoad_AccessAuth_Suc)
  740. {
  741. termInfo["AccessAuth"] = "T";
  742. }
  743. else
  744. {
  745. termInfo["AccessAuth"] = "F";
  746. CSimpleStringA tmpAuthErrMsg("");
  747. if (GetEntityBase()->GetFunction()->GetSysVar("AuthErrMsg", tmpAuthErrMsg) == Error_Succeed)
  748. termInfo["AuthErrMsg"] = tmpAuthErrMsg;
  749. }
  750. csOSVerion = GetOsVersion();
  751. if (!csOSVerion.IsNullOrEmpty())
  752. termInfo["OSVersion"] = csOSVerion;
  753. termInfo["Harddisk"] = QueryHarddiskInfo();
  754. #if defined(RVC_OS_WIN)
  755. termInfo["OSType"] = "Windows";
  756. termInfo["AsiaInfo"] = CheckProcessExistByName("NTRtScan.exe") ? "Y" : "N";
  757. termInfo["UniAccess"] = CheckProcessExistByName("UniAccessAgent.exe") ? "Y" : "N";
  758. termInfo["RuiYan"] = CheckProcessExistByName("RuiYan.exe") ? "Y" : "N";
  759. termInfo["Symantec"] = CheckProcessExistByName("SavUI.exe") ? "Y" : "N";
  760. #else
  761. termInfo["OSType"] = "UOS";
  762. #endif
  763. CSmartPointer<IConfigInfo> spConfigRun;
  764. GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfigRun);
  765. //CAutoArray<SP::Module::Net::NetworkAdapterItem> netList;
  766. if (m_netList.GetCount() == 0)
  767. SP::Module::Net::GetINETMacAddresses(m_netList);
  768. CSimpleStringA csMac(""), csIP(""), csDNS("");
  769. for (int i = 0; i < m_netList.GetCount(); i++) {
  770. if (!csMac.IsNullOrEmpty()) {
  771. csMac += ";";
  772. }
  773. csMac += m_netList[i].mac.c_str();
  774. if (!csIP.IsNullOrEmpty()) {
  775. csIP += ";";
  776. }
  777. csIP += m_netList[i].ip.c_str();
  778. }
  779. for (int i = 0; i < m_dns.GetCount(); i++) {
  780. if (!csDNS.IsNullOrEmpty()) {
  781. csDNS += ";";
  782. }
  783. csDNS += m_dns[i].c_str();
  784. }
  785. termInfo["MACs"] = csMac;
  786. termInfo["IPs"] = csIP;
  787. termInfo["DNSs"] = csDNS;
  788. char xOSTime[64] = {0};
  789. char elapseTime[64] = {0};//使用机器启动时间秒数
  790. ULONGLONG dwElapse = SP::Module::Comm::RVCGetTickCount();
  791. DWORD elapseTimeTemp = dwElapse / 1000;
  792. #if defined(RVC_OS_WIN)
  793. termInfo["OSTime"] = itoa(m_elapseTimeFromOSStart, xOSTime, 10);
  794. termInfo["elapseTime"] = itoa(elapseTimeTemp, elapseTime, 10);
  795. #else
  796. termInfo["OSTime"] = _itoa(m_elapseTimeFromOSStart, xOSTime, 10);
  797. termInfo["elapseTime"] = _itoa(elapseTimeTemp, elapseTime, 10);
  798. #endif
  799. CSimpleStringA csRunPath("");
  800. GetEntityBase()->GetFunction()->GetPath("Run", csRunPath);
  801. termInfo["AppPath"] = csRunPath;
  802. std::pair<bool, std::string> strResult;
  803. strResult = generateJsonStr(termInfo);
  804. spConfigRun->ReadConfigValue("Run", "WarnMsg", csWarnMsg);
  805. //oilyang@20210323 discard the following rule of throwing LogWarn.Always throw LogWarn
  806. //oilyang@20201201 log warn every time if content of msg has changed
  807. if (bTmpEtyNewStart)
  808. {
  809. LogWarn(Severity_Low, Error_Unexpect, LOG_WARN_HEALTH_UPLOAD_INFO_ABOUT_TERM, strResult.second.c_str());
  810. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutTerm")(strResult.second.c_str());
  811. }
  812. else
  813. {
  814. LogWarn(Severity_Low, Error_Unexpect, LOG_WARN_HEALTH_UPLOAD_INFO_ABOUT_TERM, strResult.second.c_str());
  815. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutTerm")(strResult.second.c_str());
  816. }
  817. }
  818. void CHealthManagerFSM::ToCallAccessAuthDoWork()
  819. {
  820. if (!m_bInAccessAuthDoWork)
  821. {
  822. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("To Call AccessAuthDoWork");
  823. AccessAuthTask* pTask = new AccessAuthTask(this);
  824. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  825. }
  826. }
  827. bool CHealthManagerFSM::IfInUpgradeProcess()
  828. {
  829. CSimpleStringA csRunCfgPath(""), csFileName("");
  830. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("RunCfg", csRunCfgPath);
  831. csFileName = csRunCfgPath + SPLIT_SLASH_STR + "starttime.dat";
  832. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("csFileName:%s", csFileName.GetData());
  833. #if defined(RVC_OS_WIN)
  834. if (_access((const char*)csFileName, 0) == 0) {
  835. #else
  836. if (access((const char*)csFileName, F_OK) == 0) {
  837. #endif
  838. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("升级切换中");
  839. return true;
  840. }
  841. else
  842. return false;
  843. }
  844. void CHealthManagerFSM::WaitToCallAccessAuthDoWork()
  845. {
  846. //WaitForSingleObject
  847. bool bHaveShowMsg = false;
  848. while (1)
  849. {
  850. CSimpleStringA csHavePath("N");
  851. GetEntityBase()->GetFunction()->GetSysVar("AccessHavePath", csHavePath);
  852. if (csHavePath.Compare("Y") == 0 || csHavePath.Compare("E") == 0)
  853. {
  854. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501A2")("AccessAuth entity ok.");
  855. AccessAuthTask* pTask = new AccessAuthTask(this);
  856. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  857. break;
  858. }
  859. else
  860. {
  861. Sleep(5000);
  862. LogWarn(Severity_High, Error_Unexpect, HealthManager_UserErrorCode_WaitForAccessAuthEntityIdle, "等待准入实体准备好");
  863. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501A2").setResultCode("RTA5107")("等待准入实体准备好");
  864. }
  865. }
  866. }
  867. void CHealthManagerFSM::WKUpdatePeriod()
  868. {
  869. if (m_sysInfo.strTerminalID.GetLength() < 7)
  870. {
  871. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("wrong terminalNo:[%s]", m_sysInfo.strTerminalID.GetData());
  872. return;
  873. }
  874. auto pEntity = ((CHealthManagerEntity*)m_pEntity);
  875. //oilyang@20220413 control update working key by CenterSetting
  876. if (m_iDoNotUpdateWKDaily == 1)
  877. {
  878. // 没有密码键盘 或 集中配置告知无需更新,无需更新
  879. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)
  880. (CSimpleStringA::Format("DoNotUpdateWKDaily:%d, ignore update wk"
  881. , m_iDoNotUpdateWKDaily));
  882. return;
  883. }
  884. // 检查上次密钥同步时间(一天只同步一次)
  885. CSmartPointer<IConfigInfo> pConfigRun;
  886. m_pEntity->GetFunction()->OpenConfig(Config_Run, pConfigRun);
  887. int nWKLastSyncTime(0);
  888. pConfigRun->ReadConfigValueInt("Main", "WKSyncSuccTime", nWKLastSyncTime);
  889. int nWKSyncFailCount(0);
  890. pConfigRun->ReadConfigValueInt("Main", "WKSyncFailCount", nWKSyncFailCount);
  891. SYSTEMTIME stSyncTime = CSmallDateTime(nWKLastSyncTime).ToSystemTime();
  892. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)
  893. ("last WK sync time: %04d-%02d-%02d %02d:%02d:%02d",
  894. stSyncTime.wYear, stSyncTime.wMonth, stSyncTime.wDay,
  895. stSyncTime.wHour, stSyncTime.wMinute, stSyncTime.wSecond);
  896. SYSTEMTIME stNow = {};
  897. GetLocalTimeRVC(stNow);
  898. int lastUpdateDays = sumday(stSyncTime.wYear, stSyncTime.wMonth, stSyncTime.wDay);
  899. int todayDays = sumday(stNow.wYear, stNow.wMonth, stNow.wDay);
  900. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("lastUpdateDays:%d,todayDays:%d,x:%d", lastUpdateDays,todayDays, todayDays-lastUpdateDays);
  901. //if ((nWKLastSyncTime > 0 && stSyncTime.wYear == stNow.wYear
  902. // && stSyncTime.wMonth == stNow.wMonth && stSyncTime.wDay == stNow.wDay
  903. // && nWKSyncFailCount == 0)) // 最近一次同步成功,才能跳过
  904. if (todayDays - lastUpdateDays < m_wkUpdatePeriod)
  905. {
  906. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)
  907. ("WK has been updated, last sync time: %s", (const char*)CSmallDateTime(nWKLastSyncTime).ToTimeString());
  908. }
  909. else
  910. {
  911. //if have exceed the time,we should update working key in the next peroid
  912. if (todayDays - lastUpdateDays < m_wkUpdatePeriod * 2)
  913. {
  914. int xTerm = atoi(m_sysInfo.strTerminalID.SubString(m_sysInfo.strTerminalID.GetLength() - 7, 7));
  915. if ((todayDays % m_wkUpdatePeriod) != (xTerm % m_wkUpdatePeriod))
  916. {
  917. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("todayDays:%d, xTerm:%d, m_wkUpdatePeriod:%d", todayDays, xTerm, m_wkUpdatePeriod);
  918. return;
  919. }
  920. }
  921. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("begin update WK now");
  922. ErrorCodeEnum eErrCode = Error_Succeed;
  923. if (m_pACClient == NULL)
  924. {
  925. m_pACClient = new AccessAuthService_ClientBase(this->GetEntityBase());
  926. eErrCode = m_pACClient->Connect();
  927. if (eErrCode != Error_Succeed) {
  928. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("accessauth connected failed.");
  929. m_pACClient->SafeDelete();
  930. m_pACClient = NULL;
  931. m_bInAccessAuthDoWork = false;
  932. return;
  933. }
  934. else {
  935. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("accessauth connected.");
  936. }
  937. }
  938. eErrCode = (*m_pACClient)(EntityResource::getLink().upgradeLink())->UpdateWK();
  939. if(Error_Succeed == eErrCode)
  940. {
  941. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501K1")("accessauth updatewk succ.");
  942. pConfigRun->WriteConfigValue("Main", "WKSyncSuccTime",
  943. (const char*) CSimpleStringA::Format("0x%08X", (DWORD)CSmallDateTime::GetNow()));
  944. pConfigRun->WriteConfigValueInt("Main", "WKSyncFailCount", 0);
  945. }
  946. else
  947. {
  948. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501K1").setResultCode("RTA5103")("accessauth updatewk failed.");
  949. nWKSyncFailCount++;
  950. pConfigRun->WriteConfigValueInt("Main", "WKSyncFailCount", nWKSyncFailCount);
  951. }
  952. }
  953. }
  954. int CHealthManagerFSM::sumday(int year, int month, int day)
  955. {
  956. 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} };
  957. int iLeapYear = 0;
  958. if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
  959. iLeapYear = 1;
  960. int yearday = year * 365 + year / 4 - year / 100 + year / 400;
  961. int monthday = days[iLeapYear][month - 1];
  962. return yearday + monthday + day;
  963. }
  964. void CHealthManagerFSM::QueryHardwareInfo(SpReqAnsContext<HealthManagerService_QueryHardwareInfo_Req, HealthManagerService_QueryHardwareInfo_Ans>::Pointer ctx)
  965. {
  966. CSystemStaticInfo info;
  967. GetEntityBase()->GetFunction()->GetSystemStaticInfo(info);
  968. //CAutoArray<SP::Module::Net::NetworkAdapterItem> netList;
  969. if (m_netList.GetCount() == 0)
  970. SP::Module::Net::GetINETMacAddresses(m_netList);
  971. CAutoArray<CSimpleStringA> ipAddrs, macAddrs;
  972. for (int i = 0; i < m_netList.GetCount(); i++) {
  973. CSimpleStringA tmpip = m_netList[i].ip.c_str();
  974. CSimpleStringA tmpmac = m_netList[i].mac.c_str();
  975. ipAddrs.Append(&tmpip, 0, 1);
  976. macAddrs.Append(&tmpmac, 0, 1);
  977. }
  978. ctx->Ans.ip = ipAddrs;
  979. ctx->Ans.mac = macAddrs;
  980. ctx->Ans.machineType = info.strMachineType;
  981. ctx->Ans.site = info.strSite;
  982. ctx->Ans.terminalNo = info.strTerminalID;
  983. ctx->Ans.termLimit = "";
  984. ctx->Ans.termVersion = info.InstallVersion.ToString();
  985. //oilyang@20241220 (win)不再获取操作系统信息
  986. ctx->Ans.reserved3 = "";
  987. ctx->Ans.reserved4 = "";
  988. //oilyang@20241220 标准版搜狗输入法推全行已久,默认给1,即走标准输入法。待郭丹下线业务端依赖逻辑后废弃此字段使用
  989. ctx->Ans.reserved2 = 1;
  990. //reserved1
  991. #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
  992. ctx->Ans.reserved1 = 1;
  993. #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
  994. ctx->Ans.reserved1 = 2;
  995. #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
  996. ctx->Ans.reserved1 = 3;
  997. #elif defined(DEVOPS_ON_DEV)/*DevOps流水线编译,Dev环境*/
  998. ctx->Ans.reserved1 = 0;
  999. #else/*本地编译等非DevOps环境编译的版本*/
  1000. ctx->Ans.reserved1 = 0;
  1001. #endif
  1002. 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
  1003. , ctx->Ans.machineType.GetData());
  1004. ctx->Answer(Error_Succeed);
  1005. }
  1006. bool CHealthManagerFSM::CheckProcessExistByName(CSimpleStringA procName)
  1007. {
  1008. if (procName.IsNullOrEmpty())
  1009. return false;
  1010. #ifdef RVC_OS_WIN
  1011. HANDLE hSnapshot;
  1012. //find if have "NTRtScan.exe"
  1013. hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  1014. if (hSnapshot)
  1015. {
  1016. PROCESSENTRY32 pe;
  1017. pe.dwSize = sizeof(pe);
  1018. if (Process32First(hSnapshot, &pe))
  1019. {
  1020. do {
  1021. if (_stricmp(&pe.szExeFile[0], procName.GetData()) == 0)
  1022. {
  1023. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("find %s on this machine.", procName.GetData());
  1024. return true;
  1025. }
  1026. } while (Process32Next(hSnapshot, &pe));
  1027. }
  1028. CloseHandle(hSnapshot);
  1029. }
  1030. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("can't find %s on this machine.", procName.GetData());
  1031. return false;
  1032. #else
  1033. return false;
  1034. #endif
  1035. }
  1036. void CHealthManagerFSM::QueryAndSaveDNS()
  1037. {
  1038. for (int i = 0; i < m_dns.GetCount(); ++i)
  1039. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("before to get, the m_dns[%s]", m_dns[i].c_str());
  1040. m_dns.Clear();
  1041. CSimpleStringA runInfoPath, csDNSKeyword;
  1042. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
  1043. if (eErr != Error_Succeed) {
  1044. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetPath runinfo error=%d.", eErr);
  1045. return;
  1046. }
  1047. runInfoPath = runInfoPath + SPLIT_SLASH_STR + "runcfg" + SPLIT_SLASH_STR + "dns";
  1048. #if defined(RVC_OS_WIN)
  1049. CSimpleStringA csCmd;
  1050. csCmd = CSimpleStringA::Format("cmd /c ipconfig /all >%s", runInfoPath.GetData());
  1051. WinExec((LPCSTR)csCmd, SW_HIDE);
  1052. csDNSKeyword = "DNS 服务器";
  1053. #else
  1054. std::string sucContent, failedContent;
  1055. CSimpleStringA strCmd;
  1056. strCmd = CSimpleStringA::Format("cat /etc/resolv.conf | grep \"nameserver\" >%s", runInfoPath.GetData());
  1057. bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
  1058. csDNSKeyword = "nameserver";
  1059. #endif //RVC_OS_WIN
  1060. ifstream is;
  1061. is.open(runInfoPath.GetData(), ios::binary);
  1062. if (!is.is_open())
  1063. {
  1064. DWORD dwErr = GetLastError();
  1065. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("open %s file failed. [%d]", runInfoPath.GetData(), dwErr);
  1066. return;
  1067. }
  1068. string line;
  1069. while (!is.eof()) {
  1070. getline(is, line);
  1071. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("line:%s", line.c_str());
  1072. size_t start = line.find(csDNSKeyword.GetData());
  1073. if (start != string::npos)
  1074. {
  1075. #if defined(RVC_OS_WIN)
  1076. int dnsStart = line.find(": ");
  1077. if (dnsStart != string::npos)
  1078. {
  1079. string xDns = SP::Utility::ToTrim(line.substr(dnsStart + 1, line.length() - dnsStart - 1));
  1080. m_dns.Append(&xDns, 0, 1);
  1081. }
  1082. #else
  1083. string xDns = SP::Utility::ToTrim(line.substr(start + csDNSKeyword.GetLength() + 1, line.length() - start - csDNSKeyword.GetLength() - 1));
  1084. m_dns.Append(&xDns, 0, 1);
  1085. #endif
  1086. }
  1087. else
  1088. continue;
  1089. }
  1090. return;
  1091. }
  1092. void CHealthManagerFSM::QueryAndSendCPUInfo()
  1093. {
  1094. #if defined(RVC_OS_WIN)
  1095. if (!m_cpuInfo.IsNullOrEmpty())
  1096. {
  1097. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("have queried cpu info, no need to query again, current cpuinfo:%s", m_cpuInfo.GetData());
  1098. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutCPU")(m_cpuInfo.GetData());
  1099. return;
  1100. }
  1101. SYSTEM_INFO si;
  1102. GetSystemInfo(&si);
  1103. std::map<std::string, std::string> map_cpuInfo;
  1104. map_cpuInfo.insert(std::make_pair("dwProcessorType", CSimpleStringA::Format("%d", si.dwProcessorType)));
  1105. map_cpuInfo.insert(std::make_pair("wProcessorLevel", CSimpleStringA::Format("%d", si.wProcessorLevel)));
  1106. map_cpuInfo.insert(std::make_pair("wProcessorArchitecture", CSimpleStringA::Format("%d", si.wProcessorArchitecture)));
  1107. map_cpuInfo.insert(std::make_pair("wProcessorRevision", CSimpleStringA::Format("%d", si.wProcessorRevision)));
  1108. map_cpuInfo.insert(std::make_pair("dwNumberOfProcessors", CSimpleStringA::Format("%d", si.dwNumberOfProcessors)));
  1109. m_cpuInfo = generateJsonStr(map_cpuInfo).second.c_str();
  1110. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutCPU")(m_cpuInfo.GetData());
  1111. #else
  1112. ifstream cpuinfo("/proc/cpuinfo");
  1113. if (!cpuinfo.is_open()) {
  1114. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("opening /proc/cpuinfo error:%s", strerror(GetLastErrorRVC()));
  1115. return;
  1116. }
  1117. std::map<std::string, std::string> map_cpuInfo;
  1118. string line;
  1119. while (std::getline(cpuinfo, line)) {
  1120. auto elems = SP::Utility::Split(line, ':');
  1121. if (elems.size() > 1) {
  1122. map_cpuInfo[SP::Utility::ToTrim(elems[0])] = SP::Utility::ToTrim(elems[1]);
  1123. if (line.find("CPU revision") != string::npos)
  1124. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutCPU")(generateJsonStr(map_cpuInfo).second.c_str());
  1125. }
  1126. }
  1127. #endif //RVC_OS_WIN
  1128. return;
  1129. }
  1130. void CHealthManagerFSM::QueryAndSendDisplayInfo()
  1131. {
  1132. std::map<std::string, std::string> primaryInfo;
  1133. std::map<std::string, std::string> secondaryInfo;
  1134. std::map<std::string, std::string> displayInfo;
  1135. #if defined(RVC_OS_WIN)
  1136. DISPLAY_DEVICE devDevice;
  1137. devDevice.cb = sizeof(DISPLAY_DEVICE);
  1138. //获取系统中的所有显示设备
  1139. EnumDisplayDevices(NULL, ENUM_CURRENT_SETTINGS, &devDevice, 0);
  1140. bool bPrimary = false;
  1141. // 遍历显示设备列表
  1142. for (int i = 0; EnumDisplayDevices(NULL, i, &devDevice, 0) != 0; i++)
  1143. {
  1144. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("devDevice.StateFlags:%d", devDevice.StateFlags);
  1145. bPrimary = false;
  1146. //if connected
  1147. if (devDevice.StateFlags & DISPLAY_DEVICE_ACTIVE)
  1148. {
  1149. if (devDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
  1150. bPrimary = true;
  1151. // 获取显示设备的分辨率
  1152. DEVMODE devMode;
  1153. devMode.dmSize = sizeof(DEVMODE);
  1154. EnumDisplaySettings(devDevice.DeviceName, ENUM_CURRENT_SETTINGS, &devMode);
  1155. if (bPrimary)
  1156. {
  1157. primaryInfo["dmDeviceName"] = CSimpleStringA::Format("%s", devMode.dmDeviceName);
  1158. primaryInfo["dmPelsWidth"] = CSimpleStringA::Format("%d", devMode.dmPelsWidth);
  1159. primaryInfo["dmPelsHeight"] = CSimpleStringA::Format("%d", devMode.dmPelsHeight);
  1160. primaryInfo["dmDisplayOrientation"] = CSimpleStringA::Format("%d", devMode.dmDisplayOrientation);
  1161. primaryInfo["dmDisplayFixedOutput"] = CSimpleStringA::Format("%d", devMode.dmDisplayFixedOutput);
  1162. primaryInfo["dmPosition.x"] = CSimpleStringA::Format("%d", devMode.dmPosition.x);
  1163. primaryInfo["dmPosition.y"] = CSimpleStringA::Format("%d", devMode.dmPosition.y);
  1164. }
  1165. else
  1166. {
  1167. secondaryInfo["dmDeviceName"] = CSimpleStringA::Format("%s", devMode.dmDeviceName);
  1168. secondaryInfo["dmPelsWidth"] = CSimpleStringA::Format("%d", devMode.dmPelsWidth);
  1169. secondaryInfo["dmPelsHeight"] = CSimpleStringA::Format("%d", devMode.dmPelsHeight);
  1170. secondaryInfo["dmDisplayOrientation"] = CSimpleStringA::Format("%d", devMode.dmDisplayOrientation);
  1171. secondaryInfo["dmDisplayFixedOutput"] = CSimpleStringA::Format("%d", devMode.dmDisplayFixedOutput);
  1172. secondaryInfo["dmPosition.x"] = CSimpleStringA::Format("%d", devMode.dmPosition.x);
  1173. secondaryInfo["dmPosition.y"] = CSimpleStringA::Format("%d", devMode.dmPosition.y);
  1174. }
  1175. }
  1176. }
  1177. displayInfo["PrimaryText"] = generateJsonStr(primaryInfo).second.c_str();
  1178. displayInfo["SecondaryText"] = generateJsonStr(secondaryInfo).second.c_str();
  1179. #else
  1180. CSimpleStringA runInfoPath, csDNSKeyword;
  1181. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
  1182. if (eErr != Error_Succeed) {
  1183. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetPath runinfo error=%d.", eErr);
  1184. return;
  1185. }
  1186. runInfoPath = runInfoPath + SPLIT_SLASH_STR + "runcfg" + SPLIT_SLASH_STR + "monitor";
  1187. std::string sucContent, failedContent;
  1188. CSimpleStringA strCmd;
  1189. strCmd = CSimpleStringA::Format("xrandr | grep \" connected\" >%s", runInfoPath.GetData());
  1190. bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
  1191. if (!ret)
  1192. {
  1193. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("failedContent:%s", failedContent.c_str());
  1194. return;
  1195. }
  1196. ifstream is;
  1197. is.open(runInfoPath.GetData(), ios::binary);
  1198. if (!is.is_open())
  1199. {
  1200. DWORD dwErr = GetLastError();
  1201. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("open %s file failed. [%d]", runInfoPath.GetData(), dwErr);
  1202. return;
  1203. }
  1204. string line;
  1205. while (!is.eof()) {
  1206. getline(is, line);
  1207. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("line:%s", line.c_str());
  1208. if (line.find("connected") != string::npos)
  1209. {
  1210. if (line.find("primary") != string::npos)
  1211. displayInfo["PrimaryText"] = line;
  1212. else
  1213. displayInfo["SecondaryText"] = line;
  1214. }
  1215. }
  1216. #endif
  1217. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutDisplay")(generateJsonStr(displayInfo).second.c_str());
  1218. }
  1219. string CHealthManagerFSM::QueryHarddiskInfo()
  1220. {
  1221. CSimpleStringA csRunCfgPath("");
  1222. GetEntityBase()->GetFunction()->GetPath("RunCfg", csRunCfgPath);
  1223. csRunCfgPath = csRunCfgPath + SPLIT_SLASH_STR + "AccessAuthorization.ini";
  1224. char tmp[256];
  1225. memset(tmp, 0, 256);
  1226. inifile_read_str_s("system", "info", "", tmp, 255, csRunCfgPath);
  1227. auto elems = SP::Utility::Split(tmp, '|');
  1228. if (elems.size() > 2) {
  1229. return SP::Utility::ToTrim(elems[2]);
  1230. }
  1231. return "";
  1232. }
  1233. void CHealthManagerFSM::CheckIfPinPadOK()
  1234. {
  1235. //to check if PinPad is ok, wait for 5 seconds,then go on
  1236. //RVC.CardStore have no PinPad
  1237. if (m_sysInfo.strMachineType.Compare("RVC.CardStore", true) == 0)
  1238. {
  1239. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501A3")("RVC.CardStore have no PinPad");
  1240. return;
  1241. }
  1242. ULONGLONG ullWaitStart, ullWaitEnd;
  1243. ullWaitEnd = ullWaitStart = SP::Module::Comm::RVCGetTickCount();
  1244. PinPadService_ClientBase* pClient = new PinPadService_ClientBase(this->m_pEntity);
  1245. if (pClient != NULL)
  1246. {
  1247. ErrorCodeEnum eErrCode = pClient->Connect();
  1248. if (eErrCode == Error_Succeed)
  1249. {
  1250. do {
  1251. PinPadService_GetDevInfo_Req reqQ;
  1252. PinPadService_GetDevInfo_Ans ansQ;
  1253. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 1000);
  1254. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  1255. ullWaitEnd = SP::Module::Comm::RVCGetTickCount();
  1256. if (eErrCode == Error_DevNotAvailable)
  1257. {
  1258. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("pinpad open failed");
  1259. break;
  1260. }
  1261. else if (eErrCode == Error_Succeed)
  1262. break;
  1263. if (ullWaitEnd - ullWaitStart > m_maxWaitForPinPad)
  1264. break;
  1265. Sleep(500);
  1266. } while (true);
  1267. }
  1268. else
  1269. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("connect to pinpad failed.error code:%d", eErrCode);
  1270. }
  1271. else
  1272. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("new PinPadService_ClientBase failed.GetLastError:%d", GetLastErrorRVC());
  1273. m_ullWaitForPinPad = ullWaitEnd - ullWaitStart;
  1274. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501A3").setCostTime(m_ullWaitForPinPad)("finish (or time out) check PinPad");
  1275. return;
  1276. }
  1277. bool CHealthManagerFSM::CheckIfAccessAuthSuc()
  1278. {
  1279. if (m_iAccessAuth == VtmLoad_AccessAuth_Suc)
  1280. return true;
  1281. CSimpleStringA csTmpTS("");
  1282. GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTmpTS);
  1283. if (csTmpTS.Compare("A") == 0)
  1284. return true;
  1285. else
  1286. return false;
  1287. }