| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791 |
- #include "mod_GuiConsole.h"
- #include "publicFunExport.h"
- #include <EventCode.h>
- #include "GUIConsole_msg_g.h"
- #include <chrono>
- bool isPad = false;
- void CGUIConsoleEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- void CGUIConsoleEntity::OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- void CGUIConsoleEntity::OnLog(const CAutoArray<CUUID>& SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
- const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
- const CAutoArray<DWORD>& 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<DWORD, std::string> CGUIConsoleEntity::openLogSender(SpReqAnsContext<GUIConsoleService_OpenLogSender_Req, GUIConsoleService_OpenLogSender_Ans>::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<DWORD, std::string>(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<DWORD, std::string>(rc, "");
- }
-
-
- }
- std::pair<DWORD, std::string> 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<DWORD, std::string>(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<DWORD, std::string>(rc, "");
- }
- }
- std::pair<DWORD, std::string> CGUIConsoleEntity::openEntityMonitor(SpReqAnsContext<GUIConsoleService_OpenEntityMonitor_Req, GUIConsoleService_OpenEntityMonitor_Ans>::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<DWORD, std::string>(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<DWORD, std::string>(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<EntityEntry> 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<DWORD, std::string>(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<DWORD, std::string>(Error_Succeed, "");
- }
- std::pair<DWORD, std::string> 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<DWORD, std::string>(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<DWORD, std::string>(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<DWORD, std::string>(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<DWORD, std::string>(Error_Succeed, "");
- }
- std::pair<DWORD, std::string> CGUIConsoleEntity::openPerformanceSender(SpReqAnsContext<GUIConsoleService_OpenPerformanceSender_Req, GUIConsoleService_OpenPerformanceSender_Ans>::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<DWORD, std::string>(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<DWORD, std::string>(Error_Succeed, "");
- }
- std::pair<DWORD, std::string> 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<DWORD, std::string>(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<DWORD, std::string>(Error_Succeed, "");
- }
- std::pair<DWORD, std::string> CGUIConsoleEntity::VTMSystemControl(SpReqAnsContext<GUIConsoleService_VTMSystemControl_Req, GUIConsoleService_VTMSystemControl_Ans>::Pointer ctx)
- {
- CSmartPointer<IEntityFunction> pFunc = GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- if (pFuncPrivilege == NULL)
- {
- LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_NoPrivilege, WARN_GUICONSOLE_NO_PRIVILIGE, "VTMSystemControl no privilige");
- return std::pair<DWORD, std::string>(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<DWORD, std::string>(WARN_GUICONSOLE_REBOOT_UNKNOWN_REASON, "");
- }
- return std::pair<DWORD, std::string>(rc, "");
- }
- std::pair<DWORD, std::string> CGUIConsoleEntity::VTM_controlEntity(SpReqAnsContext<GUIConsoleService_VTM_controlEntity_Req, GUIConsoleService_VTM_controlEntity_Ans>::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<DWORD, std::string>(ret, "");
- }
- std::pair<DWORD, std::string> CGUIConsoleEntity::GetBasicInformation(SpReqAnsContext<GUIConsoleService_GetBasicInformation_Req, GUIConsoleService_GetBasicInformation_Ans>::Pointer ctx)
- {
- //get idle entityNum;
- int idleNum = 0, totalNum = 0;
- CAutoArray<EntityEntry> 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<DWORD, std::string>(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<DWORD, std::string>(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<DWORD, std::string>(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<DWORD, std::string>(ErrorCodeEnum::Error_Succeed, "");
- }
- std::pair<DWORD, std::string> CGUIConsoleEntity::GetHelpInformationArr(SpReqAnsContext<GUIConsoleService_GetHelpInformationArr_Req, GUIConsoleService_GetHelpInformationArr_Ans>::Pointer ctx)
- {
- return std::pair<DWORD, std::string>();
- }
- std::pair<DWORD, std::string> CGUIConsoleEntity::GetHelpDetail(SpReqAnsContext<GUIConsoleService_GetHelpDetail_Req, GUIConsoleService_GetHelpDetail_Ans>::Pointer ctx)
- {
- return std::pair<DWORD, std::string>();
- }
- 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<GUIConsoleService_OpenLogSender_Req, GUIConsoleService_OpenLogSender_Ans>::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<GUIConsoleService_CloseLogSender_Req, GUIConsoleService_CloseLogSender_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- auto ret = m_pEntity->closeLogSender();
- ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first);
- }
- void CGUIConsoleSession::Handle_OpenEntityMonitor(SpReqAnsContext<GUIConsoleService_OpenEntityMonitor_Req, GUIConsoleService_OpenEntityMonitor_Ans>::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<GUIConsoleService_CloseEntityMonitor_Req, GUIConsoleService_CloseEntityMonitor_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- auto ret = m_pEntity->closeEntityMonitor();
- ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first);
- }
- void CGUIConsoleSession::Handle_OpenPerformanceSender(SpReqAnsContext<GUIConsoleService_OpenPerformanceSender_Req, GUIConsoleService_OpenPerformanceSender_Ans>::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<GUIConsoleService_ClosePerformanceSender_Req, GUIConsoleService_ClosePerformanceSender_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- auto ret = m_pEntity->closePerformanceSender();
- ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first);
- }
- void CGUIConsoleSession::Handle_VTMSystemControl(SpReqAnsContext<GUIConsoleService_VTMSystemControl_Req, GUIConsoleService_VTMSystemControl_Ans>::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<GUIConsoleService_VTM_controlEntity_Req, GUIConsoleService_VTM_controlEntity_Ans>::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<GUIConsoleService_GetAllEntityList_Req, GUIConsoleService_GetAllEntityList_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- CAutoArray<EntityEntry> 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<GUIConsoleService_GetBasicInformation_Req, GUIConsoleService_GetBasicInformation_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- auto ret = m_pEntity->GetBasicInformation(ctx);
- ctx->Answer((ErrorCodeEnum)ret.first, ret.first);
- }
- void CGUIConsoleSession::Handle_GetHelpInformationArr(SpReqAnsContext<GUIConsoleService_GetHelpInformationArr_Req, GUIConsoleService_GetHelpInformationArr_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- //m_pEntity->GetHelpInformationArr(ctx);
- ctx->Answer(ErrorCodeEnum::Error_Succeed);
- }
- void CGUIConsoleSession::Handle_GetHelpDetail(SpReqAnsContext<GUIConsoleService_GetHelpDetail_Req, GUIConsoleService_GetHelpDetail_Ans>::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<IEntityFunction> pFunc = GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- if (pFuncPrivilege != NULL) {
- CSmartPointer<IAsynWaitSp> 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<IEntityFunction> pFunc = GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- if (pFuncPrivilege != NULL) {
- CSmartPointer<IAsynWaitSp> spWait;
- ErrorCodeEnum Error = pFuncPrivilege->StopEntity(entity_name, spWait);
- if (Error == Error_Succeed) {
- callback_entry* entry = new callback_entry();
- entry->pRawData = pData;
- entry->EntityName = entity_name;
- entry->ErrorResult = Error_Unexpect;
- entry->op = OP_STOP_ENTITY;
- spWait->SetCallback(this, entry);
- }
- return Error;
- }
- else {
- return Error_NoPrivilege;
- }
- }
- ErrorCodeEnum CGUIConsoleEntity::AsyncPauseEntity(const char* entity_name, void* pData)
- {
- CSmartPointer<IEntityFunction> pFunc = GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- if (pFuncPrivilege != NULL) {
- CSmartPointer<IAsynWaitSp> spWait;
- ErrorCodeEnum Error = pFuncPrivilege->PauseEntity(entity_name, spWait);
- if (Error == Error_Succeed) {
- callback_entry* entry = new callback_entry();
- entry->pRawData = pData;
- entry->EntityName = entity_name;
- entry->ErrorResult = Error_Unexpect;
- entry->op = OP_PAUSE_ENTITY;
- spWait->SetCallback(this, entry);
- }
- return Error;
- }
- else {
- return Error_NoPrivilege;
- }
- }
- ErrorCodeEnum CGUIConsoleEntity::AsyncContinueEntity(const char* entity_name, void* pData)
- {
- CSmartPointer<IEntityFunction> pFunc = GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- if (pFuncPrivilege != NULL) {
- CSmartPointer<IAsynWaitSp> spWait;
- ErrorCodeEnum Error = pFuncPrivilege->ContinueEntity(entity_name, spWait);
- if (Error == Error_Succeed) {
- callback_entry* entry = new callback_entry();
- entry->pRawData = pData;
- entry->EntityName = entity_name;
- entry->ErrorResult = Error_Unexpect;
- entry->op = OP_CONTINUE_ENTITY;
- spWait->SetCallback(this, entry);
- }
- return Error;
- }
- else {
- return Error_NoPrivilege;
- }
- }
- ErrorCodeEnum CGUIConsoleEntity::AsyncTerminateEntity(const char* entity_name, void* pData)
- {
- CSmartPointer<IEntityFunction> pFunc = GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- if (pFuncPrivilege != NULL) {
- CSmartPointer<IAsynWaitSp> spWait;
- ErrorCodeEnum Error = pFuncPrivilege->TerminateEntity(entity_name, spWait);
- if (Error == Error_Succeed) {
- callback_entry* entry = new callback_entry();
- entry->pRawData = pData;
- entry->EntityName = entity_name;
- entry->ErrorResult = Error_Unexpect;
- entry->op = OP_TERMINATE_ENTITY;
- spWait->SetCallback(this, entry);
- }
- return Error;
- }
- else {
- return Error_NoPrivilege;
- }
- }
- ErrorCodeEnum CGUIConsoleEntity::GetEntity(const char* entity_name, EntityEntry& e)
- {
- CSmartPointer<IEntityFunction> 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<DWORD, std::string> CGUIConsoleEntity::GetAllEntity(CAutoArray<EntityEntry>& Entities)
- {
- CSmartPointer<IEntityFunction> spFunc = GetFunction();
- CAutoArray<CSimpleStringA> strEntityNames;
- CAutoArray<WORD> 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<IAsynWaitSp> pAsynWaitSp)
- {
- CSmartPointer<ICallbackListener> spCallback;
- CSmartPointer<IReleasable> pData;
- pAsynWaitSp->GetCallback(spCallback, pData);
- LOG_ASSERT(pData.GetRawPointer() != NULL);
- callback_entry* entry = static_cast<callback_entry*>((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()
|