|
@@ -1,6 +1,7 @@
|
|
|
-
|
|
|
#include "mod_GuiConsole.h"
|
|
|
#include "publicFunExport.h"
|
|
|
+#include <EventCode.h>
|
|
|
+#include <mod_guiconsole/GUIConsole_msg_g.h>
|
|
|
|
|
|
|
|
|
bool isPad = false;
|
|
@@ -22,15 +23,356 @@ void CGUIConsoleEntity::OnLog(const CAutoArray<CUUID>& SubIDs, const CUUID nLogI
|
|
|
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.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()
|
|
|
+{
|
|
|
+ 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 rc = GetFunction()->SubscribeLog(m_logSubID, this, Log_Ignore, 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;
|
|
|
+ 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()
|
|
|
+{
|
|
|
+ m_isOpenPerformanceSender = true;
|
|
|
+ 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()
|
|
|
+{
|
|
|
+ return std::pair<DWORD, std::string>(Error_Succeed, "");
|
|
|
+}
|
|
|
+
|
|
|
+std::pair<DWORD, std::string> CGUIConsoleEntity::VTM_controlEntity()
|
|
|
{
|
|
|
|
|
|
+ return std::pair<DWORD, std::string>(Error_Succeed, "");
|
|
|
+}
|
|
|
+
|
|
|
+CGUIConsoleEntity::CGUIConsoleEntity()
|
|
|
+ :m_isOpenLogSender(false), m_isOpenEntityMonitor(false), m_isOpenPerformanceSender(false)
|
|
|
+{
|
|
|
+}
|
|
|
+
|
|
|
+CGUIConsoleEntity::~CGUIConsoleEntity()
|
|
|
+{}
|
|
|
+
|
|
|
+
|
|
|
+void CGUIConsoleSession::Handle_OpenLogSender(SpReqAnsContext<GUIConsoleService_OpenLogSender_Req, GUIConsoleService_OpenLogSender_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ auto ret = m_pEntity->openLogSender();
|
|
|
+ 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->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->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->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first);
|
|
|
+}
|
|
|
+
|
|
|
+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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Error;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ErrorCodeEnum CGUIConsoleEntity::GetAllEntity(CAutoArray<EntityEntry>& Entities)
|
|
|
+{
|
|
|
+ CSmartPointer<IEntityFunction> spFunc = GetFunction();
|
|
|
+ CAutoArray<CSimpleStringA> strEntityNames;
|
|
|
+ CAutoArray<WORD> 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<IAsynWaitSp> pAsynWaitSp)
|
|
|
+{
|
|
|
+ /*
|
|
|
+ if (m_hWndMainFrame) {
|
|
|
+ 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();
|
|
|
+ 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)
|