123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606 |
- #include "mod_GuiConsole.h"
- #include "publicFunExport.h"
- #include <EventCode.h>
- #include "GUIConsole_msg_g.h"
- 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;
- 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)
- return;
- 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);
- }
- 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);
- 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, "openLogSender: already unregister");
- m_isOpenLogSender = false;
- return std::pair<DWORD, std::string>(WARN_GUICONSOLE_LOG_ALREADY_UNREGISTER, "openLogSender: already register");
- }
- else
- {
- auto rc = GetFunction()->UnsubscribeLog(m_logSubID);
- if(rc == ErrorCodeEnum::Error_Succeed)
- m_logSubID = 0;
- m_isOpenLogSender = !(rc == ErrorCodeEnum::Error_Succeed);
- return std::pair<DWORD, std::string>(rc, "");
- }
- }
- std::pair<DWORD, std::string> CGUIConsoleEntity::openEntityMonitor()
- {
- m_isOpenEntityMonitor = true;
- /*
- timer->stop();
- ui->performTableWidget->clearContents();
- process->start("/bin/bash");
- if(process->waitForStarted(3000)) {
- process->write(cmd.toLatin1());
- process->closeWriteChannel();
- process->waitForFinished(3000);
- QString result = process->readAllStandardOutput();
- QRegularExpression reg;
- reg.setPattern(" +");
- result = result.replace(reg," ");
- QStringList elemList = result.split("\n");
- elemList.removeFirst();
- elemList.removeLast();
- ui->performTableWidget->setRowCount(elemList.length());
- for(int i=0;i< elemList.length();i++) {
- QString line = elemList.at(i);
- QStringList elems = line.split(" ");
- QString strPID = elems.at(RAW_PID_INDEX);
- bool root = false, related = false;
- for(int j=0; j<ui->performTableWidget->columnCount(); j++) {
- QTableWidgetItem* item = new QTableWidgetItem;
- item->setBackground((i % 2 != 0) ? QColor("#f5f5f5") : QColor("#ffffff"));
- if(j== COLUMN_NAME_INDEX) {
- item->setWhatsThis(strPID);
- line = elems.at(RAW_COMMAND_INDEX);
- if (line.compare("spshell", Qt::CaseInsensitive) == 0
- || line.compare("sphost", Qt::CaseInsensitive) == 0
- || line.compare("cefclient", Qt::CaseInsensitive) == 0
- || line.compare("guardian", Qt::CaseInsensitive) == 0) {
- related = true;
- item->setForeground(QBrush(Qt::red));
- if (line.compare("sphost", Qt::CaseInsensitive) == 0 && elems.count() > 7 && elems.at(7).startsWith("mod_")) {
- line = elems.at(7);
- }
- }
- item->setToolTip(line);
- item->setText(line);
- }
- else if (j == COLUMN_PID_INDEX) {
- item->setTextAlignment(Qt::AlignHCenter);
- item->setText(elems.at(RAW_PID_INDEX));
- }
- else if (j == COLUMN_CPU_INDEX) {
- item->setTextAlignment(Qt::AlignHCenter);
- item->setText(elems.at(RAW_CPU_INDEX));
- }
- else if (j == COLUMN_MEM_INDEX) {
- item->setTextAlignment(Qt::AlignHCenter);
- item->setText(elems.at(RAW_MEM_INDEX));
- }
- else if(j== COLUMN_COMMAND_INDEX)
- {
- line = elems.mid(5).join(" ");
- item->setText(line);
- item->setToolTip(line);
- } else if(j == COLUMN_FDS_INDEX) {
- if (related) {
- int fds = GetProcessFdsImpl(pro, strPID.toInt());
- item->setText(QString::number(fds));
- } else {
- item->setText("NA");
- }
- }
- ui->performTableWidget->setItem(i, j, item);
- }
- }
- }
- timer->start();
-
- */
- return std::pair<DWORD, std::string>(Error_Succeed, "");
- }
- std::pair<DWORD, std::string> CGUIConsoleEntity::closeEntityMonitor()
- {
- m_isOpenEntityMonitor = false;
- 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;
- }
- }
- };
- return std::pair<DWORD, std::string>(Error_Succeed, "");
- }
- std::pair<DWORD, std::string> CGUIConsoleEntity::closePerformanceSender()
- {
- m_isOpenPerformanceSender = false;
- 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, "");
- }
- CGUIConsoleEntity::CGUIConsoleEntity()
- :m_isOpenLogSender(false), m_isOpenEntityMonitor(false), m_isOpenPerformanceSender(false),
- m_sendLogType(LogTypeEnum::Log_Warning)
- {
- }
- CGUIConsoleEntity::~CGUIConsoleEntity()
- {}
- void CGUIConsoleSession::Handle_OpenLogSender(SpReqAnsContext<GUIConsoleService_OpenLogSender_Req, GUIConsoleService_OpenLogSender_Ans>::Pointer ctx)
- {
- 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)
- {
- 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)
- {
- auto ret = m_pEntity->openEntityMonitor();
- ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first);
- }
- void CGUIConsoleSession::Handle_CloseEntityMonitor(SpReqAnsContext<GUIConsoleService_CloseEntityMonitor_Req, GUIConsoleService_CloseEntityMonitor_Ans>::Pointer ctx)
- {
- 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)
- {
- 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)
- {
- 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)
- {
- 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)
- {
- 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)
- {
- 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);
- }
- 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)
- {
- 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;
- }
- 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()
|