#include "stdafx.h" #include #include "VtmLoaderFSM.h" #include "VtmLoader_UserCode.h" #include "EventCode.h" #if defined(RVC_OS_WIN) #include #include "..\RvcVer.h" #else #include #include #include #include "RestfulFunc.h" #endif //RVC_OS_WIN #include "../mod_healthmanager/HealthManager_client_g.h" #include "../mod_pinpad/PinPad_client_g.h" #include "../mod_cardissuer/CardIssuer_client_g.h" #include "../mod_IDCertificate/IDCertificate_client_g.h" #include "../mod_HSPScanner/HSPScanner_client_g.h" #include "../mod_ContactlessCard/ContactlessCard_client_g.h" #include "../mod_FingerPrint/FingerPrint_client_g.h" #include "../mod_gpio/Gpio_client_g.h" using namespace HealthManager; using namespace PinPad; using namespace CardIssuer; using namespace IDCertificate; using namespace HSPScanner; using namespace ContactlessCard; using namespace FingerPrint; using namespace Gpio; using namespace SP::Module::Net; #define ALLOW_MULTI_NETWORKD_CARDS 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, }; struct callback_entry : public IReleasable { virtual ~callback_entry() {} CSimpleStringA EntityName; union { void* pRawData; int state; }; int op; ErrorCodeEnum ErrorResult; }; DWORD tokenUpdate(void* param) { CVtmLoaderFSM* t_entity = (CVtmLoaderFSM*)param; DWORD lastUpdateTime = 0; // 获取当前时间(以毫秒为单位) while (true) { DWORD currentTime = SP::Module::Comm::RVCGetTickCount(); // 获取当前时间 DWORD elapsedTime = currentTime - lastUpdateTime; // 计算与上次更新的时间间隔(毫秒) if (elapsedTime >= (t_entity->m_refreshWaitSec * 1000)) { // 如果距离上次更新时间已经超过了指定的刷新间隔 if (t_entity->refreshToken()) { // 更新成功,更新上次更新时间 lastUpdateTime = currentTime; } else { // 更新失败,可以处理一些错误逻辑 } } // 等待一段时间后再次检查 Sleep(20000); // 20秒 } return 0; } DWORD checkUrlActive(LPVOID param) { CVtmLoaderFSM* entityInfo = (CVtmLoaderFSM*)param; CSmartPointer pConfig; CSimpleString t_endpoint, t_materialUrl; CSimpleString errMsg; Sleep(60 * 1000); long srcClo = clock(); entityInfo->GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, pConfig); do { if (Error_Succeed != pConfig->ReadConfigValue("Common", "SendEndpoint", t_endpoint)) { errMsg = "checkUrlActive read Common::SendEndpoint err"; break; } if (t_endpoint.GetLength() == 0) { errMsg = "checkUrlActive endpoint len=0 err"; break; } //if (!checkHttpActive(t_endpoint.GetData())) // errMsg.Append(CSimpleString::Format("checkHttpActive endpoint err:%s !", t_endpoint.GetData())); //else if((clock() - srcClo) > 3000) // errMsg.Append(CSimpleString::Format("checkHttpActive endpoint too long:%d !", clock() - srcClo)); srcClo = clock(); } while (false); if (errMsg.GetLength() > 0) LogWarn(SeverityLevelEnum::Severity_Middle, Error_Unexpect, WARN_SendEndpoint_URL_ERR, errMsg.GetData()); //do get upload log Info for a while while (true) { if (entityInfo->m_uploadLogInfo_waitSec <= 0) break; Sleep(entityInfo->m_uploadLogInfo_waitSec * 1000); unsigned long t_upload_TerminalSys_Suc, t_upload_TerminalUser_Suc, t_upload_BussinessSys_Suc, t_upload_BussinessUser_Suc, t_upload_beidou_Suc; unsigned long t_upload_TerminalSys_Err, t_upload_TerminalUser_Err, t_upload_BussinessSys_Err, t_upload_BussinessUser_Err, t_upload_beidou_Err; entityInfo->GetEntityBase()->GetFunction()->GetPrivilegeFunction()->GetSendLogInfo(&t_upload_TerminalSys_Suc, &t_upload_TerminalUser_Suc, &t_upload_BussinessSys_Suc, &t_upload_BussinessUser_Suc, &t_upload_beidou_Suc, &t_upload_TerminalSys_Err, &t_upload_TerminalUser_Err, &t_upload_BussinessSys_Err, &t_upload_BussinessUser_Err, &t_upload_beidou_Err); LogWarn(SeverityLevelEnum::Severity_Low, Error_Trace, WARN_SendEndpoint_LOG_INFO, CSimpleString::Format("checkUrlActive::GetSendLogInfo, TS_Suc:%d, TU_Suc:%d, BS_Suc:%d, BU_Suc:%d, beidou_Suc:%d, TS_Err:%d, TU_Err:%d, BS_Err:%d, BU_Err:%d, beidou_Err:%d" , t_upload_TerminalSys_Suc, t_upload_TerminalUser_Suc, t_upload_BussinessSys_Suc, t_upload_BussinessUser_Suc, t_upload_beidou_Suc, t_upload_TerminalSys_Err, t_upload_TerminalUser_Err, t_upload_BussinessSys_Err, t_upload_BussinessUser_Err, t_upload_beidou_Err).GetData()); } return 0; } DWORD AlarmVersionErr(LPVOID param) { CVtmLoaderFSM* cur = (CVtmLoaderFSM*)param; Sleep(5000);//wait mod_alarm start LogWarn(Severity_Middle, Error_Bug, VtmLoader_DETECT_VERSION_ERR, cur->m_verShowMsg.GetData()); return 0; } bool CVtmLoaderFSM::refreshToken() { CSimpleString oldToken, newToken; ErrorCodeEnum eErr = Error_Succeed; if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateToken(oldToken, newToken))) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F02")("Get center setting, TryUpdateToken failed:0x%x", eErr); LogWarn(Severity_High, Error_Unexpect, VtmLoader_GetConfig_UpdateToken_Failed, CSimpleStringA::Format("拉取配置失败:0x%x(%s)", eErr, SpStrError(eErr)).GetData()); return false; } return true; } CVtmLoaderFSM::CVtmLoaderFSM() { m_refreshWaitSec = 1200; m_uploadLogInfo_waitSec = 3600; m_defaultSystemId = "LR04.02_Terminal"; m_iCanIgnoreAddrDetect = 0; m_ullMaxAddrDetectTime = 10*60*1000;//10 minutes m_iDetectInterval = 5000; m_terminalNoFromWeb = m_verShowMsg = ""; } CVtmLoaderFSM::~CVtmLoaderFSM() { } ErrorCodeEnum CVtmLoaderFSM::OnInit() { AddStateHooker(this); GetEntityBase()->GetFunction()->GetSystemStaticInfo(m_sysInfo); return Error_Succeed; } ErrorCodeEnum CVtmLoaderFSM::OnExit() { RemoveStateHooker(this); return Error_Succeed; } void CVtmLoaderFSM::OnStateTrans(int iSrcState, int iDstState) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("state change from %s to %s", GetStateName(iSrcState), GetStateName(iDstState)); } void CVtmLoaderFSM::s0_on_entry() { LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "开始网卡、网络连通性检查"); NetWorkCheckAndGetSettingTask* task = new NetWorkCheckAndGetSettingTask(this); GetEntityBase()->GetFunction()->PostThreadPoolTask(task); } void CVtmLoaderFSM::s0_on_exit() { } unsigned int CVtmLoaderFSM::s0_on_event(FSMEvent* pEvt) { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("s0_on_event,pEvt:%d,pEvt->param1:%d", pEvt->iEvt, pEvt->param1); switch (pEvt->iEvt) { case USER_EVT_NetworkCheck_Passed: pEvt->SetHandled(); return pEvt->param1; case USER_EVT_CHECK_DEVICE_ENTITY: pEvt->SetHandled(); { CheckDeviceEntityEvent* cdee = dynamic_cast(pEvt); CheckDeviceEntityTask* pTask = new CheckDeviceEntityTask(this); pTask->ctx = cdee->ctx; GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask); } break; case USER_EVT_SAVE_TERMINALNO: pEvt->SetHandled(); { SaveTerminalNoEvent* stne = dynamic_cast(pEvt); SaveTerminalNoTask* pTask = new SaveTerminalNoTask(this); pTask->ctx = stne->ctx; GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask); } break; default: break; } return 0; } void CVtmLoaderFSM::ShowEntityBootFailedAtFront(LPCTSTR lpcszEntityName, ErrorCodeEnum bootFailedResult, bool isBlock) { #if defined(RVC_OS_LINUX) CEntityLastErrorInfo errInfo = {}; ErrorCodeEnum errCode = GetEntityBase()->GetFunction()->GetEntityLastError(lpcszEntityName, errInfo); CSimpleStringA strErrMsg(true); if (!errInfo.strErrMsg.IsNullOrEmpty()) { strErrMsg = CSimpleStringA::Format("%s:%s", lpcszEntityName, (LPCTSTR)errInfo.strErrMsg); } else { strErrMsg = CSimpleStringA::Format("%s模块初始化失败: %s", lpcszEntityName, (LPCTSTR)SpStrError(bootFailedResult)); } if (CSimpleStringA(lpcszEntityName).Compare("SIPPhone", true) == 0) { GetEntityBase()->GetFunction()->SetSysVar("AuthErrMsg", strErrMsg.GetData());//实体启动失败保存到错误页字段 } if (isBlock) { SP::Module::Comm::LogErrorNotiyStruct notifyItem(bootFailedResult, 0); SP::Module::Comm::LogNotiyMessageStruct notifyMsg(strErrMsg); notifyItem.Notify(notifyMsg); } else { LogError(Severity_High, bootFailedResult, 0, strErrMsg); } #endif //RVC_OS_LINUX } //CoreBoot void CVtmLoaderFSM::s1_on_entry() { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("s1_on_entry"); ErrorCodeEnum eErrCode; CSmartPointer spEntityFunction = GetEntityBase()->GetFunction(); CSmartPointer pFuncPrivilege = spEntityFunction.ConvertCase(); bool bAsync = false; m_eStage = LOADSTAGE_COREBOOT; int ret = 0; map::iterator it; //start entity vector::iterator vIt; if (m_coreBootOpt.size() == 0) goto COREBOOT_FINISH; char startMsg[128]; for (vIt = m_vCoreBoot.begin(); vIt != m_vCoreBoot.end(); ++vIt) { CSmartPointer spWait;//oilyang 20160325 see the following comment it = m_coreBootOpt.find(*vIt); if (it == m_coreBootOpt.end()) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cannot find %s", (LPCSTR)* vIt); continue; } DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start,%s,%d", (LPCSTR)it->first, it->second.loadOpt); CEntityRunInfo entRunInfo; ErrorCodeEnum errCode = spEntityFunction->GetEntityRunInfo(it->first, entRunInfo); if (errCode == Error_Succeed && entRunInfo.eState == EntityState_Idle) { it->second.eResult = LOADING_SUCCEED; ret = CheckLoadResult(LOADSTAGE_COREBOOT); if (ret == 0 || ret == 2) goto COREBOOT_FINISH; else continue; } ZeroMemory(startMsg, 128); //sprintf(startMsg, "正在启动实体%s...", it->first.GetData()); //GetEntityBase()->GetFunction()->ShowStartupInfo(startMsg); switch (it->second.loadOpt) { case LOADOPT_IGNORE: { pFuncPrivilege->StartEntity(it->first, NULL, spWait); if (spWait != NULL) spWait->WaitAnswer(MAX_IGNORE_TIMEOUT);//oilyang 20160325 the null pointer it->second.eResult = LOADING_SUCCEED; ret = CheckLoadResult(LOADSTAGE_COREBOOT); if (ret == 0 || ret == 2) goto COREBOOT_FINISH; } break; case LOADOPT_ASYNC_VERIFY: errCode = AsyncStartEntity(it->first, NULL, NULL); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("AsyncStartEntity:%d", errCode); bAsync = true; break; case LOADOPT_SYNC_VERIFY: { pFuncPrivilege->StartEntity(it->first, NULL, spWait); if (spWait != NULL) errCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("(coreboot)sync...%d", errCode); if (errCode == Error_Succeed) it->second.eResult = LOADING_SUCCEED; else if (errCode == Error_TimeOut) it->second.eResult = LOADING_TIMEOUT; else it->second.eResult = LOADING_FAILED; if (errCode != Error_Succeed) { return; #if defined(RVC_OS_LINUX) ShowEntityBootFailedAtFront(it->first, errCode); return; #endif //RVC_OS_LINUX } else ret = CheckLoadResult(LOADSTAGE_COREBOOT); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s1 check ret %d", ret); if (ret == 0 || ret == 2) goto COREBOOT_FINISH; } break; default: break; } } COREBOOT_FINISH: if (!bAsync) { FSMEvent* e = new FSMEvent(USER_EVT_COREBOOT_FINISHED); e->param1 = ret; PostEventFIFO(e); } else { ret = CheckLoadResult(LOADSTAGE_COREBOOT); if (ret == 0 || ret == 2) { FSMEvent* e = new FSMEvent(USER_EVT_COREBOOT_FINISHED); e->param1 = ret; PostEventFIFO(e); } } return; } void CVtmLoaderFSM::s1_on_exit() { LOG_FUNCTION(); } unsigned int CVtmLoaderFSM::s1_on_event(FSMEvent* pEvt) { LOG_FUNCTION(); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s1 evt %d", pEvt->iEvt); switch (pEvt->iEvt) { case USER_EVT_COREBOOT_FINISHED: pEvt->SetHandled(); if (pEvt->param1 == 2) { #if defined(RVC_OS_LINUX) ShowEntityBootFailedAtFront(m_csErrEntity, Error_InvalidState); #endif } return pEvt->param1; break; default: break; } return 0; } //SafeLoad void CVtmLoaderFSM::s2_on_entry() { LOG_FUNCTION(); LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "CoreBoot 阶段实体加载完成"); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F14")("Stage Coreboot have done."); ULONGLONG dwElapse = SP::Module::Comm::RVCGetTickCount();//使用机器启动时间秒数 DWORD elapseTimeTemp = dwElapse / 1000; CSimpleStringA xMsg = CSimpleStringA::Format("{\"Decripstion\":\"Enter safeload state.\",\"version\":\"%s\",\"elapseTime\":\"%d\"}", m_sysInfo.InstallVersion.ToString().GetData(), elapseTimeTemp); //LogWarn(Severity_Low, Error_Unexpect, HealthManager_UserErrorCode_Enter_SafeLoad_State, xMsg.GetData()); if (!VerifyVer()) return; bool bAsync = false; m_eStage = LOADSTAGE_SAFELOAD; int ret = 0; map::iterator it; CSmartPointer pFunc = GetEntityBase()->GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); ErrorCodeEnum errCode; vector::iterator vIt; if (m_safeLoadOpt.size() == 0) goto SAFELOAD_FINISH; char startMsg[128]; for (vIt = m_vSafeLoad.begin(); vIt != m_vSafeLoad.end(); ++vIt) { CSmartPointer spWait; it = m_safeLoadOpt.find(*vIt); if (it == m_safeLoadOpt.end()) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cannot find %s", (LPCSTR)* vIt); continue; } CEntityRunInfo entRunInfo; errCode = pFunc->GetEntityRunInfo(it->first, entRunInfo); if (errCode == Error_Succeed && entRunInfo.eState == EntityState_Idle) { it->second.eResult = LOADING_SUCCEED; ret = CheckLoadResult(LOADSTAGE_SAFELOAD); if (ret == 0 || ret == 2) goto SAFELOAD_FINISH; else continue; } DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start %s,%d", (LPCTSTR)it->first, it->second.loadOpt); switch (it->second.loadOpt) { case LOADOPT_IGNORE: { pFuncPrivilege->StartEntity(it->first, NULL, spWait); if (spWait != NULL) spWait->WaitAnswer(MAX_IGNORE_TIMEOUT); it->second.eResult = LOADING_SUCCEED; ret = CheckLoadResult(LOADSTAGE_SAFELOAD); if (ret == 0 || ret == 2) goto SAFELOAD_FINISH; } break; case LOADOPT_ASYNC_VERIFY: AsyncStartEntity(it->first, NULL, NULL); bAsync = true; break; case LOADOPT_SYNC_VERIFY: { ZeroMemory(startMsg, 128); sprintf(startMsg, "正在启动实体%s...", it->first.GetData()); GetEntityBase()->GetFunction()->ShowStartupInfo(startMsg); pFuncPrivilege->StartEntity(it->first, NULL, spWait); if (spWait != NULL) errCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("sync...%d", errCode); if (errCode == Error_Succeed) { it->second.eResult = LOADING_SUCCEED; } else if (errCode == Error_TimeOut) it->second.eResult = LOADING_TIMEOUT; else it->second.eResult = LOADING_FAILED; if (it->second.eResult != Error_Succeed) { char tmp[128] = { 0 }; if (it->first.Compare("SIPPhone", true) == 0) { if (LOADING_TIMEOUT == it->second.eResult) { sprintf(tmp, "实体 %s 启动超时(%d),请尝试重启应用解决", it->first.GetData(), it->second.eResult); } else { sprintf(tmp, "实体 %s 启动失败(%d),识别不到声卡,请尝试重启计算机解决,多次无效后请联系厂商处理", it->first.GetData(), it->second.eResult); } } else { sprintf(tmp, "实体 %s 启动失败 %d", it->first.GetData(), it->second.eResult); } #if defined(RVC_OS_WIN) GetEntityBase()->GetFunction()->ShowFatalError(tmp); GetEntityBase()->GetFunction()->SetSysVar("AuthErrMsg", tmp);//实体启动失败保存到错误页字段 #else ShowEntityBootFailedAtFront(it->first, errCode); #endif DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("启动失败:%s", tmp); m_csErrEntity = m_csErrEntity + "|" + it->first; FSMEvent* e = new FSMEvent(USER_EVT_SAFELOAD_FINISHED); e->param1 = 2;//"SYNC START" enity started failed. PostEventFIFO(e); return; } //if (errCode != Error_Succeed) // return; //else ret = CheckLoadResult(LOADSTAGE_SAFELOAD); if (ret == 0 || ret == 2) goto SAFELOAD_FINISH; } break; default: break; } } SAFELOAD_FINISH: if (!bAsync) { FSMEvent* e = new FSMEvent(USER_EVT_SAFELOAD_FINISHED); e->param1 = ret; PostEventFIFO(e); } else { ret = CheckLoadResult(LOADSTAGE_SAFELOAD); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s2 %d", ret); if (ret == 0 || ret == 2) { FSMEvent* e = new FSMEvent(USER_EVT_SAFELOAD_FINISHED); e->param1 = ret; PostEventFIFO(e); } } SAFELOAD_END: return; } void CVtmLoaderFSM::s2_on_exit() { LOG_FUNCTION(); } unsigned int CVtmLoaderFSM::s2_on_event(FSMEvent* pEvt) { LOG_FUNCTION(); int ret = 0; DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s2 event %d,%d", pEvt->iEvt, pEvt->param1); switch (pEvt->iEvt) { case USER_EVT_SAFELOAD_FINISHED: { pEvt->SetHandled(); //oiltmp //according to the system varible TerminalState to do sth. //Configed //Breakdown //Blocking //Authentication { if (pEvt->param1 == 0) { //initializer if configured CSimpleStringA csTermStage(""); ErrorCodeEnum eErrCode; eErrCode = GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTermStage); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("after safeload to get termstage %s", (LPCTSTR)csTermStage); if (csTermStage == "B" || csTermStage == "N") return 1; } else if (pEvt->param1 == 2) { #if defined(RVC_OS_LINUX) ShowEntityBootFailedAtFront(m_csErrEntity, Error_InvalidState); #endif ret = 2; } } //Unsubscrible } break; case USER_EVT_SAFELOAD_EXMINE_FINISHED: if (pEvt->param1 == 0) ret = 0; //do something else oiltmp pEvt->SetHandled(); break; case USER_EVT_ACCESSAUTH_FINISHED: pEvt->SetHandled(); ret = pEvt->param1; break; default: break; } return ret; } //Operating void CVtmLoaderFSM::s3_on_entry() { LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "SafeLoad 阶段实体加载完成"); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F15")("Stage Safeload have done."); Sleep(m_sleepEnterOpMS); bool bAsync = false; m_eStage = LOADSTAGE_OPERATING; int ret = 0; map::iterator it; CSmartPointer pFunc = GetEntityBase()->GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); //start entity ErrorCodeEnum errCode; vector::iterator vIt; if (m_operatingOpt.size() == 0) goto OPERATING_FINISH; char startMsg[128]; for (vIt = m_vOperating.begin(); vIt != m_vOperating.end(); ++vIt) { CSmartPointer spWait; it = m_operatingOpt.find(*vIt); if (it == m_operatingOpt.end()) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cannot find %s", (LPCSTR)* vIt); continue; } CEntityRunInfo entRunInfo; errCode = pFunc->GetEntityRunInfo(it->first, entRunInfo); if (errCode == Error_Succeed && entRunInfo.eState == EntityState_Idle) { it->second.eResult = LOADING_SUCCEED; ret = CheckLoadResult(LOADSTAGE_OPERATING); if (ret == 0 || ret == 2) goto OPERATING_FINISH; else continue; } DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("op start %s,%d", (LPCTSTR)it->first, it->second.loadOpt); switch (it->second.loadOpt) { case LOADOPT_IGNORE: { pFuncPrivilege->StartEntity(it->first, NULL, spWait); if (spWait != NULL) spWait->WaitAnswer(MAX_IGNORE_TIMEOUT); it->second.eResult = LOADING_SUCCEED; ret = CheckLoadResult(LOADSTAGE_OPERATING); if (ret == 0 || ret == 2) goto OPERATING_FINISH; } break; case LOADOPT_ASYNC_VERIFY: errCode = AsyncStartEntity(it->first, NULL, NULL); bAsync = true; break; case LOADOPT_SYNC_VERIFY: { ZeroMemory(startMsg, 128); sprintf(startMsg, "正在启动实体%s...", it->first.GetData()); GetEntityBase()->GetFunction()->ShowStartupInfo(startMsg); errCode = pFuncPrivilege->StartEntity(it->first, NULL, spWait); if (errCode == Error_Succeed) { if (spWait != NULL) errCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); } else { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("StartEntity %s failed(%d).", (LPCSTR)it->first, errCode); break; } if (errCode == Error_Succeed) it->second.eResult = LOADING_SUCCEED; else if (errCode == Error_TimeOut) it->second.eResult = LOADING_TIMEOUT; else it->second.eResult = LOADING_FAILED; if (it->second.eResult != Error_Succeed) { char tmp[128] = { 0 }; if (it->first.Compare("SIPPhone", true) == 0) { if (LOADING_TIMEOUT == it->second.eResult) { sprintf(tmp, "实体 %s 启动超时(%d),请尝试重启应用解决", it->first.GetData(), it->second.eResult); } else { sprintf(tmp, "实体 %s 启动失败(%d),识别不到声卡,请尝试重启计算机解决,多次无效后请联系厂商处理", it->first.GetData(), it->second.eResult); } } else { sprintf(tmp, "实体 %s 启动失败 %d", it->first.GetData(), it->second.eResult); } #if defined(RVC_OS_WIN) GetEntityBase()->GetFunction()->ShowFatalError(tmp); #else ShowEntityBootFailedAtFront(it->first, errCode); #endif DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("启动失败:%s", tmp); m_csErrEntity = m_csErrEntity + "|" + it->first; FSMEvent* e = new FSMEvent(USER_EVT_OPERATING_FINISHED); e->param1 = 2;//"SYNC START" enity started failed. PostEventFIFO(e); return; } if (errCode != Error_Succeed) return; else ret = CheckLoadResult(LOADSTAGE_OPERATING); if (ret == 0 || ret == 2) goto OPERATING_FINISH; } break; default: break; } } OPERATING_FINISH: DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s3 ret %d", ret); if (!bAsync) { FSMEvent* e = new FSMEvent(USER_EVT_OPERATING_FINISHED); e->param1 = ret; PostEventFIFO(e); } else { ret = CheckLoadResult(LOADSTAGE_OPERATING); if (ret == 0 || ret == 2) { FSMEvent* e = new FSMEvent(USER_EVT_OPERATING_FINISHED); e->param1 = ret; PostEventFIFO(e); } } return; } void CVtmLoaderFSM::s3_on_exit() { LOG_FUNCTION(); } unsigned int CVtmLoaderFSM::s3_on_event(FSMEvent* pEvt) { LOG_FUNCTION(); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s3(Operating) event %d,%d", pEvt->iEvt, pEvt->param1); int ret = 0; switch (pEvt->iEvt) { case USER_EVT_OPERATING_FINISHED: ret = pEvt->param1; if (ret == 2) { #if defined(RVC_OS_LINUX) ShowEntityBootFailedAtFront(m_csErrEntity, Error_InvalidState); #endif } pEvt->SetHandled(); break; default: break; } return ret; } //Idle(Operating finished) void CVtmLoaderFSM::s4_on_entry() { LOG_FUNCTION(); LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "Operating 阶段实体加载完成"); //oiltmp wait for analyse progress, then change to app log format LogWarn(Severity_Low, Error_Succeed, VtmLoader_NetCard_Cost, CSimpleStringA::Format("%d", m_ullNetCardCost).GetData()); LogWarn(Severity_Low, Error_Succeed, VtmLoader_NetworkDetect_Cost, CSimpleStringA::Format("%d", m_ullNetDetectCost).GetData()); LogWarn(Severity_Low, Error_Succeed, VtmLoader_GetConfig_Cost, CSimpleStringA::Format("%d", m_ullGetConfigCost).GetData()); LogWarn(Severity_Low, Error_Succeed, VtmLoader_EntityLoad_Cost, CSimpleStringA::Format("%d", (SP::Module::Comm::RVCGetTickCount() - m_ullEntityLoadStart)/1000).GetData()); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F16")("Stage Operating have done."); NoticeEntityLoadTask* pTask = new NoticeEntityLoadTask(this,Event_VtmLoader_EntityLoad_Finished); GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask); } void CVtmLoaderFSM::s4_on_exit() { LOG_FUNCTION(); } unsigned int CVtmLoaderFSM::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) { default: break; } return 0; } //Fault void CVtmLoaderFSM::s5_on_entry() { LOG_FUNCTION(); NoticeEntityLoadTask* pTask = new NoticeEntityLoadTask(this, Event_VtmLoader_EntityLoad_Failed); GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask); CSmartPointer spConfigCen, spConfigRun; ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen); eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfigRun); int failTimes = 0, maxFailTimes = 2; do { int value(0); spConfigCen->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "MaxFailTimes", value); if (value > 0) { maxFailTimes = value; } } while (false); spConfigRun->ReadConfigValueInt("Run", "FailTimes", failTimes); failTimes++; //LogWarn(Severity_High, Error_Unexpect, LOG_ERR_HEALTH_FAILED, "HealthManager failed."); //oilyang@20210930 add to call for Close Page //GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "C"); //if (failTimes > maxFailTimes) //{ // //LogEvent(Severity_Middle, LOG_EVT_HEADLIGHT_RED_ON, "设备故障"); // eErr = GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "D"); // if (eErr != Error_Succeed) { // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("set termstage D failed (%d).", eErr); // } // else { // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Set TerminalStage D."); // } //} //else //{ // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("have failed %d times.", failTimes); // spConfigRun->WriteConfigValueInt("Run", "FailTimes", failTimes); // eErr = GetEntityBase()->GetFunction()->SetSysVar("RunState", "F"); // if (eErr != Error_Succeed) // { // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("set RunState failed (%d).", eErr); // } //} } void CVtmLoaderFSM::s5_on_exit() { LOG_FUNCTION(); } unsigned int CVtmLoaderFSM::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_ACCESSAUTH_FINISHED: pEvt->SetHandled(); if (pEvt->param1 == 1) { return 1; } break; default: break; } return 0; } BOOL CVtmLoaderFSM::DetectNetworkLegality(CSimpleStringA& strInfo) { BOOL result(TRUE); strInfo.Clear(); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Detect network legality..."); BOOL fLocalLANConnected(FALSE); unsigned int curTimes = 1; const unsigned int maxTimes = 3; do { CAutoArray netList; if (SP::Module::Net::GetINETMacAddresses(netList) == Error_Succeed) { for (int i = 0; i < netList.GetCount(); i++) { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("interface(%d):%s", i, netList[i].description.c_str()); DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ip(%d):%s", i, netList[i].ip.c_str()); DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("mac(%d):%s", i, netList[i].mac.c_str()); DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("operStatus(%d):%d", i, netList[i].operStatus); DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("type(%d):%d", i, netList[i].type); //if (netList[i].type == IF_TYPE_ETHERNET_CSMACD && netList[i].operStatus == IfOperStatusUp) if (netList[i].operStatus == 1)//oiltest { fLocalLANConnected = TRUE; break; } } } Sleep(500); curTimes++; } while (curTimes < maxTimes && !fLocalLANConnected); if (!fLocalLANConnected) { strInfo = "未检查到有网卡连接,请检查网络连接"; result = FALSE; } return result; } int CVtmLoaderFSM::NetWorkCheckAndGetSetting() { //检查网卡状态 DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to check network status"); CSimpleStringA strMsg(true), tmpTS("X"); //GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", tmpTS); int netcheckCount = 1; ULLINT ullTmpStart = SP::Module::Comm::RVCGetTickCount(); //for rvc.pad only if (!m_sysInfo.strTerminalID.IsNullOrEmpty() && m_sysInfo.strTerminalID.SubString(m_sysInfo.strTerminalID.GetLength() - 4, 1).Compare("5") == 0) DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s is pad,no network connection detect.", m_sysInfo.strTerminalID.GetData()); else { while (true) { if (!DetectNetworkLegality(strMsg)) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F10").setResultCode("RTA1F00")("can't find valid network interface"); LogWarn(Severity_High, Error_Unexpect, VtmLoader_UserCode_NetCard_UnAvaible, CSimpleStringA::Format("%s。%d 秒后自动重试(第%d次重试)。请检查网线是否插好、网络是否正常" , strMsg.GetData(), m_iDetectInterval / 1000, netcheckCount).GetData()); //if (tmpTS.Compare("E") != 0) //{ // GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "E"); // tmpTS = "E"; //} Sleep(5000); netcheckCount++; } else { m_ullNetCardCost = (SP::Module::Comm::RVCGetTickCount() - ullTmpStart) / 1000;//second LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "网卡状态正常"); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F10")("network interface ok."); break; } } ullTmpStart = SP::Module::Comm::RVCGetTickCount(); //检查网络连通性(网络连通性是否作为关键路径走配置,默认不是关键路径) if (!DetectHttpActive()) { //网络连通性检查未通过,提示确认网络后重启应用?界面加一个重启按钮? LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, "网络连通性检查失败,请检查网络"); return -1; } } DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F11")("connect to http(s) service ok."); m_ullNetDetectCost = (SP::Module::Comm::RVCGetTickCount() - ullTmpStart) / 1000;//second ToCheckIfInstalling(); ullTmpStart = SP::Module::Comm::RVCGetTickCount(); //拉取配置并通知提前启动的实体(Chromium) //重试5次,失败则放弃 int getRetry = 0; while(true) { if (GetConfig()) break; else { if (getRetry >= 5) return -2; getRetry++; Sleep(5000 * getRetry); } } m_ullGetConfigCost = (SP::Module::Comm::RVCGetTickCount() - ullTmpStart) / 1000;//second //加载实体列表 CSimpleStringA csTmpRootIni(""); if (!IsRootINIExist(csTmpRootIni)) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)(CSimpleStringA::Format("root.ini不存在(%s),Set TerminalStage N ", csTmpRootIni.GetData()).GetData()); GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "N"); } return EntityLoad(); } int CVtmLoaderFSM::EntityLoad() { //前提:收到了配置拉取完成的指令,才会进入到这里 //为了测试,假装已经拿到了集中配置 m_ullEntityLoadStart = SP::Module::Comm::RVCGetTickCount(); LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "开始加载实体"); CSmartPointer spConfigCen,spRunCfg; GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen); GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spRunCfg); CSimpleStringA csCoreBootList(true), csSafeLoadList(true), csOperatingList(true),csKeyCB("CoreBootList."),csKeySL("SafeLoadList."),csKeyOp("OperatingList."); spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), (csKeyCB + m_sysInfo.strMachineType).GetData(), csCoreBootList); spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), (csKeySL + m_sysInfo.strMachineType).GetData(), csSafeLoadList); spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), (csKeyOp + m_sysInfo.strMachineType).GetData(), csOperatingList); DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CoreBoot.EntityList.%s:%s", m_sysInfo.strMachineType.GetData(), csCoreBootList.GetData()); DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SafeLoad.EntityList.%s:%s", m_sysInfo.strMachineType.GetData(), csSafeLoadList.GetData()); DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Operating.EntityList.%s:%s", m_sysInfo.strMachineType.GetData(), csOperatingList.GetData()); //oiltmp 如果没有配置,则走默认配置 if (csCoreBootList.IsNullOrEmpty() || csCoreBootList.IndexOf("HealthManager") < 0 || csCoreBootList.IndexOf("AccessAuthorization") < 0 || csCoreBootList.IndexOf("UpgradeManager") < 0 || csCoreBootList.IndexOf("HeartBeat") < 0 || csCoreBootList.IndexOf("TokenKeeper") < 0 || csCoreBootList.IndexOf("ResourceWatcher") < 0 || csCoreBootList.IndexOf("EventConverter") < 0 || csCoreBootList.IndexOf("Alarm") < 0) { if (csCoreBootList.IsNullOrEmpty()) { LogWarn(Severity_High, Error_Unexpect, VtmLoader_CoreBootCfg_Err, "CoreBoot配置为空,请联系总行开发人员检查"); DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode("QLR040210F14").setResultCode("RTA1F05")("CoreBoot配置为空,请联系总行开发人员检查"); } else { LogWarn(Severity_High, Error_Unexpect, VtmLoader_CoreBootCfg_Err, CSimpleStringA::Format("CoreBoot配置异常,请联系总行开发人员检查(%s)", csCoreBootList.GetData()).GetData()); DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode("QLR040210F14").setResultCode("RTA1F05")(CSimpleStringA::Format("CoreBoot配置异常,请联系总行开发人员检查(%s)", csCoreBootList.GetData())); } //if have PinPad module //if (m_sysInfo.strMachineType.Compare("RVC.CardStore", true) == 0) // csCoreBootList = "HealthManager=0|TokenKeeper=0|Alarm=0|UpgradeManager=0|DeviceControl=0|ResourceWatcher=0|AccessAuthorization=0|HeartBeat=0|EventConverter=0|CenterSetting=0"; //else // csCoreBootList = "HealthManager=0|TokenKeeper=0|Alarm=0|UpgradeManager=0|DeviceControl=0|ResourceWatcher=0|AccessAuthorization=0|HeartBeat=0|EventConverter=0|CenterSetting=0|PinPad=0"; } spConfigCen->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "SleepEnterOpMS", m_sleepEnterOpMS); if (m_sleepEnterOpMS <= 0 || m_sleepEnterOpMS > 20000) m_sleepEnterOpMS = 1000;//default //save centersetting to runcfg for vtmloader. using it before download centersetting int iTmp = 0; if (spConfigCen->ReadConfigValueInt("Common", "CanIgnoreAddrDetect", iTmp) == Error_Succeed && iTmp > 0) spRunCfg->WriteConfigValueInt("Common", "CanIgnoreAddrDetect", iTmp); iTmp = 0; if (spConfigCen->ReadConfigValueInt("Common", "MaxAddrDetectTimes", iTmp) == Error_Succeed && iTmp > 0) spRunCfg->WriteConfigValueInt("Common", "MaxAddrDetectTimes", iTmp); iTmp = 0; if (spConfigCen->ReadConfigValueInt("Common", "AddrDetectInterval", iTmp) == Error_Succeed && iTmp > 0) spRunCfg->WriteConfigValueInt("Common", "AddrDetectInterval", iTmp); CSimpleStringA csTmpAddr(true); if (spConfigCen->ReadConfigValue("Common", "SettingDetectAddr", csTmpAddr) == Error_Succeed && !csTmpAddr.IsNullOrEmpty()) spRunCfg->WriteConfigValue("Common", "SettingDetectAddr", csTmpAddr.GetData()); csTmpAddr = ""; if (spConfigCen->ReadConfigValue("Common", "AccessAuthDetectAddr", csTmpAddr) == Error_Succeed && !csTmpAddr.IsNullOrEmpty()) spRunCfg->WriteConfigValue("Common", "AccessAuthDetectAddr", csTmpAddr.GetData()); //int count, cbNum, slNum, opNum; //count = cbNum = slNum = opNum = 0; CAutoArray arrCoreBoot; arrCoreBoot.Init(64); arrCoreBoot = csCoreBootList.Split('|'); for (int i = 0; i < arrCoreBoot.GetCount(); ++i) { CAutoArray arrEntity; arrEntity.Init(2); arrEntity = arrCoreBoot[i].Split('='); if (arrEntity.GetCount() < 2) break; if (arrEntity[0].Compare("VtmLoader", true) == 0 || arrEntity[0].Compare("Chromium", true) == 0 || arrEntity[0].Compare("GuiConsole", true) == 0) continue; m_vCoreBoot.push_back(arrEntity[0]); if (arrEntity[1].Compare("1") == 0) m_coreBootOpt[arrEntity[0]].loadOpt = LOADOPT_ASYNC_VERIFY; else if (arrEntity[1].Compare("2") == 0) m_coreBootOpt[arrEntity[0]].loadOpt = LOADOPT_SYNC_VERIFY; else m_coreBootOpt[arrEntity[0]].loadOpt = LOADOPT_IGNORE; m_coreBootOpt[arrEntity[0].GetData()].eResult = LOADING_INIT; //m_entityBootOpt[arrEntity[0].GetData()].initSn = cbNum; //cbNum++; } CAutoArray arrSafeLoad; arrSafeLoad.Init(64); arrSafeLoad = csSafeLoadList.Split('|'); for (int i = 0; i < arrSafeLoad.GetCount(); ++i) { CAutoArray arrEntity; arrEntity.Init(2); arrEntity = arrSafeLoad[i].Split('='); if (arrEntity.GetCount() < 2) break; if (arrEntity[0].Compare("VtmLoader", true) == 0 || arrEntity[0].Compare("Chromium", true) == 0 || arrEntity[0].Compare("GuiConsole", true) == 0) continue; //去重,防止前面已经加载了 if (find(m_vCoreBoot.begin(), m_vCoreBoot.end(), arrEntity[0].GetData()) != m_vCoreBoot.end()) continue; m_vSafeLoad.push_back(arrEntity[0].GetData()); if (arrEntity[1].Compare("1") == 0) m_safeLoadOpt[arrEntity[0]].loadOpt = LOADOPT_ASYNC_VERIFY; else if (arrEntity[1].Compare("2") == 0) m_safeLoadOpt[arrEntity[0]].loadOpt = LOADOPT_SYNC_VERIFY; else m_safeLoadOpt[arrEntity[0]].loadOpt = LOADOPT_IGNORE; m_safeLoadOpt[arrEntity[0].GetData()].eResult = LOADING_INIT; //m_safeLoadOpt[arrEntity[0].GetData()].initSn = slNum; //slNum++; } CAutoArray arrOperating; arrOperating.Init(64); arrOperating = csOperatingList.Split('|'); for (int i = 0; i < arrOperating.GetCount(); ++i) { CAutoArray arrEntity; arrEntity.Init(2); arrEntity = arrOperating[i].Split('='); if (arrEntity.GetCount() < 2) break; if (arrEntity[0].Compare("VtmLoader", true) == 0 || arrEntity[0].Compare("Chromium", true) == 0 || arrEntity[0].Compare("GuiConsole", true) == 0) continue; //去重,防止前面已经加载了 if (find(m_vCoreBoot.begin(), m_vCoreBoot.end(), arrEntity[0].GetData()) != m_vCoreBoot.end() || find(m_vSafeLoad.begin(), m_vSafeLoad.end(), arrEntity[0].GetData()) != m_vSafeLoad.end()) continue; m_vOperating.push_back(arrEntity[0].GetData()); if (arrEntity[1].Compare("1") == 0) m_operatingOpt[arrEntity[0]].loadOpt = LOADOPT_ASYNC_VERIFY; else if (arrEntity[1].Compare("2") == 0) m_operatingOpt[arrEntity[0]].loadOpt = LOADOPT_SYNC_VERIFY; else m_operatingOpt[arrEntity[0]].loadOpt = LOADOPT_IGNORE; m_operatingOpt[arrEntity[0].GetData()].eResult = LOADING_INIT; //m_operatingOpt[arrEntity[0].GetData()].initSn = opNum; //opNum++; } //oilyang if install VTM ,just wait for msg to start entity CSimpleStringA csTermStage(""); ErrorCodeEnum eErrCode; eErrCode = GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTermStage); DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("TerminalStage %s.", csTermStage.GetData()); if (csTermStage.Compare("N") == 0)//"N" for installing { //start UpgradeManager CSmartPointer pFuncPrivilege = m_pEntity->GetFunction().ConvertCase(); CSmartPointer spWait; eErrCode = pFuncPrivilege->StartEntity("UpgradeManager", NULL, spWait); if (eErrCode == Error_Succeed) { if (spWait != NULL) eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); } else { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity UpgradeManager failed(%d).", eErrCode); return -1; } eErrCode = pFuncPrivilege->StartEntity("HealthManager", NULL, spWait); if (eErrCode == Error_Succeed) { if (spWait != NULL) eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); } else { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity HealthManager failed(%d).", eErrCode); return -1; } eErrCode = pFuncPrivilege->StartEntity("InteractiveControl", NULL, spWait); if (eErrCode == Error_Succeed) { if (spWait != NULL) eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); } else { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity InteractiveControl failed(%d).", eErrCode); return -1; } //wait for all the things have beed done,then save TerminalNo to root.ini while (true) { m_hSaveTerminalNoVar.Wait(); return 1; } } return 0; } int CVtmLoaderFSM::CheckLoadResult(LoadStage eStage) { int ret = 0; CSimpleStringA csLogCode = "QLR040210F14"; map::iterator it; if (eStage == LOADSTAGE_COREBOOT) it = m_coreBootOpt.begin(); else if (eStage == LOADSTAGE_SAFELOAD) { it = m_safeLoadOpt.begin(); csLogCode = "QLR040210F15"; } else { it = m_operatingOpt.begin(); csLogCode = "QLR040210F16"; } while (1) { switch (it->second.loadOpt) { case LOADOPT_IGNORE: if (it->second.eResult == LOADING_INIT) return 1; break; case LOADOPT_ASYNC_VERIFY: case LOADOPT_SYNC_VERIFY: default: if (it->second.eResult == LOADING_INIT) return 3; else if (it->second.eResult != LOADING_SUCCEED) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode(csLogCode).setResultCode("RTA1F04")("%s start failed", m_csErrEntity); LogWarn(Severity_High, Error_Unexpect, VtmLoader_EntityLoad_Failed, CSimpleStringA::Format("实体%s加载失败,启动终止。请排查启动失败实体或重启应用", m_csErrEntity.GetData())); m_csErrEntity = m_csErrEntity + "|" + it->first; ret = 2; } break; } it++; if (eStage == LOADSTAGE_COREBOOT && it == m_coreBootOpt.end()) break; else if (eStage == LOADSTAGE_SAFELOAD && it == m_safeLoadOpt.end()) break; else if (eStage == LOADSTAGE_OPERATING && it == m_operatingOpt.end()) break; } return ret; } ErrorCodeEnum CVtmLoaderFSM::AsyncStartEntity(const char* entity_name, const char* cmdline, void* pData) { CSmartPointer pFunc = m_pEntity->GetFunction(); ErrorCodeEnum errCode; CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); if (pFuncPrivilege != NULL) { CSmartPointer spWait; errCode = pFuncPrivilege->StartEntity(entity_name, cmdline, spWait); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("AsyncStartEntity")("start entity %s", entity_name); 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; } } void CVtmLoaderFSM::OnAnswer(CSmartPointer pAsynWaitSp) { CSmartPointer spCallback; CSmartPointer pData; pAsynWaitSp->GetCallback(spCallback, pData); callback_entry* entry = dynamic_cast((IReleasable*)(pData.GetRawPointer())); entry->ErrorResult = pAsynWaitSp->AsyncGetAnswer(); callback_entry* new_entry = new callback_entry(); new_entry->EntityName = entry->EntityName; new_entry->ErrorResult = entry->ErrorResult; new_entry->op = entry->op; new_entry->state = entry->state; map::iterator it; int ret; DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnAnswer")("stage %d,%s,result %d", m_eStage, (LPCSTR)new_entry->EntityName, new_entry->ErrorResult); switch (m_eStage) { case LOADSTAGE_COREBOOT: it = m_coreBootOpt.find(new_entry->EntityName); if (it != m_coreBootOpt.end()) { if (new_entry->ErrorResult == Error_Succeed) it->second.eResult = LOADING_SUCCEED; else if (new_entry->ErrorResult == Error_TimeOut) it->second.eResult = LOADING_TIMEOUT; else it->second.eResult = LOADING_FAILED; if (it->second.eResult != Error_Succeed) { char tmp[64] = { 0 }; sprintf(tmp, "实体 %s 启动失败-----", it->first.GetData()); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnAnswer")("启动失败:%s -----", tmp); } ret = CheckLoadResult(LOADSTAGE_COREBOOT); if (ret == 0 || ret == 2) { FSMEvent* e = new FSMEvent(USER_EVT_COREBOOT_FINISHED); e->param1 = ret; PostEventFIFO(e); } } break; case LOADSTAGE_SAFELOAD: it = m_safeLoadOpt.find(new_entry->EntityName); if (it != m_safeLoadOpt.end()) { if (new_entry->ErrorResult == Error_Succeed) it->second.eResult = LOADING_SUCCEED; else if (new_entry->ErrorResult == Error_TimeOut) it->second.eResult = LOADING_TIMEOUT; else it->second.eResult = LOADING_FAILED; ret = CheckLoadResult(LOADSTAGE_SAFELOAD); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnAnswer")("safeload answer %d", ret); if (ret == 0 || ret == 2) { FSMEvent* e = new FSMEvent(USER_EVT_SAFELOAD_FINISHED); e->param1 = ret; PostEventFIFO(e); } } else { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnAnswer")("cannot find %s", (LPCTSTR)new_entry->EntityName); } break; case LOADSTAGE_OPERATING: it = m_operatingOpt.find(new_entry->EntityName); if (it != m_operatingOpt.end()) { if (new_entry->ErrorResult == Error_Succeed) it->second.eResult = LOADING_SUCCEED; else if (new_entry->ErrorResult == Error_TimeOut) it->second.eResult = LOADING_TIMEOUT; else it->second.eResult = LOADING_FAILED; ret = CheckLoadResult(LOADSTAGE_OPERATING); if (ret == 0 || ret == 2) { FSMEvent* e = new FSMEvent(USER_EVT_OPERATING_FINISHED); e->param1 = ret; PostEventFIFO(e); } } break; default: break; } } void CVtmLoaderFSM::NoticeEntityLoad(int evtCode) { HealthManagerService_ClientBase* pHMClient = new HealthManagerService_ClientBase(m_pEntity); int count = 0; bool bConnected = false; do { ErrorCodeEnum eErrConn = Error_Unexpect; ErrorCodeEnum eErrCall = Error_Unexpect; if (!bConnected) { eErrConn = pHMClient->Connect(); if (eErrConn == Error_Succeed) bConnected = true; } if (bConnected) { HealthManagerService_DoEvent_Req req; HealthManagerService_DoEvent_Ans ans; req.code = evtCode; eErrCall = pHMClient->DoEvent(req, ans, 5000); if (eErrCall == Error_Succeed) break; } DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Notice HealthManager failed,eErrConn:%d,eErrCall:%d", eErrConn, eErrCall); Sleep(2000); count++; } while (count < 100); } bool CVtmLoaderFSM::DetectHttpActive() { memset(m_httpCheckResult, 0, sizeof(m_httpCheckResult)); CSmartPointer pConfigRun; CSimpleStringA strSettingAddr(true),strAccessAuthAddr(true); CSimpleStringA errMsg; ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, pConfigRun); if (eErr == Error_Succeed) { int iTmp = 0; if (pConfigRun->ReadConfigValueInt("Common", "CanIgnoreAddrDetect", iTmp) == Error_Succeed && iTmp > 0) m_iCanIgnoreAddrDetect = iTmp; iTmp = 0; if (pConfigRun->ReadConfigValueInt("Common", "MaxAddrDetectTime", iTmp) == Error_Succeed && iTmp > 0) m_ullMaxAddrDetectTime = iTmp; iTmp = 0; if (pConfigRun->ReadConfigValueInt("Common", "AddrDetectInterval", iTmp) == Error_Succeed && iTmp > 0) m_iDetectInterval = iTmp; } DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErr:%d, iDetectInterval:%d", eErr, m_iDetectInterval); //oiltmp 由于行外pad即将下线,暂时不考虑行外地址探测 CSimpleStringA csTmpAddr(true); //集中配置探测地址 pConfigRun->ReadConfigValue("Common", "SettingDetectAddr", csTmpAddr); if (csTmpAddr.IsNullOrEmpty()) { #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/ strSettingAddr = "https://accessproxy-service.paasst.cmbchina.cn/centerconfig/rvc/detect"; #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/ strSettingAddr = "https://accessproxy-service.paas.cmbchina.cn/centerconfig/rvc/detect"; #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/ strSettingAddr = "https://accessproxy-service.paasuat.cmbchina.cn/centerconfig/rvc/detect"; #elif defined(DEVOPS_ON_DEV)/*DevOps流水线编译,Dev环境*/ strSettingAddr = "https://accessproxy-service.paas.cmbchina.cn/centerconfig/rvc/detect"; #else/*本地编译等非DevOps环境编译的版本*/ strSettingAddr = "https://accessproxy-service.paasst.cmbchina.cn/centerconfig/rvc/detect"; #endif } else strSettingAddr = csTmpAddr; csTmpAddr = ""; pConfigRun->ReadConfigValue("Common", "AccessAuthDetectAddr", strAccessAuthAddr); //准入探测地址 if (strAccessAuthAddr.IsNullOrEmpty()) { #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/ strAccessAuthAddr = "https://terminalaccess.paasst.cmbchina.cn/tsas/detect"; #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/ strAccessAuthAddr = "https://accessproxy-service.paas.cmbchina.cn/tsaccess/tsas/detect"; #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/ strAccessAuthAddr = "https://terminalaccess.paasuat.cmbchina.cn/tsas/detect"; #elif defined(DEVOPS_ON_DEV)/*DevOps流水线编译,Dev环境*/ strAccessAuthAddr = "https://terminalaccess.paas.cmbchina.cn/tsas/detect"; #else/*本地编译等非DevOps环境编译的版本*/ strAccessAuthAddr = "https://terminalaccess.paasst.cmbchina.cn/tsas/detect"; #endif } else strAccessAuthAddr = csTmpAddr; DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CenterSetting addr:%s, strAccessAuthAddr:%s", strSettingAddr.GetData(), strAccessAuthAddr.GetData()); HttpConnCheckTask* pCSTask = new HttpConnCheckTask(this, strSettingAddr, HttpAddr_CenterSetting); GetEntityBase()->GetFunction()->PostThreadPoolTask(pCSTask); HttpConnCheckTask* pAATask = new HttpConnCheckTask(this, strAccessAuthAddr, HttpAddr_AccessAuth); GetEntityBase()->GetFunction()->PostThreadPoolTask(pAATask); ULLINT beginTick, endTick; beginTick = SP::Module::Comm::RVCGetTickCount(); do { Sleep(2000); if (m_httpCheckResult[HttpAddr_CenterSetting] == HttpConnResult_OK || m_httpCheckResult[HttpAddr_AccessAuth] == HttpConnResult_OK) return true; else { endTick = SP::Module::Comm::RVCGetTickCount(); } } while (endTick - beginTick < m_ullMaxAddrDetectTime); if (m_iCanIgnoreAddrDetect > 0) return true; else return false; } bool CVtmLoaderFSM::IsRootINIExist(CSimpleStringA& path) { CSimpleStringA csHardwareCfg(true); ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("HardwareCfg", csHardwareCfg); if (eErr != Error_Succeed) { path = CSimpleStringA::Format("GetPath of HardwareCfg failed(%d)", eErr); DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("get path of Run failed:%s", SpStrError(eErr)); return false; } path = csHardwareCfg + SPLIT_SLASH_STR + "root.ini"; #if defined(RVC_OS_WIN) if (_access(path.GetData(), 0) == 0) { #else if (access(path.GetData(), F_OK) == 0) { #endif return true; } else { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("root.ini(%s) is not exist.", path.GetData()); return false; } } bool CVtmLoaderFSM::VerifyVer() { CSmartPointer pConfig; GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, pConfig); int VerifyVersion = 0; CSimpleStringA activeVer; bool isVerEqual = false; if (Error_Succeed != pConfig->ReadConfigValueInt("Common", "VerifyVersion", VerifyVersion) || Error_Succeed != GetEntityBase()->GetFunction()->GetRunningVersion(activeVer)) DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("read [Common]VerifyVersion failed"); #ifdef RVC_OS_WIN std::string curVer = std::to_string((ULONGLONG)VER_Major) + "." + std::to_string((ULONGLONG)VER_Minor) + "." + std::to_string((ULONGLONG)VER_Revision) + "." + std::to_string((ULONGLONG)VER_Build); #else std::string curVer = std::string(RVC_VERSION_STR); #endif if (curVer == activeVer.GetData()) isVerEqual = true; if (!isVerEqual) { CSimpleString showMsg = CSimpleString::Format("version not equal, file version:%s, acitve verion:%s", curVer.c_str(), activeVer.GetData()); switch (VerifyVersion) { case 0: DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)(showMsg.GetData()); break; case 1: m_verShowMsg = showMsg; CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&AlarmVersionErr, this, 0, NULL)); break; case 2: m_verShowMsg = showMsg; CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&AlarmVersionErr, this, 0, NULL)); return false; break; default: DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("VerifyVersion not support param:%d", VerifyVersion); break; } } return true; } bool CVtmLoaderFSM::GetConfig() { //拉取配置前先检查root.ini文件 CSimpleStringA csTmpRootIni(""); if (!IsRootINIExist(csTmpRootIni) && m_terminalNoFromWeb.IsNullOrEmpty()) { LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("root.ini不存在或安装页面未设置终端号,请检查(%s)", csTmpRootIni.GetData()).GetData()); return false; } ErrorCodeEnum eErr = Error_Succeed; #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/ CSimpleString channelId = "5fdd82e3b90a4de69f9da4738e5f1216"; CSimpleString tokenSecret = "eca829c78067c686561bd844129321c8a78af3"; CSimpleString CommonLaunchUrl = "https://rvc-gateway.paasst.cmbchina.cn|https://rvc-gateway-out.paasst.cmbchina.cn"; CSimpleString CenterConfigTotal = "https://accessproxy-service.paasst.cmbchina.cn/centerconfig"; #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/ CSimpleString channelId = "7eb748cb71744c87b5c126e05af8cce7"; CSimpleString tokenSecret = "eca529c78967c640561bd844229391c8a78af3"; CSimpleString CommonLaunchUrl = "https://rvc-gateway.paasuat.cmbchina.cn|https://rvc-gateway-out.paasuat.cmbchina.cn"; CSimpleString CenterConfigTotal = "https://accessproxy-service.paasuat.cmbchina.cn/centerconfig|https://accessproxy-service.paasuat.cmbchina.cn/centerconfigdmz"; #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/ CSimpleString channelId = "572f7577fa9f425c8475a8d77db4ae31"; CSimpleString tokenSecret = "eca129c78767c670561bd844629361c8a78af3"; CSimpleString CommonLaunchUrl = "https://rvc-gateway.paas.cmbchina.cn|https://vtmunify.paas.cmbchina.com/gateway"; CSimpleString CenterConfigTotal = "https://accessproxy-service.paas.cmbchina.cn/centerconfig|https://vtmunify.paas.cmbchina.com/centerconfig"; #else/*本地编译等非DevOps环境编译的版本*/ CSimpleString channelId = "5fdd82e3b90a4de69f9da4738e5f1216"; CSimpleString tokenSecret = "eca829c78067c686561bd844129321c8a78af3"; CSimpleString CommonLaunchUrl = "https://rvc-gateway.paasst.cmbchina.cn"; CSimpleString CenterConfigTotal = "https://accessproxy-service.paasst.cmbchina.cn/centerconfig"; #endif LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "开始拉取配置"); VTMInitParam vtmInitParam(m_terminalNoFromWeb.GetData(), channelId, tokenSecret, CommonLaunchUrl, CenterConfigTotal); if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->InitCfgUrl(vtmInitParam))) { LogWarn(Severity_High, Error_Unexpect, VtmLoader_GetConfig_InitCfgUrl_Failed, CSimpleStringA::Format("拉取配置,初始化配置地址失败:0x%x(%s)", eErr, SpStrError(eErr)).GetData()); DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F01")("Get config,InitCfgUrl failed."); LogEvent(Severity_High, Event_VtmLoader_GetConfig_Fail, "拉取配置,初始化配置地址失败"); return false; } else { CSimpleString oldToken, newToken; if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateToken(oldToken, newToken))) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F02")("Get config, TryUpdateToken failed:0x%x", eErr); LogWarn(Severity_High, Error_Unexpect, VtmLoader_GetConfig_UpdateToken_Failed, CSimpleStringA::Format("拉取配置失败:0x%x(%s)", eErr, SpStrError(eErr)).GetData()); } //if token update failed,we can also update cfg suc if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateCfg())) { LogWarn(Severity_High, Error_Unexpect, VtmLoader_GetConfig_UpdateCfg_Failed, CSimpleStringA::Format("拉取配置失败:0x%x(%s)", eErr, SpStrError(eErr)).GetData()); DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F03")("Get config, TryUpdateCfg failed:0x%x", eErr); LogEvent(Severity_High, Event_VtmLoader_GetConfig_Fail, "拉取配置失败"); return false; } } refreshLogLevel(); //all cfg is ready, then init the entity eErr = SubscribeEntitysEvents(); if (eErr != Error_Succeed) DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("subscribe event fail, 0x%x", eErr); else DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("subscribe event succeed"); CSmartPointer pConfig; CSimpleString t_endpoint, t_topicSys, t_topicUser, t_topicBeidou, t_bussSys, t_bussUser; eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, pConfig); if (eErr == Error_Succeed && Error_Succeed == pConfig->ReadConfigValue("Common", "SendEndpoint", t_endpoint) && Error_Succeed == pConfig->ReadConfigValue("Common", "SendSys", t_topicSys) && Error_Succeed == pConfig->ReadConfigValue("Common", "SendUser", t_topicUser) && Error_Succeed == pConfig->ReadConfigValue("Common", "SendBeidou", t_topicBeidou) && Error_Succeed == pConfig->ReadConfigValue("Common", "BusinessSys", t_bussSys) && Error_Succeed == pConfig->ReadConfigValue("Common", "BusinessUser", t_bussUser) && 0 != t_topicSys.GetLength() && 0 != t_topicUser.GetLength() && 0 != t_topicBeidou.GetLength() && 0 != t_bussSys.GetLength() && 0 != t_bussUser.GetLength()) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("endpoint:%s, topicSys:%s, topicUser:%s, topicBeidou:%s, bussSys:%s, bussUser:%s", t_endpoint.GetData(), t_topicSys.GetData(), t_topicUser.GetData(), t_topicBeidou.GetData(), t_bussSys.GetData(), t_bussUser.GetData()); if (0 != t_endpoint.GetLength()) { GetEntityBase()->GetFunction()->GetPrivilegeFunction()->BeginLogSend(t_endpoint.GetData(), t_topicSys.GetData(), t_topicUser.GetData(), t_topicBeidou.GetData(), t_bussSys.GetData(), t_bussUser.GetData()); } else DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("endpoint is empty, do not begin send log"); } else { const char* default_endpoint = "https://kafkaproxy.paas.cmbchina.cn/api/kafka/log/send"; const char* topicSys = "LR18_23_VTMTerminalLogService_L_sys_VTMTerminalSysLog_SRC_SZ"; const char* topicUser = "LR18_23_VTMTerminalLogService_L_biz_VTMTerminalUserLog_SRC_SZ"; const char* topicBeidou = "LR18_23_VTMTerminalLogService_L_trace_VTMTerminalTraceLog_SRC_SZ"; const char* topicBussSys = "LR18_23_VTMTerminalLogService_L_sys_VTMBusiness_SRC_SZ"; const char* topicBussUser = "LR18_23_VTMTerminalLogService_L_biz_VTMBusiness_SRC_SZ"; DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("read endpoint and topic err, need check centersetting, use default %s-%s-%s-%s-%s-%s", default_endpoint, topicSys, topicUser, topicBeidou, topicBussSys, topicBussUser); GetEntityBase()->GetFunction()->GetPrivilegeFunction()->BeginLogSend(default_endpoint, topicSys, topicUser, topicBeidou, topicBussSys, topicBussUser); } GetEntityBase()->GetFunction()->GetSystemStaticInfo(m_sysInfo); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("terminalNo:%s, MachineType:%s, MachineVersion:%s, Site:%s, Screen:%d, EnrolGPS:%f.%f, EnrolAddr:%s" , m_sysInfo.strTerminalID.GetData(), m_sysInfo.strMachineType.GetData(), m_sysInfo.MachineVersion.ToString().GetData() , m_sysInfo.strSite.GetData(), m_sysInfo.eScreen, m_sysInfo.EnrolGPS.GetLatitude(), m_sysInfo.EnrolGPS.GetLongitude(), m_sysInfo.strEnrolAddr.GetData()); int tmpSec = 0; if (Error_Succeed == pConfig->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "refreshTokenWaitSec", tmpSec) && tmpSec > 0) m_refreshWaitSec = tmpSec; int t_sec = 0; pConfig->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "UploadLogWaitSec", t_sec); if (t_sec > 0) m_uploadLogInfo_waitSec = t_sec; CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& checkUrlActive, this, 0, NULL)); CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& tokenUpdate, this, 0, NULL)); //通知Chromium实体 LogEvent(Severity_High, Event_VtmLoader_GetConfig_Suc, "Get config succeed."); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F13")("Get config succeed."); return true; } ErrorCodeEnum CVtmLoaderFSM::SubscribeEntitysEvents() { //want to do what? auto rc = Error_Succeed; //auto pFunc = GetEntityBase()->GetFunction(); //auto rc = pFunc->SubscribeLog(m_SubLogID2, this, Log_Event, Severity_None, Error_IgnoreAll, -1, "Gpio"); //// 准入成功事件 //rc = pFunc->SubscribeLog(m_SubLogID3, this, Log_Event, Severity_None, Error_IgnoreAll, 0x50200001, "AccessAuthorization"); // 业务首页加载事件 //rc = pFunc->SubscribeLog(m_SubLogID3, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_HEALTH_FIRST_ENTER_MAINPADE, "HealthManager"); return rc; } int CVtmLoaderFSM::HttpConnCheck(CSimpleStringA csHttAddr, HttpAddrType eType) { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to HttpConnCheck"); ULLINT beginTick = SP::Module::Comm::RVCGetTickCount(); int httpcheckCount = 1; bool bCheckOK = false; while(true){ #if defined(RVC_OS_LINUX) string msg; int curFlag = HttpProbe(csHttAddr.GetData(), msg, 5); if (curFlag > 0 && curFlag < 400) bCheckOK = true; #else bCheckOK = checkHttpActive(csHttAddr.GetData()); #endif if (!bCheckOK) { LogWarn(Severity_Middle, Error_Unexpect, VtmLoader_ConnectDetect_Failed, CSimpleStringA::Format("尝试连接总行服务失败(%s),%d 秒后自动重试(第%d次重试)。请确认终端到总行服务网络是否正常", csHttAddr.GetData(), m_iDetectInterval/1000, httpcheckCount).GetData()); DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F11").setResultCode("RTA1F06")("connect to http(s) service(%s) failed.", csHttAddr.GetData()); m_httpCheckResult[eType] = HttpConnResult_Failed; Sleep(m_iDetectInterval); httpcheckCount++; CAutoArray netList; if (SP::Module::Net::GetINETMacAddresses(netList) == Error_Succeed) { string tmpDns; GetDns(tmpDns); for (int i = 0; i < netList.GetCount(); i++) { LogWarn(Severity_Low, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("(%d)interface:%s; ip:%s; mac:%s; %s", i, netList[i].description.c_str() , netList[i].ip.c_str(), netList[i].mac.c_str(), tmpDns.c_str()).GetData()); } } } else { m_httpCheckResult[eType] = HttpConnResult_OK; if ((SP::Module::Comm::RVCGetTickCount() - beginTick) > 3000) { LogWarn(Severity_Middle, Error_Unexpect, VtmLoader_ConnectDetect_Slow, CSimpleStringA::Format("第(%d)次尝试连接总行服务成功(%s),但是网络偏慢,连接花了(%d)秒,请检查网络!" , httpcheckCount, csHttAddr.GetData(), (SP::Module::Comm::RVCGetTickCount() - beginTick)/1000).GetData()); } DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F11")("尝试连接总行服务成功(%s)", csHttAddr.GetData()); return 0; } } return -1; } void CVtmLoaderFSM::GetDns(string& dns) { dns = ""; #if defined(RVC_OS_LINUX) FILE* stream; char* line = NULL; size_t len = 0; ssize_t read; stream = popen("cat /etc/resolv.conf", "r"); string tmpStr; while ((read = getline(&line, &len, stream)) != -1) { tmpStr = line; int pos = tmpStr.find("nameserver"); if (pos != string::npos) { tmpStr = tmpStr.replace(pos, strlen("nameserver"), "dns"); dns += tmpStr + ";"; } } int rnPos = dns.find("\n"); while (rnPos != string::npos) { dns.replace(rnPos, 1, " "); rnPos = dns.find("\n"); } #else #endif return; } void CVtmLoaderFSM::ToCheckIfInstalling() { //拉取配置前先检查root.ini文件 CSimpleStringA csTmpRootIni(""); if (!IsRootINIExist(csTmpRootIni)) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)(CSimpleStringA::Format("root.ini is not exist(%s).maybe we are in installing,to wait for terminalno", csTmpRootIni.GetData()).GetData()); //oiltest //OilTestTask* task = new OilTestTask(this); //GetEntityBase()->GetFunction()->PostThreadPoolTask(task); while (true) { m_hWaitTerminalNoVar.Wait(); break; } } } void CVtmLoaderFSM::CheckDeviceEntity(SpReqAnsContext::Pointer ctx) { if (!RefreshDeviceConfig(ctx)) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("RefreshDeviceConfig failed."); ctx->Answer(Error_Unexpect); } CEntityStaticInfo staticInfo; if (m_pEntity->GetFunction()->GetEntityStaticInfo(ctx->Req.entityName.GetData(), staticInfo) != Error_Succeed) { ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo); return; } switch (staticInfo.wEntityDevelopID) { case 0x201: case 0x203: case 0x204: case 0x206: case 0x213: case 0x217: CheckDeviceBaseEntity(ctx, staticInfo.wEntityDevelopID); break; case 0x209://Gpio case 0x301://SIPPhone CheckEntityRestartIdle(ctx); break; case 0x208://MediaController CheckVideo(ctx); default: break; } return; } void CVtmLoaderFSM::SaveTerminalNo(SpReqAnsContext::Pointer ctx) { if (ctx->Req.terminalNo.IsNullOrEmpty()) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("terminalNo is null or empty"); ctx->Answer(Error_Param); return; } DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("write terminalNo[%s] to root.ini", ctx->Req.terminalNo.GetData()); ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->WriteTerminalNoToRootIni(ctx->Req.terminalNo); ctx->Answer(eErr); } bool CVtmLoaderFSM::RefreshDeviceConfig(SpReqAnsContext::Pointer ctx) { if (ctx->Req.entityName.IsNullOrEmpty() || ctx->Req.paramNum <= 0) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("param error! nothing to refresh"); return false; } DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("entityName:%s,paramNum:%d,module.GetCount:%d",ctx->Req.entityName.GetData(),ctx->Req.paramNum,ctx->Req.module.GetCount()); if (ctx->Req.module.GetCount() < ctx->Req.paramNum || ctx->Req.name.GetCount() < ctx->Req.paramNum || ctx->Req.value.GetCount() < ctx->Req.paramNum) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("param array length error! nothing to refresh"); return false; } for (int i = 0; i < ctx->Req.paramNum; i++) { MemCfgParam tmpParam("root", ctx->Req.module[i].GetData(), ctx->Req.name[i].GetData(), ctx->Req.value[i].GetData()); GetEntityBase()->GetFunction()->GetPrivilegeFunction()->ModifyMemCfgParam(tmpParam); } return true; } void CVtmLoaderFSM::CheckDeviceBaseEntity(SpReqAnsContext::Pointer ctx, WORD wEntityID) { CSmartPointer pFuncPrivilege = m_pEntity->GetFunction().ConvertCase(); CSmartPointer spWait; CEntityRunInfo runInfo; //to check entity state ErrorCodeEnum eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo); if (eErrCode == Error_Succeed) { if (runInfo.eState != EntityState_NoStart) { eErrCode = pFuncPrivilege->TerminateEntity(ctx->Req.entityName.GetData(), spWait); if (spWait != NULL) eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); } } else { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F24") ("GetEntityRunInfo %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode); ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo); return; } //(re)start entity eErrCode = pFuncPrivilege->StartEntity(ctx->Req.entityName.GetData(), NULL, spWait); if (eErrCode == Error_Succeed) { if (spWait != NULL) eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); } else { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F21") ("StartEntity %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode); ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity); return; } //TODO we should wait for device entity open suc? int count = 0; do { CEntityRunInfo runInfo; eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo); if (eErrCode == Error_Succeed) { if (runInfo.eState == EntityState_Idle) break; else if (runInfo.eState == EntityState_Lost || runInfo.eState == EntityState_Close || runInfo.eState == EntityState_Killed) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F21") ("entity state:%d", runInfo.eState); ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity); return; } count++; if (count > 3) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F21") ("entity state:%d", runInfo.eState); ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity); return; } Sleep(1000); } else { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F21") ("GetEntityRunInfo failed:%d", eErrCode); ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity); return; } } while (true); const int retryGetDevInfoInterval = 5000;//5 seconds const int maxRetryTimes = 16;//16*5 = 80 seconds ,the web timeout setting is 90s CClientSessionBase* pClient; int entityState = 0; switch (wEntityID) { case 0x206: //pinpad { PinPadService_ClientBase* pClient = new PinPadService_ClientBase(this->m_pEntity); if (pClient != NULL) { eErrCode = pClient->Connect(); if (eErrCode == Error_Succeed) { int retryTimes = maxRetryTimes; do { PinPadService_GetDevInfo_Req reqQ; PinPadService_GetDevInfo_Ans ansQ; eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000); DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state); if (eErrCode == Error_Succeed && ansQ.state == 1)// 1 for "DEVICE_STATUS_NORMAL" defined in DeviceBaseClass.h { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller"); ctx->Answer(Error_Succeed); break; } Sleep(retryGetDevInfoInterval); retryTimes--; } while (retryTimes > 0); if (retryTimes == 0) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23") ("after have tried x times"); ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal); } } else { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22") ("connect to %s failed.error code:%d", ctx->Req.entityName.GetData(), eErrCode); ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity); } } else { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22") ("new client failed."); ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity); } } break; case 0x201: //IDCertificate { IDCertService_ClientBase* pClient = new IDCertService_ClientBase(this->m_pEntity); if (pClient != NULL) { eErrCode = pClient->Connect(); if (eErrCode == Error_Succeed) { int retryTimes = maxRetryTimes; do { IDCertService_GetDevInfo_Req reqQ; IDCertService_GetDevInfo_Ans ansQ; eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000); if (eErrCode == Error_Succeed && ansQ.state == 1)// 1 for "DEVICE_STATUS_NORMAL" defined in DeviceBaseClass.h { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller"); ctx->Answer(Error_Succeed); break; } Sleep(retryGetDevInfoInterval); retryTimes--; } while (retryTimes > 0); if (retryTimes == 0) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23") ("after have tried x times"); ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal); } } else { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22") ("connect to %s failed.error code:%d", ctx->Req.entityName.GetData(), eErrCode); ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity); } } else { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22") ("new client failed."); ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity); } } break; case 0x204: //FingerPrint { FingerPrintService_ClientBase* pClient = new FingerPrintService_ClientBase(this->m_pEntity); if (pClient != NULL) { eErrCode = pClient->Connect(); if (eErrCode == Error_Succeed) { int retryTimes = maxRetryTimes; do { FingerPrintService_GetDevInfo_Req reqQ; FingerPrintService_GetDevInfo_Ans ansQ; eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000); if (eErrCode == Error_Succeed && ansQ.state == 1)// 1 for "DEVICE_STATUS_NORMAL" defined in DeviceBaseClass.h { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller"); ctx->Answer(Error_Succeed); break; } Sleep(retryGetDevInfoInterval); retryTimes--; } while (retryTimes > 0); if (retryTimes == 0) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23") ("after have tried x times"); ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal); } } else { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22") ("connect to %s failed.error code:%d", ctx->Req.entityName.GetData(), eErrCode); ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity); } } else { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22") ("new client failed."); ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity); } } break; case 0x203: //CardIssuer { CardIssuerService_ClientBase* pClient = new CardIssuerService_ClientBase(this->m_pEntity); if (pClient != NULL) { eErrCode = pClient->Connect(); if (eErrCode == Error_Succeed) { int retryTimes = maxRetryTimes; do { CardIssuerService_GetDevInfo_Req reqQ; CardIssuerService_GetDevInfo_Ans ansQ; eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000); if (eErrCode == Error_Succeed && ansQ.state == 1)// 1 for "DEVICE_STATUS_NORMAL" defined in DeviceBaseClass.h { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller"); ctx->Answer(Error_Succeed); break; } Sleep(retryGetDevInfoInterval); retryTimes--; } while (retryTimes > 0); if (retryTimes == 0) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23") ("after have tried x times"); ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal); } } else { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22") ("connect to %s failed.error code:%d", ctx->Req.entityName.GetData(), eErrCode); ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity); } } else { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22") ("new client failed."); ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity); } } break; case 0x213: //ContactlessCard { ContactlessCardService_ClientBase* pClient = new ContactlessCardService_ClientBase(this->m_pEntity); if (pClient != NULL) { eErrCode = pClient->Connect(); if (eErrCode == Error_Succeed) { int retryTimes = maxRetryTimes; do { ContactlessCardService_GetDevInfo_Req reqQ; ContactlessCardService_GetDevInfo_Ans ansQ; eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000); if (eErrCode == Error_Succeed && ansQ.state == 1)// 1 for "DEVICE_STATUS_NORMAL" defined in DeviceBaseClass.h { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller"); ctx->Answer(Error_Succeed); break; } Sleep(retryGetDevInfoInterval); retryTimes--; } while (retryTimes > 0); if (retryTimes == 0) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23") ("after have tried x times"); ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal); } } else { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22") ("connect to %s failed.error code:%d", ctx->Req.entityName.GetData(), eErrCode); ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity); } } else { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22") ("new client failed."); ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity); } } break; case 0x217: { HSPScannerService_ClientBase* pClient = new HSPScannerService_ClientBase(this->m_pEntity); if (pClient != NULL) { eErrCode = pClient->Connect(); if (eErrCode == Error_Succeed) { int retryTimes = maxRetryTimes; do { HSPScannerService_GetDevInfo_Req reqQ; HSPScannerService_GetDevInfo_Ans ansQ; eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000); if (eErrCode == Error_Succeed && ansQ.state == 1)// 1 for "DEVICE_STATUS_NORMAL" defined in DeviceBaseClass.h { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller"); ctx->Answer(Error_Succeed); break; } Sleep(retryGetDevInfoInterval); retryTimes--; } while (retryTimes > 0); if (retryTimes == 0) { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23") ("after have tried x times"); ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal); } } else { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22") ("connect to %s failed.error code:%d", ctx->Req.entityName.GetData(), eErrCode); ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity); } } else { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22") ("new client failed."); ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity); } } break; default: break; } return; } void CVtmLoaderFSM::CheckEntityRestartIdle(SpReqAnsContext::Pointer ctx) { CSmartPointer pFuncPrivilege = m_pEntity->GetFunction().ConvertCase(); CSmartPointer spWait; CEntityRunInfo runInfo; //to check entity state ErrorCodeEnum eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo); if (eErrCode == Error_Succeed) { if (runInfo.eState != EntityState_NoStart) { eErrCode = pFuncPrivilege->TerminateEntity(ctx->Req.entityName.GetData(), spWait); if (spWait != NULL) eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); } } else { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetEntityRunInfo %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode); ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo); return; } //(re)start entity eErrCode = pFuncPrivilege->StartEntity(ctx->Req.entityName.GetData(), NULL, spWait); if (eErrCode == Error_Succeed) { if (spWait != NULL) eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); } else { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode); ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity); return; } //TODO we should wait for device entity open suc? int count = 0; do { CEntityRunInfo runInfo; eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo); if (eErrCode == Error_Succeed) { if (runInfo.eState == EntityState_Idle) { ctx->Answer(Error_Succeed); return; } else if (runInfo.eState == EntityState_Lost || runInfo.eState == EntityState_Close || runInfo.eState == EntityState_Killed) { ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity); return; } count++; if (count > 5) { ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity); return; } Sleep(2000); } else { ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity); return; } } while (true); } void CVtmLoaderFSM::CheckVideo(SpReqAnsContext::Pointer ctx) { CSmartPointer pFuncPrivilege = m_pEntity->GetFunction().ConvertCase(); CSmartPointer spWait; CEntityRunInfo runInfo; //to check entity state ErrorCodeEnum eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo); if (eErrCode == Error_Succeed) { if (runInfo.eState != EntityState_NoStart) { eErrCode = pFuncPrivilege->TerminateEntity(ctx->Req.entityName.GetData(), spWait); if (spWait != NULL) eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); } } else { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetEntityRunInfo %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode); ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo); return; } //(re)start entity eErrCode = pFuncPrivilege->StartEntity(ctx->Req.entityName.GetData(), NULL, spWait); if (eErrCode == Error_Succeed) { if (spWait != NULL) eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); } else { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode); ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity); return; } //TODO we should wait for device entity open suc? int count = 0; do { CEntityRunInfo runInfo; eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo); if (eErrCode == Error_Succeed) { if (runInfo.eState == EntityState_Idle) { CSimpleStringA csCameraState(""); eErrCode = GetEntityBase()->GetFunction()->GetSysVar("CameraState", csCameraState); if (eErrCode == Error_Succeed && csCameraState.Compare("N") == 0) ctx->Answer(Error_Succeed); else ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity); return; } else if (runInfo.eState == EntityState_Lost || runInfo.eState == EntityState_Close || runInfo.eState == EntityState_Killed) { ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity); return; } count++; if (count > 5) { ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity); return; } Sleep(2000); } else { ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity); return; } } while (true); } void CVtmLoaderFSM::Oiltest() { CSmartPointer pFuncPrivilege = m_pEntity->GetFunction().ConvertCase(); CSmartPointer spWait; //(re)start entity ErrorCodeEnum eErrCode = pFuncPrivilege->StartEntity("HealthManager", NULL, spWait); if (eErrCode == Error_Succeed) { if (spWait != NULL) eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT); } else { DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity %s failed(%d).", "HealthManager", eErrCode); return; } DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity %s suc.", "HealthManager"); return; SetTerminalNo(NULL); Sleep(11000); DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to save to root.ini"); SaveTerminalNo(NULL); m_hSaveTerminalNoVar.Broadcast(); DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("continue boot"); }