123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329 |
- #include "stdafx.h"
- #include <fstream>
- #include <string>
- #include <algorithm>
- #include <regex>
- #include "SpUtility.h"
- #include "iniutil.h"
- #if defined(RVC_OS_WIN)
- #include <TlHelp32.h>
- #include <iphlpapi.h>
- #include <ws2tcpip.h>
- #include <Winsock2.h>
- #include <io.h>
- #include "CSystemStatus.h"
- #pragma comment(lib, "IPHLPAPI.lib")
- #pragma comment(lib, "libpublicFun.lib")
- #else
- #include <unistd.h>
- #include <fcntl.h>
- #include <errno.h>
- #endif //RVC_OS_WIN
- #include "mod_healthmanager.h"
- #include "publicFunExport.h"
- using namespace std;
- const int MAX_AYSNC_TIMEOUT = 60000;
- const int MAX_IGNORE_TIMEOUT = 100;
- unsigned long long GetLastErrorRVC() {
- #if defined(RVC_OS_WIN)
- return GetLastError();
- #else
- return errno;
- #endif //RVC_OS_WIN
- }
- enum EntityOP
- {
- OP_STOP_ENTITY,
- OP_START_ENTITY,
- OP_PAUSE_ENTITY,
- OP_TERMINATE_ENTITY,
- OP_CONTINUE_ENTITY,
- };
- ErrorCodeEnum CHealthManagerFSM::Initial()
- {
- m_netList.Init(0);
- CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- CSmartPointer<IAsynWaitSp> spWait;
-
- ErrorCodeEnum err;
- GetEntityBase()->GetFunction()->GetSystemStaticInfo(m_sysInfo);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("machinetype[%s],terminalID[%s]", (LPCTSTR)m_sysInfo.strMachineType, (LPCTSTR)m_sysInfo.strTerminalID);
- CSmartPointer<IConfigInfo> spConfigCen;
- GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen);
- spConfigCen->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "WKUpdatePeriod", m_wkUpdatePeriod);
- if (m_wkUpdatePeriod <= 0 || m_wkUpdatePeriod > 365)
- m_wkUpdatePeriod = 30;//default
- spConfigCen->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "DoNotUpdateWKDaily", m_iDoNotUpdateWKDaily);
-
- spConfigCen->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "MaxWaitForPinPad", m_maxWaitForPinPad);
- if (m_maxWaitForPinPad <= 0 || m_maxWaitForPinPad > 5000)
- m_maxWaitForPinPad = 5000;//default
- CSimpleStringA csTmpTS("");
- GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTmpTS);
- if (csTmpTS.Compare("N") != 0)
- GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "X");
-
- SP::Module::Net::GetINETMacAddresses(m_netList);
- return Error_Succeed;
- }
- ErrorCodeEnum CHealthManagerFSM::OnInit(void)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Complied at: %s %s", __DATE__, __TIME__);
- return Initial();
- }
- ErrorCodeEnum CHealthManagerFSM::OnExit(void)
- {
- return Error_Succeed;
- }
- void CHealthManagerFSM::s0_on_entry(void)
- {
- LOG_FUNCTION();
- m_fsmState = HM_FSM_INIT;
- m_ullElapseFromOSStart = SP::Module::Comm::RVCGetTickCount();
- m_elapseTimeFromOSStart = m_ullElapseFromOSStart / 1000;
- CSimpleStringA xMsg = CSimpleStringA::Format("{\"Decripstion\":\"Entity start\",\"version\":\"%s\",\"elapseTime\":\"%d\"}", m_sysInfo.InstallVersion.ToString().GetData(), m_elapseTimeFromOSStart);
- LogWarn(Severity_Low, Error_Unexpect, HealthManager_UserErrorCode_Enter_SafeLoad_State, xMsg.GetData());
- FSMEvent* pEvt = new FSMEvent(USER_EVT_WAIT_DEAMON_FINISHED);
- pEvt->param1 = 0;
- PostEventFIFO(pEvt);
- }
- void CHealthManagerFSM::s0_on_exit(void)
- {
- }
- unsigned int CHealthManagerFSM::s0_on_event(FSMEvent* pEvt)
- {
- int ret = 0;
- switch(pEvt->iEvt)
- {
- case USER_EVT_WAIT_DEAMON_FINISHED:
- ret = pEvt->param1;
- pEvt->SetHandled();
- break;
- default:
- break;
- }
- return ret;
- }
- //Idle(Operating finished)
- void CHealthManagerFSM::s4_on_entry()
- {
- m_fsmState = HM_FSM_STATE_IDLE;
- }
- void CHealthManagerFSM::s4_on_exit()
- {
- LOG_FUNCTION();
- }
- unsigned int CHealthManagerFSM::s4_on_event(FSMEvent* pEvt)
- {
- LOG_FUNCTION();
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("s4 event %d,%d",pEvt->iEvt,pEvt->param1);
- switch(pEvt->iEvt)
- {
- case USER_EVT_ACCESSAUTH_FINISHED:
- {
- pEvt->SetHandled();
-
- CSimpleStringA csTermStage;
- ErrorCodeEnum eErrCode;
- eErrCode = GetEntityBase()->GetFunction()->GetSysVar("TerminalStage",csTermStage);
- DbgWithLink(LOG_LEVEL_DEBUG,LOG_TYPE_SYSTEM)("after accessauth to get termstage %s",(LPCTSTR)csTermStage);
- //oilyang@20220614 添加密钥更新逻辑
- if (csTermStage[0] == 'A')
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("after auth suc,to call WKUpdatePeriodTask");
- WKUpdatePeriodTask* pTask = new WKUpdatePeriodTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
- }
- LogTermInfoTask* task = new LogTermInfoTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- if (m_iAccessAuth != VtmLoad_AccessAuth_Suc)
- PostProcessAfterUpgrade();
- }
- break;
- case USER_EVT_MAITAIN:
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("to maintain...");
- m_stateBeforeMaintain = m_fsmState;
- pEvt->SetHandled();
- break;
- case USER_EVT_ENTER_CUSTOMER_MANAGER:
- pEvt->SetHandled();
- break;
- case USER_EVT_VTMLOADER_FINISHED:
- {
- pEvt->SetHandled();
- if (pEvt->param1 == 1)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501V1").setResultCode("RTA510E")("VtmLoader load SIPphone entity failed, to Set TerminalStage M.");
- SetVtmLoadResult(VtmLoad_MediaLoadFail);
- return pEvt->param1;
- }
- else if (pEvt->param1 == 2)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501V1").setResultCode("RTA510F")("VtmLoader load SYNCSTART(boot cfg = 2) entity failed, to Set TerminalStage C.");
- SetVtmLoadResult(VtmLoad_OtherSyncEntityLoadFail);
- return pEvt->param1;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501A1")("VtmLoader load entitys ok.");
- if (m_iAccessAuth == VtmLoad_AccessAuth_Init)
- {
- WaitToCallAccessAuthTask* pTask = new WaitToCallAccessAuthTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
- }
- }
- break;
- default:
- break;
- }
- return 0;
- }
- //Fault
- void CHealthManagerFSM::s5_on_entry()
- {
- LOG_FUNCTION();
- LogTermInfoTask* task = new LogTermInfoTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- m_fsmState = HM_FSM_STATE_FAULT;
- PostProcessAfterUpgrade();
- }
- void CHealthManagerFSM::s5_on_exit()
- {
- LOG_FUNCTION();
- }
- unsigned int CHealthManagerFSM::s5_on_event(FSMEvent* pEvt)
- {
- LOG_FUNCTION();
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("s5(Fault) event %d,%d",pEvt->iEvt,pEvt->param1);
- switch(pEvt->iEvt)
- {
- case USER_EVT_MAITAIN:
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("to maintain...");
- m_stateBeforeMaintain = m_fsmState;
- pEvt->SetHandled();
- break;
- case USER_EVT_ENTER_CUSTOMER_MANAGER:
- pEvt->SetHandled();
- break;
- case USER_EVT_ACCESSAUTH_FINISHED:
- pEvt->SetHandled();
- if (pEvt->param1 == 1)
- {
- return 1;
- }
- break;
- default:
- break;
- }
- return 0;
- }
- //Maintaining
- void CHealthManagerFSM::s6_on_entry()
- {
- LOG_FUNCTION();
- m_preFsmState = m_fsmState;
- m_fsmState = HM_FSM_STATE_MAINTAINING;
- CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- if (pFuncPrivilege == NULL)
- {
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("display screen NoPrivilege");
- return;
- }
- ErrorCodeEnum eErr = pFuncPrivilege->DisplayBlueScreen("暂停服务");
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("display blue screen %d",eErr);
- }
- void CHealthManagerFSM::s6_on_exit()
- {
- LOG_FUNCTION();
- }
- unsigned int CHealthManagerFSM::s6_on_event(FSMEvent* pEvt)
- {
- LOG_FUNCTION();
- int ret = 0;
- switch(pEvt->iEvt)
- {
- case USER_EVT_MAITAIN_FINISHED:
- pEvt->SetHandled();
- {
- CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- if (pFuncPrivilege == NULL)
- {
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("un-display screen NoPrivilege");
- return 1;
- }
- ErrorCodeEnum eErr = pFuncPrivilege->UndisplayBlueScreen();
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("un-display blue screen %d",eErr);
- if (m_stateBeforeMaintain == HM_FSM_STATE_IDLE)
- {
- }
- ret = m_preFsmState;
- }
- break;
- case USER_EVT_ENTER_CUSTOMER_MANAGER:
- pEvt->SetHandled();
- break;
- default:
- break;
- }
- return ret;
- }
- //In Customer Manager System
- void CHealthManagerFSM::s11_on_entry()
- {
- LOG_FUNCTION();
- m_preFsmState = m_fsmState;
- m_fsmState = HM_FSM_STATE_CMS;
- }
- void CHealthManagerFSM::s11_on_exit()
- {
- LOG_FUNCTION();
- }
- unsigned int CHealthManagerFSM::s11_on_event(FSMEvent* pEvt)
- {
- LOG_FUNCTION();
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("s11(In CMS) event %d",pEvt->iEvt);
- int ret = 0;
- switch (pEvt->iEvt)
- {
- case USER_EVT_MAITAIN:
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("to maintain...");
- m_stateBeforeMaintain = m_fsmState;
- pEvt->SetHandled();
- break;
- case USER_EVT_SWITCH_BACK_TO_RVC:
- pEvt->SetHandled();
- ret = m_preFsmState;
- break;
- default:
- break;
- }
- return ret;
- }
- //0:auth suc or have already authed;1:auth failed;
- int CHealthManagerFSM::AccessAuthDoWork()
- {
- LOG_FUNCTION();
- CheckIfPinPadOK();
- m_bInAccessAuthDoWork = true;
- CSimpleStringA csTermStage("");
- ErrorCodeEnum eErrCode = GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTermStage);
- if (eErrCode == Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("before accessauth get TerminalStage %s", csTermStage.GetData());
- CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- CEntityRunInfo acInfo;
- eErrCode = pFunc->GetEntityRunInfo("AccessAuthorization", acInfo);
- if (eErrCode == Error_Succeed)
- {
- switch (acInfo.eState)
- {
- case EntityState_NoStart:
- {
- CSmartPointer<IAsynWaitSp> spWaitAC;
- eErrCode = pFuncPrivilege->StartEntity("AccessAuthorization", NULL, spWaitAC);
- eErrCode = spWaitAC->WaitAnswer(MAX_AYSNC_TIMEOUT);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start accessauth %d.", eErrCode);
- }
- break;
- case EntityState_Idle:
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("AccessAuth state idle.");
- break;
- default:
- break;
- }
- if (m_pACClient == NULL)
- {
- m_pACClient = new AccessAuthService_ClientBase(this->GetEntityBase());
- eErrCode = m_pACClient->Connect();
- if (eErrCode != Error_Succeed) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("accessauth connected failed:%s", SpStrError(eErrCode));
- m_pACClient->SafeDelete();
- m_pACClient = NULL;
- m_bInAccessAuthDoWork = false;
- return 1;
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("accessauth connected.");
- }
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("Get AccessAuth RunInfo failed(%s).", SpStrError(eErrCode));
- m_bInAccessAuthDoWork = false;
- return 1;
- }
- if (m_pACClient != NULL)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to call accessauth regist");
- CSystemRunInfo sysRunInfo;
- if (GetEntityBase()->GetFunction()->GetSystemRunInfo(sysRunInfo) != Error_Succeed || sysRunInfo.eAppBootState == AppBootState_StartEntity)
- GetEntityBase()->GetFunction()->GetPrivilegeFunction()->RefreshAppBootState(AppBootState_CallAccessAuth);
- m_ullAuthStart = SP::Module::Comm::RVCGetTickCount();
- eErrCode = (*m_pACClient)(EntityResource::getLink().upgradeLink())->Regist();
- m_bHasAuthEver = true;
-
- if (eErrCode == Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501A4")("call AccessAuth's Regist return succeed");
- do {
- if (m_iAccessAuth != VtmLoad_AccessAuth_Init)
- break;
- Sleep(1000);
- } while (1);//wait for accessauth send result
- m_bFirstAccessAuth = false;
- m_bInAccessAuthDoWork = false;
- return 0;
- }
- else
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501A4").setResultCode("RTA5102")("call accessauth Regist failed:%s", SpStrError(eErrCode));
- m_bInAccessAuthDoWork = false;
- return 1;
- }
- }
- else
- {
- m_bInAccessAuthDoWork = false;
- return 1;
- }
- }
- else {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("Get TerminalStage failed(%s).", SpStrError(eErrCode));
- }
- m_bInAccessAuthDoWork = false;
- return 1;
- }
- void CHealthManagerFSM::SetVtmLoadResult(int bResult)
- {
- m_iAccessAuth = bResult;
- ErrorCodeEnum eErrCode;
- if (bResult == VtmLoad_AccessAuth_Suc)
- {
- eErrCode = GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "A");
- m_ullAccessAuthCost = SP::Module::Comm::RVCGetTickCount() - m_ullAuthStart;
- }
- else if (bResult == VtmLoad_AccessAuth_servFail) //准入服务端返回失败
- {
- eErrCode = GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "S");
- m_ullAccessAuthCost = SP::Module::Comm::RVCGetTickCount() - m_ullAuthStart;
- }
- else if (bResult == VtmLoad_MediaLoadFail) //音视频校验不通过
- {
- eErrCode = GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "M");
- }
- else //其他失败
- {
- eErrCode = GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "C");
- if (bResult != VtmLoad_OtherSyncEntityLoadFail)//if haven't call Regist(), no need to calulate the AccessAuth cost
- m_ullAccessAuthCost = SP::Module::Comm::RVCGetTickCount() - m_ullAuthStart;
- }
- if (eErrCode != Error_Succeed)
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("set TerminalStage %d,failed:%s", bResult, SpStrError(eErrCode));
- else
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("set TerminalStage %d", bResult);
- }
- void CHealthManagerFSM::ToReAccessAuth(bool bEver)
- {
- Sleep(1500);//for function "AccessAuthDoWork" to quit while
- if (m_bFirstAccessAuth)
- return;
- ToCallAccessAuthDoWork();
- }
- ErrorCodeEnum CHealthManagerFSM::AsyncStartEntity(const char *entity_name, const char *cmdline, void *pData)
- {
- CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
- ErrorCodeEnum errCode;
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- if (pFuncPrivilege != NULL) {
- CSmartPointer<IAsynWaitSp> spWait;
- errCode = pFuncPrivilege->StartEntity(entity_name, cmdline, spWait);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("start entity %s,errCode:%s", entity_name, SpStrError(errCode));
- if (errCode == Error_Succeed) {
- callback_entry *entry = new callback_entry();
- entry->pRawData = pData;
- entry->EntityName = entity_name;
- entry->ErrorResult = Error_Unexpect;
- entry->op = OP_START_ENTITY;
- if (spWait != NULL)
- spWait->SetCallback(this, entry);
- }
- return errCode;
- } else {
- return Error_NoPrivilege;
- }
- }
- ErrorCodeEnum CHealthManagerFSM::AsyncStopEntity(const char *entity_name, void *pData)
- {
- CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- if (pFuncPrivilege != NULL) {
- CSmartPointer<IAsynWaitSp> spWait;
- ErrorCodeEnum Error = pFuncPrivilege->StopEntity(entity_name, spWait);
- if (Error == Error_Succeed) {
- callback_entry *entry = new callback_entry();
- entry->pRawData = pData;
- entry->EntityName = entity_name;
- entry->ErrorResult = Error_Unexpect;
- entry->op = OP_STOP_ENTITY;
- if (spWait != NULL)
- spWait->SetCallback(this, entry);
- }
- return Error;
- } else {
- return Error_NoPrivilege;
- }
- }
- ErrorCodeEnum CHealthManagerFSM::AsyncPauseEntity(const char *entity_name, void *pData)
- {
- CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- if (pFuncPrivilege != NULL) {
- CSmartPointer<IAsynWaitSp> spWait;
- ErrorCodeEnum Error = pFuncPrivilege->PauseEntity(entity_name, spWait);
- if (Error == Error_Succeed) {
- callback_entry *entry = new callback_entry();
- entry->pRawData = pData;
- entry->EntityName = entity_name;
- entry->ErrorResult = Error_Unexpect;
- entry->op = OP_PAUSE_ENTITY;
- if (spWait != NULL)
- spWait->SetCallback(this, entry);
- }
- return Error;
- } else {
- return Error_NoPrivilege;
- }
- }
- ErrorCodeEnum CHealthManagerFSM::AsyncContinueEntity(const char *entity_name, void *pData)
- {
- CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- if (pFuncPrivilege != NULL) {
- CSmartPointer<IAsynWaitSp> spWait;
- ErrorCodeEnum Error = pFuncPrivilege->ContinueEntity(entity_name, spWait);
- if (Error == Error_Succeed) {
- callback_entry *entry = new callback_entry();
- entry->pRawData = pData;
- entry->EntityName = entity_name;
- entry->ErrorResult = Error_Unexpect;
- entry->op = OP_CONTINUE_ENTITY;
- if (spWait != NULL)
- spWait->SetCallback(this, entry);
- }
- return Error;
- } else {
- return Error_NoPrivilege;
- }
- }
- ErrorCodeEnum CHealthManagerFSM::AsyncTerminateEntity(const char *entity_name, void *pData)
- {
- CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- if (pFuncPrivilege != NULL) {
- CSmartPointer<IAsynWaitSp> spWait;
- ErrorCodeEnum Error = pFuncPrivilege->TerminateEntity(entity_name, spWait);
- if (Error == Error_Succeed) {
- callback_entry *entry = new callback_entry();
- entry->pRawData = pData;
- entry->EntityName = entity_name;
- entry->ErrorResult = Error_Unexpect;
- entry->op = OP_TERMINATE_ENTITY;
- if (spWait != NULL)
- spWait->SetCallback(this, entry);
- }
- return Error;
- } else {
- return Error_NoPrivilege;
- }
- }
- void CHealthManagerFSM::OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp)
- {
- }
- int CHealthManagerFSM::QuitFrameworkAndSaveInfo(RebootTriggerEnum eTrigger, RebootWayEnum eWay)
- {
- m_bRebooting = true;
- CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- if (pFuncPrivilege == NULL) {
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("has no privilege");
- return (int)(Error_NoPrivilege);
- }
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("quit framework and info %d,%d.", eTrigger, eWay);
- const auto result = pFuncPrivilege->Reboot(eTrigger, eWay);
- return (int)result;
- }
- void CHealthManagerFSM::PostProcessAfterUpgrade()
- {
- LOG_FUNCTION();
- if (IfInUpgradeProcess())
- {
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("exist upgrade flag file,to decide if restart framework.");
- //存在升级后的启动文件
- CSmartPointer<IConfigInfo> spConfigRun;
- ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfigRun);
- if (eErr == Error_Succeed)
- {
- int restartOSTime = 0;
- spConfigRun->ReadConfigValueInt("Run", "UpgradeRestartOSTimes", restartOSTime);
- if(restartOSTime==1){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("升级切换已重启过系统");
- //重启过的系统过的升级,在重试一定次数后等guardian 10分钟回退
- int xTimes = 0;
- spConfigRun->ReadConfigValueInt("Run", "UpgradeRestartTimes", xTimes);
- if (xTimes < 3)
- {
- xTimes++;
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("写入: UpgradeRestartTimes:%d", xTimes);
- spConfigRun->WriteConfigValueInt("Run", "UpgradeRestartTimes", xTimes);
- QuitFrameworkAndSaveInfo(RebootTrigger_Resource, RebootWay_Framework);
- }
- }else{
- //未重启过操作系统
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("升级切换未重启过系统");
- int xTimes = 0;
- spConfigRun->ReadConfigValueInt("Run", "UpgradeRestartTimes", xTimes);
- if (xTimes < 3)
- {
- xTimes++;
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("写入: UpgradeRestartTimes:%d", xTimes);
- spConfigRun->WriteConfigValueInt("Run", "UpgradeRestartTimes", xTimes);
- //oilyang@20211130 change from 3 to 2
- if (xTimes == 2)
- {
- //重启操作系统前把重启框架次数重置,重启OS次数置为1
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("准备尝试重启系统后再切换升级");
- spConfigRun->WriteConfigValueInt("Run", "UpgradeRestartTimes", 0);
- spConfigRun->WriteConfigValueInt("Run", "UpgradeRestartOSTimes", 1);
- Sleep(2000);
- QuitFrameworkAndSaveInfo(RebootTrigger_Resource, RebootWay_OS);
- }
- else
- QuitFrameworkAndSaveInfo(RebootTrigger_Resource, RebootWay_Framework);
- }
- }
- }
- }
- }
- CSimpleStringA CHealthManagerFSM::GetOsVersion()
- {
- #if defined(RVC_OS_WIN)
- CSimpleStringA runInfoPath;
- ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
- if (eErr != Error_Succeed) {
- DbgWithLink(LOG_LEVEL_ERROR,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("GetPath runinfo error=%s.", SpStrError(eErr));
- return "";
- }
- runInfoPath += "\\runcfg\\osverion";
- ifstream is;
- is.open(runInfoPath.GetData(), ios::binary);
- if (!is.is_open())
- {
- DWORD dwErr = GetLastError();
- DbgWithLink(LOG_LEVEL_ERROR,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("open runcfg\\osverion file failed. [%d]", dwErr);
- return "";
- }
- string line;
- while(!is.eof()){
- getline(is, line);
- int start = line.find("版本");
- if (start != string::npos)
- //return CSimpleStringA(line.substr(start + 5, line.length() - start - 7).c_str());
- return CSimpleStringA(line.c_str());
- else
- continue;
- }
- return "";
- #else
- std::map<std::string, std::string> osInfo;
- const char filePath[] = "/etc/os-version";
- char tmp[33];
- memset(tmp, 0, 33);
- inifile_read_str_s("Version", "SystemName", "unknown", tmp, 32, filePath);
- osInfo["SystemName"] = tmp;
- memset(tmp, 0, 33);
- inifile_read_str_s("Version", "ProductType", "unknown", tmp, 32, filePath);
- osInfo["ProductType"] = tmp;
- memset(tmp, 0, 33);
- inifile_read_str_s("Version", "MajorVersion", "unknown", tmp, 32, filePath);
- osInfo["MajorVersion"] = tmp;
- memset(tmp, 0, 33);
- inifile_read_str_s("Version", "MinorVersion", "unknown", tmp, 32, filePath);
- osInfo["MinorVersion"] = tmp;
- memset(tmp, 0, 33);
- inifile_read_str_s("Version", "OsBuild", "unknown", tmp, 32, filePath);
- osInfo["OsBuild"] = tmp;
- return generateJsonStr(osInfo).second.c_str();
- #endif
- }
- DWORD GetDualTime(SYSTEMTIME& t1, SYSTEMTIME& t2)
- {
- //assume t2 > t1...
- //oiltest for simple
- int s1, s2;
- s1 = (t1.wMinute * 60 + t1.wSecond) * 1000 + t1.wMilliseconds;
- s2 = (t2.wMinute * 60 + t2.wSecond) * 1000 + t2.wMilliseconds;
- return s2 - s1;
- }
- void CHealthManagerFSM::ToLogWarnTermAboutInfo()
- {
- LOG_FUNCTION();
- bool bTmpEtyNewStart = m_bEntityNewStart;
- if (m_bEntityNewStart)
- {
- SYSTEMTIME shellStartTime;
- m_ullTotalCost = 0;
- m_bEntityNewStart = false;
- CAutoArray<CSimpleStringA> strEntityNames;
- CAutoArray<int> strEntityIdx;
- CAutoArray<CEntityStartInfo> Infos;
- ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetAllEntityStartInfo(strEntityNames, strEntityIdx, Infos);
- for (int i = 0; i < Infos.GetCount(); ++i)
- {
- if (strEntityIdx[i] == 0)
- {
- shellStartTime = Infos[i].startTime;
- ULONGLONG dwElapseNow = SP::Module::Comm::RVCGetTickCount();
- m_ullTotalCost = dwElapseNow - m_ullElapseFromOSStart;
- LogWarn(Severity_Low, Error_Debug, LOG_TRACE_ENTITY_START_TIME,
- SP::Module::Util::generateConsumeTimeJson("total", SP::Module::Util::formatTime(shellStartTime).c_str(), m_ullTotalCost).GetData());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("EntityStartCost")(SP::Module::Util::generateConsumeTimeJson("total", SP::Module::Util::formatTime(shellStartTime).c_str(), m_ullTotalCost).GetData());
- //break;
- }
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s,%d", strEntityNames[i].GetData(), GetDualTime(Infos[i].startTime, Infos[i].startEndTime));
- if (strEntityNames[i].Compare("SIPPhone") == 0)
- m_ullSIPPhoneCost = GetDualTime(Infos[i].startTime, Infos[i].startEndTime);
- else if (strEntityNames[i].Compare("TokenKeeper") == 0)
- m_ullTokenKeeperCost = GetDualTime(Infos[i].startTime, Infos[i].startEndTime);
- }
- std::map<std::string, std::string> termStartInfo;
- termStartInfo["SIPPhoneCost"] = CSimpleStringA::Format("%d", m_ullSIPPhoneCost);
- termStartInfo["TokenKeeperCost"] = CSimpleStringA::Format("%d", m_ullTokenKeeperCost);
- termStartInfo["WaitForPinPadCost"] = CSimpleStringA::Format("%d", m_ullWaitForPinPad);
- termStartInfo["TotalCost"] = CSimpleStringA::Format("%d", m_ullTotalCost);
- termStartInfo["AccessAuthCost"] = CSimpleStringA::Format("%d", m_ullAccessAuthCost);
- termStartInfo["AccessAuthResult"] = CSimpleStringA::Format("%d", m_iAccessAuth);
- termStartInfo["OSElapseTime"] = CSimpleStringA::Format("%d", m_elapseTimeFromOSStart);
-
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("TerminalStartCost")("%s", generateJsonStr(termStartInfo).second.c_str());
- LogWarn(Severity_Low, Error_Debug, HealthManager_UserErrorCode_TerminalAppLoadInfo, generateJsonStr(termStartInfo).second.c_str());
- }
- QueryAndSaveDNS();
- QueryAndSendCPUInfo();
- QueryAndSendDisplayInfo();
- CSimpleStringA csOSVerion(""), csWarnMsg("");
- std::map<std::string, std::string> termInfo;
- termInfo["version"] = m_sysInfo.InstallVersion.ToString();
- if (m_iAccessAuth == VtmLoad_AccessAuth_Suc)
- {
- termInfo["AccessAuth"] = "T";
- }
- else
- {
- termInfo["AccessAuth"] = "F";
- CSimpleStringA tmpAuthErrMsg("");
- if (GetEntityBase()->GetFunction()->GetSysVar("AuthErrMsg", tmpAuthErrMsg) == Error_Succeed)
- termInfo["AuthErrMsg"] = tmpAuthErrMsg;
- }
- csOSVerion = GetOsVersion();
- if (!csOSVerion.IsNullOrEmpty())
- termInfo["OSVersion"] = csOSVerion;
- termInfo["Harddisk"] = QueryHarddiskInfo();
- #if defined(RVC_OS_WIN)
- termInfo["OSType"] = "Windows";
- termInfo["AsiaInfo"] = CheckProcessExistByName("NTRtScan.exe") ? "Y" : "N";
- termInfo["UniAccess"] = CheckProcessExistByName("UniAccessAgent.exe") ? "Y" : "N";
- termInfo["RuiYan"] = CheckProcessExistByName("RuiYan.exe") ? "Y" : "N";
- termInfo["Symantec"] = CheckProcessExistByName("SavUI.exe") ? "Y" : "N";
- #else
- termInfo["OSType"] = "UOS";
- #endif
- CSmartPointer<IConfigInfo> spConfigRun;
- GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfigRun);
- //CAutoArray<SP::Module::Net::NetworkAdapterItem> netList;
- if (m_netList.GetCount() == 0)
- SP::Module::Net::GetINETMacAddresses(m_netList);
- CSimpleStringA csMac(""), csIP(""), csDNS("");
- for (int i = 0; i < m_netList.GetCount(); i++) {
- if (!csMac.IsNullOrEmpty()) {
- csMac += ";";
- }
- csMac += m_netList[i].mac.c_str();
- if (!csIP.IsNullOrEmpty()) {
- csIP += ";";
- }
- csIP += m_netList[i].ip.c_str();
- }
- for (int i = 0; i < m_dns.GetCount(); i++) {
- if (!csDNS.IsNullOrEmpty()) {
- csDNS += ";";
- }
- csDNS += m_dns[i].c_str();
- }
- termInfo["MACs"] = csMac;
- termInfo["IPs"] = csIP;
- termInfo["DNSs"] = csDNS;
- char xOSTime[64] = {0};
- char elapseTime[64] = {0};//使用机器启动时间秒数
- ULONGLONG dwElapse = SP::Module::Comm::RVCGetTickCount();
- DWORD elapseTimeTemp = dwElapse / 1000;
- //TODO: CrossPlaform [Gifur@2025729]
- #if defined(RVC_OS_WIN)
- termInfo["OSTime"] = itoa(m_elapseTimeFromOSStart, xOSTime, 10);
- termInfo["elapseTime"] = itoa(elapseTimeTemp, elapseTime, 10);
- #else
- termInfo["OSTime"] = _itoa(m_elapseTimeFromOSStart, xOSTime, 10);
- termInfo["elapseTime"] = _itoa(elapseTimeTemp, elapseTime, 10);
- #endif
-
- CSimpleStringA csRunPath("");
- GetEntityBase()->GetFunction()->GetPath("Run", csRunPath);
- termInfo["AppPath"] = csRunPath;
- std::pair<bool, std::string> strResult;
- strResult = generateJsonStr(termInfo);
- spConfigRun->ReadConfigValue("Run", "WarnMsg", csWarnMsg);
- //oilyang@20210323 discard the following rule of throwing LogWarn.Always throw LogWarn
- //oilyang@20201201 log warn every time if content of msg has changed
- if (bTmpEtyNewStart)
- {
- LogWarn(Severity_Low, Error_Unexpect, LOG_WARN_HEALTH_UPLOAD_INFO_ABOUT_TERM, strResult.second.c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutTerm")(strResult.second.c_str());
- }
- else
- {
- LogWarn(Severity_Low, Error_Unexpect, LOG_WARN_HEALTH_UPLOAD_INFO_ABOUT_TERM, strResult.second.c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutTerm")(strResult.second.c_str());
- }
- }
- void CHealthManagerFSM::ToCallAccessAuthDoWork()
- {
- if (!m_bInAccessAuthDoWork)
- {
- DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("To Call AccessAuthDoWork");
- AccessAuthTask* pTask = new AccessAuthTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
- }
- }
- bool CHealthManagerFSM::IfInUpgradeProcess()
- {
- CSimpleStringA csRunCfgPath(""), csFileName("");
- ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("RunCfg", csRunCfgPath);
- csFileName = csRunCfgPath + SPLIT_SLASH_STR + "starttime.dat";
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("csFileName:%s", csFileName.GetData());
- #if defined(RVC_OS_WIN)
- if (_access((const char*)csFileName, 0) == 0) {
- #else
- if (access((const char*)csFileName, F_OK) == 0) {
- #endif
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("升级切换中");
- return true;
- }
- else
- return false;
- }
- void CHealthManagerFSM::WaitToCallAccessAuthDoWork()
- {
- //WaitForSingleObject
- bool bHaveShowMsg = false;
- while (1)
- {
- CSimpleStringA csHavePath("N");
- GetEntityBase()->GetFunction()->GetSysVar("AccessHavePath", csHavePath);
- if (csHavePath.Compare("Y") == 0 || csHavePath.Compare("E") == 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501A2")("AccessAuth entity ok.");
- AccessAuthTask* pTask = new AccessAuthTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
- break;
- }
- else
- {
- Sleep(5000);
- LogWarn(Severity_High, Error_Unexpect, HealthManager_UserErrorCode_WaitForAccessAuthEntityIdle, "等待准入实体准备好");
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501A2").setResultCode("RTA5107")("等待准入实体准备好");
- }
- }
- }
- void CHealthManagerFSM::WKUpdatePeriod()
- {
- if (m_sysInfo.strTerminalID.GetLength() < 7)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("wrong terminalNo:[%s]", m_sysInfo.strTerminalID.GetData());
- return;
- }
- auto pEntity = ((CHealthManagerEntity*)m_pEntity);
- //oilyang@20220413 control update working key by CenterSetting
- if (m_iDoNotUpdateWKDaily == 1)
- {
- // 没有密码键盘 或 集中配置告知无需更新,无需更新
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)
- (CSimpleStringA::Format("DoNotUpdateWKDaily:%d, ignore update wk"
- , m_iDoNotUpdateWKDaily));
- return;
- }
- // 检查上次密钥同步时间(一天只同步一次)
- CSmartPointer<IConfigInfo> pConfigRun;
- m_pEntity->GetFunction()->OpenConfig(Config_Run, pConfigRun);
- int nWKLastSyncTime(0);
- pConfigRun->ReadConfigValueInt("Main", "WKSyncSuccTime", nWKLastSyncTime);
- int nWKSyncFailCount(0);
- pConfigRun->ReadConfigValueInt("Main", "WKSyncFailCount", nWKSyncFailCount);
- SYSTEMTIME stSyncTime = CSmallDateTime(nWKLastSyncTime).ToSystemTime();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)
- ("last WK sync time: %04d-%02d-%02d %02d:%02d:%02d",
- stSyncTime.wYear, stSyncTime.wMonth, stSyncTime.wDay,
- stSyncTime.wHour, stSyncTime.wMinute, stSyncTime.wSecond);
- SYSTEMTIME stNow = {};
- GetLocalTimeRVC(stNow);
- int lastUpdateDays = sumday(stSyncTime.wYear, stSyncTime.wMonth, stSyncTime.wDay);
- int todayDays = sumday(stNow.wYear, stNow.wMonth, stNow.wDay);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("lastUpdateDays:%d,todayDays:%d,x:%d", lastUpdateDays,todayDays, todayDays-lastUpdateDays);
- //if ((nWKLastSyncTime > 0 && stSyncTime.wYear == stNow.wYear
- // && stSyncTime.wMonth == stNow.wMonth && stSyncTime.wDay == stNow.wDay
- // && nWKSyncFailCount == 0)) // 最近一次同步成功,才能跳过
- if (todayDays - lastUpdateDays < m_wkUpdatePeriod)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)
- ("WK has been updated, last sync time: %s", (const char*)CSmallDateTime(nWKLastSyncTime).ToTimeString());
- }
- else
- {
- //if have exceed the time,we should update working key in the next peroid
- if (todayDays - lastUpdateDays < m_wkUpdatePeriod * 2)
- {
- int xTerm = atoi(m_sysInfo.strTerminalID.SubString(m_sysInfo.strTerminalID.GetLength() - 7, 7));
- if ((todayDays % m_wkUpdatePeriod) != (xTerm % m_wkUpdatePeriod))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("todayDays:%d, xTerm:%d, m_wkUpdatePeriod:%d", todayDays, xTerm, m_wkUpdatePeriod);
- return;
- }
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("begin update WK now");
- ErrorCodeEnum eErrCode = Error_Succeed;
- if (m_pACClient == NULL)
- {
- m_pACClient = new AccessAuthService_ClientBase(this->GetEntityBase());
- eErrCode = m_pACClient->Connect();
- if (eErrCode != Error_Succeed) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("accessauth connected failed:%d", eErrCode);
- m_pACClient->SafeDelete();
- m_pACClient = NULL;
- m_bInAccessAuthDoWork = false;
- return;
- }
- else {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("accessauth connected.");
- }
- }
- eErrCode = (*m_pACClient)(EntityResource::getLink().upgradeLink())->UpdateWK();
- if(Error_Succeed == eErrCode)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501K1")("accessauth updatewk succ.");
- pConfigRun->WriteConfigValue("Main", "WKSyncSuccTime",
- (const char*) CSimpleStringA::Format("0x%08X", (DWORD)CSmallDateTime::GetNow()));
- pConfigRun->WriteConfigValueInt("Main", "WKSyncFailCount", 0);
- }
- else
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501K1").setResultCode("RTA5103")("accessauth updatewk failed.");
- nWKSyncFailCount++;
- pConfigRun->WriteConfigValueInt("Main", "WKSyncFailCount", nWKSyncFailCount);
- }
- }
- }
- int CHealthManagerFSM::sumday(int year, int month, int day)
- {
- 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} };
- int iLeapYear = 0;
- if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
- iLeapYear = 1;
- int yearday = year * 365 + year / 4 - year / 100 + year / 400;
- int monthday = days[iLeapYear][month - 1];
- return yearday + monthday + day;
- }
- void CHealthManagerFSM::QueryHardwareInfo(SpReqAnsContext<HealthManagerService_QueryHardwareInfo_Req, HealthManagerService_QueryHardwareInfo_Ans>::Pointer ctx)
- {
- CSystemStaticInfo info;
- GetEntityBase()->GetFunction()->GetSystemStaticInfo(info);
- //CAutoArray<SP::Module::Net::NetworkAdapterItem> netList;
- if (m_netList.GetCount() == 0)
- SP::Module::Net::GetINETMacAddresses(m_netList);
- CAutoArray<CSimpleStringA> ipAddrs, macAddrs;
- for (int i = 0; i < m_netList.GetCount(); i++) {
- CSimpleStringA tmpip = m_netList[i].ip.c_str();
- CSimpleStringA tmpmac = m_netList[i].mac.c_str();
- ipAddrs.Append(&tmpip, 0, 1);
- macAddrs.Append(&tmpmac, 0, 1);
- }
- ctx->Ans.ip = ipAddrs;
- ctx->Ans.mac = macAddrs;
- ctx->Ans.machineType = info.strMachineType;
- ctx->Ans.site = info.strSite;
- ctx->Ans.terminalNo = info.strTerminalID;
- ctx->Ans.termLimit = "";
- ctx->Ans.termVersion = info.InstallVersion.ToString();
- //oilyang@20241220 (win)不再获取操作系统信息
- ctx->Ans.reserved3 = "";
- ctx->Ans.reserved4 = "";
- //oilyang@20241220 标准版搜狗输入法推全行已久,默认给1,即走标准输入法。待郭丹下线业务端依赖逻辑后废弃此字段使用
- ctx->Ans.reserved2 = 1;
- //reserved1
- #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
- ctx->Ans.reserved1 = 1;
- #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
- ctx->Ans.reserved1 = 2;
- #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
- ctx->Ans.reserved1 = 3;
- #elif defined(DEVOPS_ON_DEV)/*DevOps流水线编译,Dev环境*/
- ctx->Ans.reserved1 = 0;
- #else/*本地编译等非DevOps环境编译的版本*/
- ctx->Ans.reserved1 = 0;
- #endif
- 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
- , ctx->Ans.machineType.GetData());
- ctx->Answer(Error_Succeed);
- }
- bool CHealthManagerFSM::CheckProcessExistByName(CSimpleStringA procName)
- {
- if (procName.IsNullOrEmpty())
- return false;
- #ifdef RVC_OS_WIN
- HANDLE hSnapshot;
- //find if have "NTRtScan.exe"
- hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- if (hSnapshot)
- {
- PROCESSENTRY32 pe;
- pe.dwSize = sizeof(pe);
- if (Process32First(hSnapshot, &pe))
- {
- do {
- if (_stricmp(&pe.szExeFile[0], procName.GetData()) == 0)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("find %s on this machine.", procName.GetData());
- return true;
- }
- } while (Process32Next(hSnapshot, &pe));
- }
- CloseHandle(hSnapshot);
- }
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("can't find %s on this machine.", procName.GetData());
- return false;
- #else
- return false;
- #endif
- }
- void CHealthManagerFSM::QueryAndSaveDNS()
- {
- for (int i = 0; i < m_dns.GetCount(); ++i)
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("before to get, the m_dns[%s]", m_dns[i].c_str());
- m_dns.Clear();
- CSimpleStringA runInfoPath, csDNSKeyword;
- ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
- if (eErr != Error_Succeed) {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetPath runinfo error=%d.", eErr);
- return;
- }
- runInfoPath = runInfoPath + SPLIT_SLASH_STR + "runcfg" + SPLIT_SLASH_STR + "dns";
- #if defined(RVC_OS_WIN)
- CSimpleStringA csCmd;
- csCmd = CSimpleStringA::Format("cmd /c ipconfig /all >%s", runInfoPath.GetData());
- WinExec((LPCSTR)csCmd, SW_HIDE);
- csDNSKeyword = "DNS 服务器";
- #else
- std::string sucContent, failedContent;
- CSimpleStringA strCmd;
- strCmd = CSimpleStringA::Format("cat /etc/resolv.conf | grep \"nameserver\" >%s", runInfoPath.GetData());
- bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
- csDNSKeyword = "nameserver";
- #endif //RVC_OS_WIN
- ifstream is;
- is.open(runInfoPath.GetData(), ios::binary);
- if (!is.is_open())
- {
- DWORD dwErr = GetLastError();
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("open %s file failed. [%d]", runInfoPath.GetData(), dwErr);
- return;
- }
- string line;
- while (!is.eof()) {
- getline(is, line);
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("line:%s", line.c_str());
- size_t start = line.find(csDNSKeyword.GetData());
- if (start != string::npos)
- {
- #if defined(RVC_OS_WIN)
- int dnsStart = line.find(": ");
- if (dnsStart != string::npos)
- {
- string xDns = SP::Utility::ToTrim(line.substr(dnsStart + 1, line.length() - dnsStart - 1));
- m_dns.Append(&xDns, 0, 1);
- }
- #else
- string xDns = SP::Utility::ToTrim(line.substr(start + csDNSKeyword.GetLength() + 1, line.length() - start - csDNSKeyword.GetLength() - 1));
- m_dns.Append(&xDns, 0, 1);
- #endif
- }
- else
- continue;
- }
- return;
- }
- void CHealthManagerFSM::QueryAndSendCPUInfo()
- {
- #if defined(RVC_OS_WIN)
- if (!m_cpuInfo.IsNullOrEmpty())
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("have queried cpu info, no need to query again, current cpuinfo:%s", m_cpuInfo.GetData());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutCPU")(m_cpuInfo.GetData());
- return;
- }
- SYSTEM_INFO si;
- GetSystemInfo(&si);
- std::map<std::string, std::string> map_cpuInfo;
- map_cpuInfo.insert(std::make_pair("dwProcessorType", CSimpleStringA::Format("%d", si.dwProcessorType)));
- map_cpuInfo.insert(std::make_pair("wProcessorLevel", CSimpleStringA::Format("%d", si.wProcessorLevel)));
- map_cpuInfo.insert(std::make_pair("wProcessorArchitecture", CSimpleStringA::Format("%d", si.wProcessorArchitecture)));
- map_cpuInfo.insert(std::make_pair("wProcessorRevision", CSimpleStringA::Format("%d", si.wProcessorRevision)));
- map_cpuInfo.insert(std::make_pair("dwNumberOfProcessors", CSimpleStringA::Format("%d", si.dwNumberOfProcessors)));
- m_cpuInfo = generateJsonStr(map_cpuInfo).second.c_str();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutCPU")(m_cpuInfo.GetData());
- #else
- ifstream cpuinfo("/proc/cpuinfo");
- if (!cpuinfo.is_open()) {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("opening /proc/cpuinfo error:%s", strerror(GetLastErrorRVC()));
- return;
- }
- std::map<std::string, std::string> map_cpuInfo;
- string line;
- while (std::getline(cpuinfo, line)) {
- auto elems = SP::Utility::Split(line, ':');
- if (elems.size() > 1) {
- map_cpuInfo[SP::Utility::ToTrim(elems[0])] = SP::Utility::ToTrim(elems[1]);
- if (line.find("CPU revision") != string::npos)
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutCPU")(generateJsonStr(map_cpuInfo).second.c_str());
- }
- }
- #endif //RVC_OS_WIN
- return;
- }
- void CHealthManagerFSM::QueryAndSendDisplayInfo()
- {
- std::map<std::string, std::string> primaryInfo;
- std::map<std::string, std::string> secondaryInfo;
- std::map<std::string, std::string> displayInfo;
- #if defined(RVC_OS_WIN)
- DISPLAY_DEVICE devDevice;
- devDevice.cb = sizeof(DISPLAY_DEVICE);
- //获取系统中的所有显示设备
- EnumDisplayDevices(NULL, ENUM_CURRENT_SETTINGS, &devDevice, 0);
- bool bPrimary = false;
- // 遍历显示设备列表
- for (int i = 0; EnumDisplayDevices(NULL, i, &devDevice, 0) != 0; i++)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("devDevice.StateFlags:%d", devDevice.StateFlags);
- bPrimary = false;
- //if connected
- if (devDevice.StateFlags & DISPLAY_DEVICE_ACTIVE)
- {
- if (devDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
- bPrimary = true;
- // 获取显示设备的分辨率
- DEVMODE devMode;
- devMode.dmSize = sizeof(DEVMODE);
- EnumDisplaySettings(devDevice.DeviceName, ENUM_CURRENT_SETTINGS, &devMode);
- if (bPrimary)
- {
- primaryInfo["dmDeviceName"] = CSimpleStringA::Format("%s", devMode.dmDeviceName);
- primaryInfo["dmPelsWidth"] = CSimpleStringA::Format("%d", devMode.dmPelsWidth);
- primaryInfo["dmPelsHeight"] = CSimpleStringA::Format("%d", devMode.dmPelsHeight);
- primaryInfo["dmDisplayOrientation"] = CSimpleStringA::Format("%d", devMode.dmDisplayOrientation);
- primaryInfo["dmDisplayFixedOutput"] = CSimpleStringA::Format("%d", devMode.dmDisplayFixedOutput);
- primaryInfo["dmPosition.x"] = CSimpleStringA::Format("%d", devMode.dmPosition.x);
- primaryInfo["dmPosition.y"] = CSimpleStringA::Format("%d", devMode.dmPosition.y);
- }
- else
- {
- secondaryInfo["dmDeviceName"] = CSimpleStringA::Format("%s", devMode.dmDeviceName);
- secondaryInfo["dmPelsWidth"] = CSimpleStringA::Format("%d", devMode.dmPelsWidth);
- secondaryInfo["dmPelsHeight"] = CSimpleStringA::Format("%d", devMode.dmPelsHeight);
- secondaryInfo["dmDisplayOrientation"] = CSimpleStringA::Format("%d", devMode.dmDisplayOrientation);
- secondaryInfo["dmDisplayFixedOutput"] = CSimpleStringA::Format("%d", devMode.dmDisplayFixedOutput);
- secondaryInfo["dmPosition.x"] = CSimpleStringA::Format("%d", devMode.dmPosition.x);
- secondaryInfo["dmPosition.y"] = CSimpleStringA::Format("%d", devMode.dmPosition.y);
- }
- }
- }
- displayInfo["PrimaryText"] = generateJsonStr(primaryInfo).second.c_str();
- displayInfo["SecondaryText"] = generateJsonStr(secondaryInfo).second.c_str();
- #else
- CSimpleStringA runInfoPath, csDNSKeyword;
- ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
- if (eErr != Error_Succeed) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetPath runinfo error=%d.", eErr);
- return;
- }
- runInfoPath = runInfoPath + SPLIT_SLASH_STR + "runcfg" + SPLIT_SLASH_STR + "monitor";
- std::string sucContent, failedContent;
- CSimpleStringA strCmd;
- strCmd = CSimpleStringA::Format("xrandr | grep \" connected\" >%s", runInfoPath.GetData());
- bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
- if (!ret)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("failedContent:%s", failedContent.c_str());
- return;
- }
- ifstream is;
- is.open(runInfoPath.GetData(), ios::binary);
- if (!is.is_open())
- {
- DWORD dwErr = GetLastError();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("open %s file failed. [%d]", runInfoPath.GetData(), dwErr);
- return;
- }
- string line;
- while (!is.eof()) {
- getline(is, line);
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("line:%s", line.c_str());
- if (line.find("connected") != string::npos)
- {
- if (line.find("primary") != string::npos)
- displayInfo["PrimaryText"] = line;
- else
- displayInfo["SecondaryText"] = line;
- }
- }
- #endif
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InfoAboutDisplay")(generateJsonStr(displayInfo).second.c_str());
- }
- string CHealthManagerFSM::QueryHarddiskInfo()
- {
- CSimpleStringA csRunCfgPath("");
- GetEntityBase()->GetFunction()->GetPath("RunCfg", csRunCfgPath);
- csRunCfgPath = csRunCfgPath + SPLIT_SLASH_STR + "AccessAuthorization.ini";
- char tmp[256];
- memset(tmp, 0, 256);
- inifile_read_str_s("system", "info", "", tmp, 255, csRunCfgPath);
- auto elems = SP::Utility::Split(tmp, '|');
- if (elems.size() > 2) {
- return SP::Utility::ToTrim(elems[2]);
- }
- return "";
- }
- void CHealthManagerFSM::CheckIfPinPadOK()
- {
- //to check if PinPad is ok, wait for 5 seconds,then go on
- //RVC.CardStore have no PinPad
- if (m_sysInfo.strMachineType.Compare("RVC.CardStore", true) == 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501A3")("RVC.CardStore have no PinPad");
- return;
- }
- ULONGLONG ullWaitStart, ullWaitEnd;
- ullWaitEnd = ullWaitStart = SP::Module::Comm::RVCGetTickCount();
- PinPadService_ClientBase* pClient = new PinPadService_ClientBase(this->m_pEntity);
- if (pClient != NULL)
- {
- ErrorCodeEnum eErrCode = pClient->Connect();
- if (eErrCode == Error_Succeed)
- {
- do {
- PinPadService_GetDevInfo_Req reqQ;
- PinPadService_GetDevInfo_Ans ansQ;
- eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 1000);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
- ullWaitEnd = SP::Module::Comm::RVCGetTickCount();
- if (eErrCode == Error_DevNotAvailable)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("pinpad open failed");
- break;
- }
- else if (eErrCode == Error_Succeed)
- break;
- if (ullWaitEnd - ullWaitStart > m_maxWaitForPinPad)
- break;
- Sleep(500);
- } while (true);
- }
- else
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("connect to pinpad failed.error code:%d", eErrCode);
- }
- else
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("new PinPadService_ClientBase failed.GetLastError:%d", GetLastErrorRVC());
- m_ullWaitForPinPad = ullWaitEnd - ullWaitStart;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501A3").setCostTime(m_ullWaitForPinPad)("finish (or time out) check PinPad");
- return;
- }
- bool CHealthManagerFSM::CheckIfAccessAuthSuc()
- {
- if (m_iAccessAuth == VtmLoad_AccessAuth_Suc)
- return true;
- CSimpleStringA csTmpTS("");
- GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTmpTS);
- if (csTmpTS.Compare("A") == 0)
- return true;
- else
- return false;
- }
|