12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310 |
- #include "stdafx.h"
- #include <fstream>
- #include <string>
- #include <algorithm>
- #include <regex>
- #include "SpUtility.h"
- #include "iniutil.h"
- #include "fileutil.h"
- #if defined(RVC_OS_WIN)
- #include <TlHelp32.h>
- #include <iphlpapi.h>
- #include <ws2tcpip.h>
- #include <Winsock2.h>
- #include <io.h>
- #include "CSystemStatus.h"
- #else
- #include <unistd.h>
- #include <fcntl.h>
- #include <errno.h>
- #endif //RVC_OS_WIN
- #include <winpr/sysinfo.h>
- #include "mod_healthmanager.h"
- #include "publicFunExport.h"
- using namespace std;
- const int MAX_AYSNC_TIMEOUT = 60000;
- const int MAX_IGNORE_TIMEOUT = 100;
- 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;
- termInfo["OSTime"] = _itoa(m_elapseTimeFromOSStart, xOSTime, 10);
- termInfo["elapseTime"] = _itoa(elapseTimeTemp, elapseTime, 10);
-
- 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 (ExistsFileA(csFileName)) {
- 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 = {};
- GetLocalTime(&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(errno));
- 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", GetLastError());
- 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;
- }
|