#include "mod_GuiConsole.h" #include "publicFunExport.h" #include #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; 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.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 CGUIConsoleEntity::openLogSender() { 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 rc = GetFunction()->SubscribeLog(m_logSubID, this, Log_Ignore, Severity_None, Error_IgnoreAll, -1, NULL, false); 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, "openLogSender: already unregister"); m_isOpenLogSender = false; return std::pair(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(rc, ""); } } std::pair CGUIConsoleEntity::openEntityMonitor() { m_isOpenEntityMonitor = true; return std::pair(Error_Succeed, ""); } std::pair CGUIConsoleEntity::closeEntityMonitor() { m_isOpenEntityMonitor = false; return std::pair(Error_Succeed, ""); } std::pair CGUIConsoleEntity::openPerformanceSender() { m_isOpenPerformanceSender = true; return std::pair(Error_Succeed, ""); } std::pair CGUIConsoleEntity::closePerformanceSender() { m_isOpenPerformanceSender = false; return std::pair(Error_Succeed, ""); } std::pair CGUIConsoleEntity::VTMSystemControl() { return std::pair(Error_Succeed, ""); } std::pair CGUIConsoleEntity::VTM_controlEntity() { return std::pair(Error_Succeed, ""); } CGUIConsoleEntity::CGUIConsoleEntity() :m_isOpenLogSender(false), m_isOpenEntityMonitor(false), m_isOpenPerformanceSender(false) { } CGUIConsoleEntity::~CGUIConsoleEntity() {} void CGUIConsoleSession::Handle_OpenLogSender(SpReqAnsContext::Pointer ctx) { auto ret = m_pEntity->openLogSender(); ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first); } void CGUIConsoleSession::Handle_CloseLogSender(SpReqAnsContext::Pointer ctx) { auto ret = m_pEntity->closeLogSender(); ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first); } void CGUIConsoleSession::Handle_OpenEntityMonitor(SpReqAnsContext::Pointer ctx) { auto ret = m_pEntity->openEntityMonitor(); ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first); } void CGUIConsoleSession::Handle_CloseEntityMonitor(SpReqAnsContext::Pointer ctx) { auto ret = m_pEntity->closeEntityMonitor(); ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first); } void CGUIConsoleSession::Handle_OpenPerformanceSender(SpReqAnsContext::Pointer ctx) { auto ret = m_pEntity->openPerformanceSender(); ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first); } void CGUIConsoleSession::Handle_ClosePerformanceSender(SpReqAnsContext::Pointer ctx) { auto ret = m_pEntity->closePerformanceSender(); ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first); } void CGUIConsoleSession::Handle_VTMSystemControl(SpReqAnsContext::Pointer ctx) { auto ret = m_pEntity->VTMSystemControl(); ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first); } void CGUIConsoleSession::Handle_VTM_controlEntity(SpReqAnsContext::Pointer ctx) { auto ret = m_pEntity->VTM_controlEntity(); ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first); } 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; } } return Error; } ErrorCodeEnum CGUIConsoleEntity::GetAllEntity(CAutoArray& Entities) { CSmartPointer spFunc = GetFunction(); CAutoArray strEntityNames; CAutoArray wDevelopIDs; ErrorCodeEnum Error = spFunc->GetAllRegistedEntity(strEntityNames, wDevelopIDs); if (Error == Error_Succeed) { Entities.Init(strEntityNames.GetCount()); for (int i = 0; i < strEntityNames.GetCount(); ++i) { Error = GetEntity(strEntityNames[i], Entities[i]); } } return Error; } void CGUIConsoleEntity::OnAnswer(CSmartPointer pAsynWaitSp) { /* if (m_hWndMainFrame) { 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(); 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; PostMessage(m_hWndMainFrame, WM_GUICONSOLE, 0, (LPARAM)new_entry); } */ } SP_BEGIN_ENTITY_MAP() SP_ENTITY(CGUIConsoleEntity) SP_END_ENTITY_MAP()