#include "mod_GuiConsole.h" #include "publicFunExport.h" #include #include "GUIConsole_msg_g.h" #include bool isPad = false; void CGUIConsoleEntity::OnPreStart(CAutoArray strArgs, CSmartPointer pTransactionContext) { pTransactionContext->SendAnswer(Error_Succeed); } void CGUIConsoleEntity::OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer pTransactionContext) { pTransactionContext->SendAnswer(Error_Succeed); } void CGUIConsoleEntity::OnLog(const CAutoArray& SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel, const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID, const CAutoArray& Param, const char* pszEntityName, const char* pszModuleName, const char* pszMessage, const linkContext& pLinkInfo) { // 忽略GPIO事件 if (dwUserCode == 0x2090000A || dwUserCode == 0x20900009) return; //did not open log sender if (!m_isOpenLogSender) return; DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("OnLog %s %s", pszEntityName, pszMessage); if (pszMessage != NULL && strlen(pszMessage) > 2) { CSimpleStringA str = pszMessage; LogInfo msg; msg.sysError = dwSysError; msg.userCode = dwUserCode; msg.timeStr = GenerateTimeStr().c_str(); msg.entityName = pszEntityName; msg.LogType = LogTypeEnumToString(eLogType).c_str(); msg.message = str; SpSendBroadcast(GetFunction(), eMsg_LogInfo, eMsgSig_LogInfo, msg); } } void CGUIConsoleEntity::OnEntityStateHook(const char* pszEntityName, const char* pszTriggerEntity, EntityStateEnum eState, EntityStateEnum eLastState) { //did not open log sender if (m_isOpenLogSender) { LogInfo msg; if (eLastState == EntityState_Idle && eState != EntityState_Idle) { msg.sysError = ErrorCodeEnum::Error_Closed; msg.userCode = ErrorCodeEnum::Error_Closed; msg.message = CSimpleString::Format("%s实体异常,重新启动...", pszEntityName); } else { msg.sysError = ErrorCodeEnum::Error_Succeed; msg.userCode = ErrorCodeEnum::Error_Succeed; if (eState == EntityState_Starting) msg.message = CSimpleString::Format("正在启动实体%s...", pszEntityName); else if (eState == EntityState_Idle) msg.message = CSimpleString::Format("%s 实体启动成功", pszEntityName); } msg.timeStr = GenerateTimeStr().c_str(); msg.entityName = pszEntityName; SpSendBroadcast(GetFunction(), eMsg_LogInfo, eMsgSig_LogInfo, msg); } if (m_isOpenEntityMonitor) PostEntityVary(pszEntityName);//if registered, while entity status changed, send to web } void CGUIConsoleEntity::OnTimeout(DWORD dwTimerID) { } std::pair CGUIConsoleEntity::openLogSender(SpReqAnsContext::Pointer ctx) { if ((__int64)m_logSubID != 0) { LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_AlreadyExist, WARN_GUICONSOLE_LOG_ALREADY_REGISTER, "openLogSender: already register"); m_isOpenLogSender = true; return std::pair(WARN_GUICONSOLE_LOG_ALREADY_REGISTER, "openLogSender: already register"); } else { auto logType = StringToLogTypeEnum(ctx->Req.LogType.GetData()); //check valid input for this function if (logType != LogTypeEnum::Log_Ignore && logType != LogTypeEnum::Log_Event && logType != LogTypeEnum::Log_Warning && logType != LogTypeEnum::Log_Error) { LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_NotSupport, WARN_GUICONSOLE_LOGSENDER_UNVAILD_INPUT, CSimpleString::Format("openLogSender: not valid input: %s, use default warning", ctx->Req.LogType.GetData()).GetData()); m_sendLogType = LogTypeEnum::Log_Warning; } else m_sendLogType = logType; auto rc = GetFunction()->SubscribeLog(m_logSubID, this, (LogTypeEnum)m_sendLogType, Severity_None, Error_IgnoreAll, -1, NULL, false); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("openLogSender SubscribeLog %s %s", ctx->Req.LogType.GetData(), (rc == ErrorCodeEnum::Error_Succeed ? "success" : "failed")); m_isOpenLogSender = (rc == ErrorCodeEnum::Error_Succeed); return std::pair(rc, ""); } } std::pair CGUIConsoleEntity::closeLogSender() { if ((__int64)m_logSubID == 0) { LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_AlreadyExist, WARN_GUICONSOLE_LOG_ALREADY_UNREGISTER, "closeLogSender: already unregister"); m_isOpenLogSender = false; return std::pair(WARN_GUICONSOLE_LOG_ALREADY_UNREGISTER, "closeLogSender: already unregister"); } else { auto rc = GetFunction()->UnsubscribeLog(m_logSubID); if(rc == ErrorCodeEnum::Error_Succeed) m_logSubID = 0; DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("closeLogSender UnsubscribeLog %s", (rc == ErrorCodeEnum::Error_Succeed ? "success" : "failed")); m_isOpenLogSender = !(rc == ErrorCodeEnum::Error_Succeed); return std::pair(rc, ""); } } std::pair CGUIConsoleEntity::openEntityMonitor(SpReqAnsContext::Pointer ctx) { m_isOpenEntityMonitor = true; if (ctx->Req.longestFrequence <= 1) m_longestEntityMonitor = 1; else m_longestEntityMonitor = ctx->Req.longestFrequence; if (ctx->Req.leastFrequence <= 1) m_leastEntityMonitor = 1; else m_leastEntityMonitor = ctx->Req.leastFrequence; m_entityMonitor_shouldwork = true; int rc_errorenum = ErrorCodeEnum::Error_Succeed; if (!GetFunction()->HasPrivilege()) { LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_NoPrivilege, WARN_GUICONSOLE_ENTITYMONITOR_NO_PRIVILEGE, "openEntityMonitor no privilige"); return std::pair(WARN_GUICONSOLE_ENTITYMONITOR_NO_PRIVILEGE, ""); } if (ErrorCodeEnum::Error_Succeed != (rc_errorenum = GetFunction()->GetPrivilegeFunction()->RegistEntityStateEvent(NULL, this))) { LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_NoPrivilege, WARN_GUICONSOLE_ENTITYMONITOR_REGISTER, CSimpleStringA::Format("openEntityMonitor RegistEntityStateEvent failed, %d", rc_errorenum)); return std::pair(WARN_GUICONSOLE_ENTITYMONITOR_REGISTER, ""); } auto entityMonitorSender = [this] { while (m_isOpenEntityMonitor) { if(m_entityMonitor_shouldwork || (std::chrono::steady_clock::now() - m_entityMonitorlast_notify_time >= std::chrono::seconds(m_longestEntityMonitor))) { m_entityMonitorlast_notify_time = std::chrono::steady_clock::now(); m_entityMonitor_shouldwork = false; EntityStatus cur; CAutoArray Entities; auto ret = GetAllEntity(Entities); if (ret.first != ErrorCodeEnum::Error_Succeed) { LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_AlreadyExist, WARN_GUICONSOLE_ENTITYMONITOR_GETINFO_FAILED, CSimpleStringA::Format("openEntityMonitor - GetAllEntity failed, %d", ret.first)); continue; } cur.entityName.Init(Entities.GetCount()); cur.status.Init(Entities.GetCount()); cur.processId.Init(Entities.GetCount()); cur.versionNo.Init(Entities.GetCount()); cur.lastStartTime.Init(Entities.GetCount()); for (int i = 0; i < Entities.GetCount(); ++i) { cur.entityName[i] = Entities[i].Name; cur.status[i] = EntityEntry::GetStateName(Entities[i].State); cur.processId[i] = std::to_string(Entities[i].Pid).c_str(); cur.versionNo[i] = getRunVersion(); cur.lastStartTime[i] = Entities[i].lastStartTime.ToTimeString(); } SpSendBroadcast(GetFunction(), eMsg_EntityStatus, eMsgSig_EntityStatus, cur); } std::this_thread::sleep_for(std::chrono::seconds(m_leastEntityMonitor)); } }; if (thread_entityMonitor != NULL) { LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_AlreadyExist, WARN_GUICONSOLE_ENTITYMONITOR_EXISTED, "openEntityMonitor, thread_entityMonitor already existed"); return std::pair(WARN_GUICONSOLE_ENTITYMONITOR_EXISTED, ""); } thread_entityMonitor = new std::thread(entityMonitorSender); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("openEntityMonitor create entityMonitor sender thread %s, leastFrequence:%d, m_longestEntityMonitor:%d", (thread_entityMonitor != NULL ? "success" : "failed"), m_leastEntityMonitor, m_longestEntityMonitor); return std::pair(Error_Succeed, ""); } std::pair CGUIConsoleEntity::closeEntityMonitor() { m_isOpenEntityMonitor = false; int rc_errorenum = ErrorCodeEnum::Error_Succeed; if (!GetFunction()->HasPrivilege()) { LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_NoPrivilege, WARN_GUICONSOLE_ENTITYMONITOR_NO_PRIVILEGE, "closeEntityMonitor no privilige"); return std::pair(WARN_GUICONSOLE_ENTITYMONITOR_NO_PRIVILEGE, ""); } if (ErrorCodeEnum::Error_Succeed != (rc_errorenum = GetFunction()->GetPrivilegeFunction()->UnregistEntityStateEvent(NULL))) { LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_NoPrivilege, WARN_GUICONSOLE_ENTITYMONITOR_UNREGISTER, CSimpleStringA::Format("closeEntityMonitor unRegistEntityStateEvent failed, %d", rc_errorenum)); return std::pair(WARN_GUICONSOLE_ENTITYMONITOR_UNREGISTER, ""); } if (thread_entityMonitor == NULL) { LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_NotExist, WARN_GUICONSOLE_ENTITYMONITOR_NOTEXISTED, "closeEntityMonitor, thread_entityMonitor not exist"); return std::pair(WARN_GUICONSOLE_ENTITYMONITOR_NOTEXISTED, ""); } thread_entityMonitor->join(); delete thread_entityMonitor; thread_entityMonitor = NULL; DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("closeEntityMonitor close entityMonitor sender thread success"); return std::pair(Error_Succeed, ""); } std::pair CGUIConsoleEntity::openPerformanceSender(SpReqAnsContext::Pointer ctx) { m_isOpenPerformanceSender = true; if (ctx->Req.sendFrequence <= 1) m_performanceSenderFrequence = 1; else m_performanceSenderFrequence = ctx->Req.sendFrequence; auto performanceSender = [this] { while (m_isOpenPerformanceSender) { system_monitor_status curStatus; auto pullret = PollProcessList(m_performanceSenderFrequence, curStatus); PerformanceList dst; dst.NameArr.Init(curStatus.processList.size()); dst.pidArr.Init(curStatus.processList.size()); dst.cpuArr.Init(curStatus.processList.size()); dst.memoryArr.Init(curStatus.processList.size()); dst.cmdlineArr.Init(curStatus.processList.size()); dst.handleNumArr.Init(curStatus.processList.size()); for (int i = 0; i < curStatus.processList.size(); i++) { dst.NameArr[i] = curStatus.processList[i].ExeName; dst.pidArr[i] = curStatus.processList[i].ID; dst.cpuArr[i] = curStatus.processList[i].PercentProcessorTime; dst.memoryArr[i] = curStatus.processList[i].PercentMemory; dst.cmdlineArr[i] = ""; dst.handleNumArr[i] = curStatus.processList[i].ThreadCount; } SpSendBroadcast(GetFunction(), eMsg_PerformanceList, eMsgSig_PerformanceList, dst); std::this_thread::sleep_for(std::chrono::seconds(m_performanceSenderFrequence)); } }; if (thread_performanceSend != NULL) { LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_AlreadyExist, WARN_GUICONSOLE_PERFORMANCE_EXISTED, "openPerformanceSender, thread_performanceSend already existed"); return std::pair(WARN_GUICONSOLE_PERFORMANCE_EXISTED, ""); } thread_performanceSend = new std::thread(performanceSender); DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("openPerformanceSender create performance sender thread %s, sendFrequence:%d", (thread_performanceSend != NULL ? "success" : "failed"), m_performanceSenderFrequence); return std::pair(Error_Succeed, ""); } std::pair CGUIConsoleEntity::closePerformanceSender() { m_isOpenPerformanceSender = false; if(thread_performanceSend == NULL) { LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_NotExist, WARN_GUICONSOLE_PERFORMANCE_NOTEXISTED, "closePerformanceSender, thread_performanceSend not exist"); return std::pair(WARN_GUICONSOLE_PERFORMANCE_NOTEXISTED, ""); } thread_performanceSend->join(); delete thread_performanceSend; thread_performanceSend = NULL; DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("closePerformanceSender close performance sender thread success"); return std::pair(Error_Succeed, ""); } std::pair CGUIConsoleEntity::VTMSystemControl(SpReqAnsContext::Pointer ctx) { CSmartPointer pFunc = GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); if (pFuncPrivilege == NULL) { LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_NoPrivilege, WARN_GUICONSOLE_NO_PRIVILIGE, "VTMSystemControl no privilige"); return std::pair(WARN_GUICONSOLE_NO_PRIVILIGE, ""); } DWORD rc = Error_Succeed; if(!ctx->Req.rebootFunction.Compare("RestartApp", true)) rc = pFuncPrivilege->Reboot(RebootTrigger_ManualLocal, RebootWayEnum::RebootWay_Framework); else if (!ctx->Req.rebootFunction.Compare("RestartOS", true)) rc = pFuncPrivilege->Reboot(RebootTrigger_ManualLocal, RebootWayEnum::RebootWay_OS); else if (!ctx->Req.rebootFunction.Compare("ShutdownOS", true)) rc = pFuncPrivilege->Reboot(RebootTrigger_ManualLocal, RebootWayEnum::RebootWay_Power); else if (!ctx->Req.rebootFunction.Compare("ExitApp", true)) rc = pFuncPrivilege->Reboot(RebootTrigger_ManualLocal, RebootWayEnum::RebootWay_Unknown); else { LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_NoDefine, WARN_GUICONSOLE_REBOOT_UNKNOWN_REASON, CSimpleStringA::Format("VTMSystemControl receive unknown param %s, do nothing", ctx->Req.rebootFunction.GetData()).GetData()); return std::pair(WARN_GUICONSOLE_REBOOT_UNKNOWN_REASON, ""); } return std::pair(rc, ""); } std::pair CGUIConsoleEntity::VTM_controlEntity(SpReqAnsContext::Pointer ctx) { ErrorCodeEnum ret = ErrorCodeEnum::Error_Succeed; if (!ctx->Req.operation.Compare("Start", true)) ret = AsyncStartEntity(ctx->Req.entityName, NULL, NULL); else if (!ctx->Req.operation.Compare("Stop", true)) ret = AsyncStopEntity(ctx->Req.entityName, NULL); else if (!ctx->Req.operation.Compare("Pause", true)) ret = AsyncPauseEntity(ctx->Req.entityName, NULL); else if (!ctx->Req.operation.Compare("Continue", true)) ret = AsyncContinueEntity(ctx->Req.entityName, NULL); else if (!ctx->Req.operation.Compare("Terminate", true)) ret = AsyncTerminateEntity(ctx->Req.entityName, NULL); if (m_isOpenLogSender) { LogInfo msg; msg.sysError = ret; msg.userCode = ret; msg.timeStr = GenerateTimeStr().c_str(); msg.entityName = ctx->Req.entityName; msg.message = CSimpleString::Format("%s %s %s, ret:%d", ctx->Req.entityName, ctx->Req.operation , (ret == ErrorCodeEnum::Error_Succeed ? "Success" : "Failed"), ret); SpSendBroadcast(GetFunction(), eMsg_LogInfo, eMsgSig_LogInfo, msg); } return std::pair(ret, ""); } std::pair CGUIConsoleEntity::GetBasicInformation(SpReqAnsContext::Pointer ctx) { //get idle entityNum; int idleNum = 0, totalNum = 0; CAutoArray Entities; auto ret = ErrorCodeEnum::Error_Succeed; auto entity_ret = GetAllEntity(Entities); if (ErrorCodeEnum::Error_Succeed != entity_ret.first) { LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_Unexpect, WARN_GUICONSOLE_BASICINFO_GETENTITY , CSimpleString::Format("GetBasicInformation-GetAllEntity get entity failed, %d", entity_ret.first).GetData()); return std::pair(WARN_GUICONSOLE_BASICINFO_GETENTITY, ""); } totalNum = Entities.GetCount(); for (int i = 0; i < Entities.GetCount(); i++) { CSimpleString curState = EntityEntry::GetStateName(Entities[i].State); if (!curState.Compare("Idle", true)) idleNum++; } ctx->Ans.total_entityNum = totalNum; ctx->Ans.Idle_entityNum = idleNum; CSystemStaticInfo m_terminalInfo; if (ErrorCodeEnum::Error_Succeed != (ret = GetFunction()->GetSystemStaticInfo(m_terminalInfo))) { LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_Unexpect, WARN_GUICONSOLE_BASICINFO_SYSTEMINFO_FAILED , CSimpleString::Format("GetBasicInformation-GetSystemStaticInfo failed, %d", ret).GetData()); return std::pair(WARN_GUICONSOLE_BASICINFO_SYSTEMINFO_FAILED, ""); } ctx->Ans.terminalNo = m_terminalInfo.strTerminalID; ctx->Ans.machineType = m_terminalInfo.strMachineType; ctx->Ans.manufacturer = m_terminalInfo.strManufacturer; ctx->Ans.machineModel = m_terminalInfo.strMachineModel; ctx->Ans.versionNo = getRunVersion(); #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/ ctx->Ans.Env = "ST"; #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/ ctx->Ans.Env = "UAT"; #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/ ctx->Ans.Env = "PRD"; #else/*本地编译等非DevOps环境编译的版本*/ ctx->Ans.Env = "DEV"; #endif CSystemRunInfo sysRunInfo; if (ErrorCodeEnum::Error_Succeed != (ret = GetFunction()->GetSystemRunInfo(sysRunInfo))) { LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_Unexpect, WARN_GUICONSOLE_BASICINFO_RUNINFO_FAILED , CSimpleString::Format("GetBasicInformation-GetSystemRunInfo failed, %d", ret).GetData()); return std::pair(WARN_GUICONSOLE_BASICINFO_RUNINFO_FAILED, ""); } ctx->Ans.vtm_startupTime = sysRunInfo.tmStart.ToTimeString(); ctx->Ans.basicconfig_status = sysRunInfo.bBasicCfgWork; ctx->Ans.errmsg_status = sysRunInfo.bErrCfgWork; return std::pair(ErrorCodeEnum::Error_Succeed, ""); } std::pair CGUIConsoleEntity::GetHelpInformationArr(SpReqAnsContext::Pointer ctx) { return std::pair(); } std::pair CGUIConsoleEntity::GetHelpDetail(SpReqAnsContext::Pointer ctx) { return std::pair(); } CGUIConsoleEntity::CGUIConsoleEntity() :m_isOpenLogSender(false), m_isOpenEntityMonitor(false), m_isOpenPerformanceSender(false), m_sendLogType(LogTypeEnum::Log_Warning), thread_performanceSend(NULL), thread_entityMonitor(NULL), m_longestEntityMonitor(60), m_leastEntityMonitor(2) { } CGUIConsoleEntity::~CGUIConsoleEntity() { m_isOpenPerformanceSender = false; m_isOpenEntityMonitor = false; m_isOpenLogSender = false; if (thread_performanceSend) { thread_performanceSend->detach(); delete thread_performanceSend; thread_performanceSend = NULL; } if (thread_entityMonitor) { thread_entityMonitor->detach(); delete thread_entityMonitor; thread_entityMonitor = NULL; } } void CGUIConsoleSession::Handle_OpenLogSender(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); auto ret = m_pEntity->openLogSender(ctx); ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first); } void CGUIConsoleSession::Handle_CloseLogSender(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); auto ret = m_pEntity->closeLogSender(); ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first); } void CGUIConsoleSession::Handle_OpenEntityMonitor(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); auto ret = m_pEntity->openEntityMonitor(ctx); ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first); } void CGUIConsoleSession::Handle_CloseEntityMonitor(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); auto ret = m_pEntity->closeEntityMonitor(); ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first); } void CGUIConsoleSession::Handle_OpenPerformanceSender(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); auto ret = m_pEntity->openPerformanceSender(ctx); ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first); } void CGUIConsoleSession::Handle_ClosePerformanceSender(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); auto ret = m_pEntity->closePerformanceSender(); ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first); } void CGUIConsoleSession::Handle_VTMSystemControl(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); auto ret = m_pEntity->VTMSystemControl(ctx); ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first); } void CGUIConsoleSession::Handle_VTM_controlEntity(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); auto ret = m_pEntity->VTM_controlEntity(ctx); ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first); } void CGUIConsoleSession::Handle_GetAllEntityList(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); CAutoArray Entities; auto ret = m_pEntity->GetAllEntity(Entities); if (ret.first != ErrorCodeEnum::Error_Succeed) { ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first); return; } ctx->Ans.entityName.Init(Entities.GetCount()); ctx->Ans.status.Init(Entities.GetCount()); ctx->Ans.processId.Init(Entities.GetCount()); ctx->Ans.versionNo.Init(Entities.GetCount()); ctx->Ans.lastStartTime.Init(Entities.GetCount()); for (int i = 0; i < Entities.GetCount(); ++i) { ctx->Ans.entityName[i] = Entities[i].Name; ctx->Ans.status[i] = EntityEntry::GetStateName(Entities[i].State); ctx->Ans.processId[i] = std::to_string(Entities[i].Pid).c_str(); ctx->Ans.versionNo[i] = m_pEntity->getRunVersion(); ctx->Ans.lastStartTime[i] = Entities[i].lastStartTime.ToTimeString(); } ctx->Answer(Error_Succeed); } void CGUIConsoleSession::Handle_GetBasicInformation(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); auto ret = m_pEntity->GetBasicInformation(ctx); ctx->Answer((ErrorCodeEnum)ret.first, ret.first); } void CGUIConsoleSession::Handle_GetHelpInformationArr(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); //m_pEntity->GetHelpInformationArr(ctx); ctx->Answer(ErrorCodeEnum::Error_Succeed); } void CGUIConsoleSession::Handle_GetHelpDetail(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); //m_pEntity->GetHelpDetail(ctx); ctx->Answer(ErrorCodeEnum::Error_Succeed); } CSimpleString CGUIConsoleEntity::getRunVersion() { static CSimpleStringA activeVer; if(activeVer.GetLength() == 0) GetFunction()->GetRunningVersion(activeVer); return activeVer; } ErrorCodeEnum CGUIConsoleEntity::AsyncStartEntity(const char* entity_name, const char* cmdline, void* pData) { CSmartPointer pFunc = GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); if (pFuncPrivilege != NULL) { CSmartPointer spWait; ErrorCodeEnum Error = pFuncPrivilege->StartEntity(entity_name, cmdline, 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_START_ENTITY; spWait->SetCallback(this, entry); } return Error; } else { return Error_NoPrivilege; } } ErrorCodeEnum CGUIConsoleEntity::AsyncStopEntity(const char* entity_name, void* pData) { CSmartPointer pFunc = GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); if (pFuncPrivilege != NULL) { CSmartPointer 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; spWait->SetCallback(this, entry); } return Error; } else { return Error_NoPrivilege; } } ErrorCodeEnum CGUIConsoleEntity::AsyncPauseEntity(const char* entity_name, void* pData) { CSmartPointer pFunc = GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); if (pFuncPrivilege != NULL) { CSmartPointer 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; spWait->SetCallback(this, entry); } return Error; } else { return Error_NoPrivilege; } } ErrorCodeEnum CGUIConsoleEntity::AsyncContinueEntity(const char* entity_name, void* pData) { CSmartPointer pFunc = GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); if (pFuncPrivilege != NULL) { CSmartPointer 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; spWait->SetCallback(this, entry); } return Error; } else { return Error_NoPrivilege; } } ErrorCodeEnum CGUIConsoleEntity::AsyncTerminateEntity(const char* entity_name, void* pData) { CSmartPointer pFunc = GetFunction(); CSmartPointer pFuncPrivilege = pFunc.ConvertCase(); if (pFuncPrivilege != NULL) { CSmartPointer 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; spWait->SetCallback(this, entry); } return Error; } else { return Error_NoPrivilege; } } ErrorCodeEnum CGUIConsoleEntity::GetEntity(const char* entity_name, EntityEntry& e) { CSmartPointer spFunc = GetFunction(); LOG_ASSERT(spFunc != NULL); CEntityStaticInfo StaticInfo; CEntityRunInfo RunInfo; ErrorCodeEnum Error = spFunc->GetEntityStaticInfo(entity_name, StaticInfo); if (Error == Error_Succeed) { Error = spFunc->GetEntityRunInfo(entity_name, RunInfo); if (Error == Error_Succeed) { e.Name = entity_name; e.Id = RunInfo.dwEntityInstanceID; e.ModuleName = _GetFileName(StaticInfo.strSpFileName); e.State = RunInfo.eState; e.Type = StaticInfo.bStartedByShell ? 0 : 1; e.Pid = (int)RunInfo.dwProcessID; e.DevelopID = (int)StaticInfo.wEntityDevelopID; e.DebugLevel = RunInfo.eDebugLevel; e.lastStartTime = RunInfo.tmLastStart; } } return Error; } void CGUIConsoleEntity::PostEntityVary(const char* entity_name) { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("PostEntityVary %s ", entity_name); EntityEntry ret; DWORD rc; if (ErrorCodeEnum::Error_Succeed != (rc = GetEntity(entity_name, ret))) { LogWarn(SeverityLevelEnum::Severity_Middle, (ErrorCodeEnum)rc, WARN_GUICONSOLE_GETENTITY_FAILED , CSimpleStringA::Format("PostEntityVary-GetEntity failed, reason:%d", rc).GetData()); return; } m_entityMonitor_shouldwork = true; /* EntityStatus cur; cur.entityName = entity_name; cur.status = EntityEntry::GetStateName(ret.State); cur.processId = std::to_string(ret.Pid).c_str(); cur.versionNo = getRunVersion(); cur.lastStartTime = ret.lastStartTime.ToTimeString(); SpSendBroadcast(GetFunction(), eMsg_EntityStatus, eMsgSig_EntityStatus, cur); */ } std::pair CGUIConsoleEntity::GetAllEntity(CAutoArray& Entities) { CSmartPointer spFunc = GetFunction(); CAutoArray strEntityNames; CAutoArray wDevelopIDs; ErrorCodeEnum Error = spFunc->GetAllRegistedEntity(strEntityNames, wDevelopIDs); if (Error_Succeed != Error) { LogWarn(SeverityLevelEnum::Severity_Middle, Error, WARN_GUICONSOLE_GETALLENTITY_REGISTERED, "GetAllEntity-GetAllRegistedEntity failed"); return std::make_pair(WARN_GUICONSOLE_GETALLENTITY_REGISTERED, ""); } CSimpleString ErrInfo; Entities.Init(strEntityNames.GetCount()); for (int i = 0; i < strEntityNames.GetCount(); ++i) { Error = GetEntity(strEntityNames[i], Entities[i]); if (Error != Error_Succeed) ErrInfo += CSimpleString::Format("|%s %d|", strEntityNames[i].GetData(), Error); } if (ErrInfo.GetLength() > 0) { LogWarn(SeverityLevelEnum::Severity_Middle, Error, WARN_GUICONSOLE_GETALLENTITY_GETENTITY, ErrInfo.GetData()); return std::make_pair(WARN_GUICONSOLE_GETALLENTITY_GETENTITY, ""); } return std::make_pair(ErrorCodeEnum::Error_Succeed, ""); } void CGUIConsoleEntity::OnAnswer(CSmartPointer pAsynWaitSp) { CSmartPointer spCallback; CSmartPointer pData; pAsynWaitSp->GetCallback(spCallback, pData); LOG_ASSERT(pData.GetRawPointer() != NULL); callback_entry* entry = static_cast((IReleasable*)pData.GetRawPointer()); entry->ErrorResult = pAsynWaitSp->AsyncGetAnswer(); if(m_isOpenEntityMonitor) PostEntityVary(entry->EntityName);//if registered, while entity status changed, send to web } SP_BEGIN_ENTITY_MAP() SP_ENTITY(CGUIConsoleEntity) SP_END_ENTITY_MAP()