Bladeren bron

Z991239-5462 #comment fea: define the function getAllentityList

chenliangyu 1 jaar geleden
bovenliggende
commit
a7cb3b1a44

+ 1 - 1
Module/CMakeLists.txt

@@ -64,7 +64,7 @@ macro(add_module_libraries _module_prefix _module_name _module_version)
         message(STATUS "add test files: ${${_module_name}_TEST_SRCS}")
     endif(BUILD_MOUDLE_TEST)
 
-    add_library(${_module_name} SHARED ${${_module_prefix}_SRCS} ${${_module_name}_TEST_SRCS} "mod_guiconsole/guiconsole_define.h")
+    add_library(${_module_name} SHARED ${${_module_prefix}_SRCS} ${${_module_name}_TEST_SRCS})
 
     target_compile_definitions(${_module_name} PUBLIC "${_module_prefix}_EXPORTS")
     target_include_directories(${_module_name} PRIVATE 

+ 6 - 0
Module/include/EventCode.h

@@ -684,6 +684,12 @@ ERROR_ACCESSAUTH_CONNECT_ACS_x}
 #define WARN_GUICONSOLE_LOG_ALREADY_REGISTER	0x50820001
 //LogSender已反订阅
 #define WARN_GUICONSOLE_LOG_ALREADY_UNREGISTER	0x50820002
+//GetAllEntity-GetAllRegistedEntity失败
+#define WARN_GUICONSOLE_GETALLENTITY_REGISTERED	0x50820011
+//GetAllEntity-GetEntity失败
+#define WARN_GUICONSOLE_GETALLENTITY_GETENTITY	0x50820012
+//no privilige
+#define WARN_GUICONSOLE_NO_PRIVILIGE	0x50820101
 
 
 

+ 49 - 0
Module/mod_guiconsole/GUIConsole_client_g.h

@@ -450,6 +450,55 @@ public:
 		return Error;
 	}
 
+	ErrorCodeEnum GetAllEntityList(GUIConsoleService_GetAllEntityList_Req &Req, CSmartPointer<IAsynWaitSp> &spAsyncWait, DWORD dwTimeout)
+	{
+		CSmartPointer<IClientSessionFunction> pFunc = GetFunction();
+		CAutoBuffer Buf = SpObject2Buffer(Req);
+		if (m_context.checkEmpty())
+		{
+			m_context.AutoGenerate();
+			DbgToBeidou(m_context, m_pEntityBase != NULL ? m_pEntityBase->GetEntityName() : "")();
+			m_context = m_context.upgradeLink();
+		}
+		auto ret = pFunc->AsyncRequest(GUIConsoleService_Method_GetAllEntityList, GUIConsoleService_MethodSignature_GetAllEntityList, Buf, spAsyncWait, m_context, dwTimeout);
+		m_context.clear();
+		return ret;
+	}
+	ErrorCodeEnum GetAllEntityList(GUIConsoleService_GetAllEntityList_Req &Req, GUIConsoleService_GetAllEntityList_Ans &Ans, DWORD dwTimeout)
+	{
+		CSmartPointer<IAsynWaitSp> spAsyncWait;
+		ErrorCodeEnum Error = GetAllEntityList(Req, spAsyncWait, dwTimeout);
+		if (Error == Error_Succeed) {
+			bool bEnd = false;
+			Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwTimeout);
+			LOG_ASSERT(Error || bEnd);
+		}
+		return Error;
+	}
+	ErrorCodeEnum GetAllEntityList(GUIConsoleService_GetAllEntityList_Req &Req, GUIConsoleService_GetAllEntityList_Ans &Ans, DWORD dwTimeout, DWORD &dwUserError, CSimpleString &str)
+	{
+		CSmartPointer<IAsynWaitSp> spAsyncWait;
+		ErrorCodeEnum Error = GetAllEntityList(Req, spAsyncWait, dwTimeout);
+		if (Error == Error_Succeed) {
+			bool bEnd = false;
+			Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);
+			LOG_ASSERT(Error || bEnd);
+		}
+		return Error;
+	}
+	ErrorCodeEnum GetAllEntityList(GUIConsoleService_GetAllEntityList_Req &Req, GUIConsoleService_GetAllEntityList_Ans &Ans, DWORD dwTimeout, DWORD &dwUserError)
+	{
+		CSmartPointer<IAsynWaitSp> spAsyncWait;
+		ErrorCodeEnum Error = GetAllEntityList(Req, spAsyncWait, dwTimeout);
+		if (Error == Error_Succeed) {
+			bool bEnd = false;
+			CSimpleString str;
+			Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);
+			LOG_ASSERT(Error || bEnd);
+		}
+		return Error;
+	}
+
 
 	bool SafeDelete()
 	{

+ 34 - 1
Module/mod_guiconsole/GUIConsole_def_g.h

@@ -20,6 +20,7 @@ namespace GUIConsole {
 #define GUIConsoleService_Method_ClosePerformanceSender 5
 #define GUIConsoleService_Method_VTMSystemControl 6
 #define GUIConsoleService_Method_VTM_controlEntity 7
+#define GUIConsoleService_Method_GetAllEntityList 8
 
 #define GUIConsoleService_MethodSignature_OpenLogSender -744778557
 #define GUIConsoleService_MethodSignature_CloseLogSender -1838250527
@@ -29,6 +30,7 @@ namespace GUIConsole {
 #define GUIConsoleService_MethodSignature_ClosePerformanceSender 975418125
 #define GUIConsoleService_MethodSignature_VTMSystemControl -1084584417
 #define GUIConsoleService_MethodSignature_VTM_controlEntity -580226164
+#define GUIConsoleService_MethodSignature_GetAllEntityList 1179841316
 
 #define GUIConsoleService_LogCode_OpenLogSender "QLR040250800"
 #define GUIConsoleService_LogCode_CloseLogSender "QLR040250801"
@@ -38,6 +40,7 @@ namespace GUIConsole {
 #define GUIConsoleService_LogCode_ClosePerformanceSender "QLR040250805"
 #define GUIConsoleService_LogCode_VTMSystemControl "QLR040250806"
 #define GUIConsoleService_LogCode_VTM_controlEntity "QLR040250807"
+#define GUIConsoleService_LogCode_GetAllEntityList "QLR040250808"
 
 struct GUIConsoleService_OpenLogSender_Req
 {
@@ -191,7 +194,7 @@ struct GUIConsoleService_ClosePerformanceSender_Ans
 
 struct GUIConsoleService_VTMSystemControl_Req
 {
-	int rebootFunction;
+	CSimpleStringA rebootFunction;
 	int reserved2;
 	CSimpleStringA reserved3;
 
@@ -241,6 +244,36 @@ struct GUIConsoleService_VTM_controlEntity_Ans
 
 };
 
+struct GUIConsoleService_GetAllEntityList_Req
+{
+	int reserved1;
+	int reserved2;
+	CSimpleStringA reserved3;
+
+	void Serialize(SpBuffer &Buf)
+	{
+		auto & buf = Buf & reserved1 & reserved2 & reserved3;
+	}
+
+};
+
+struct GUIConsoleService_GetAllEntityList_Ans
+{
+	bool result;
+	CSimpleStringA additionalMsg;
+	CAutoArray<CSimpleStringA> entityName;
+	CAutoArray<CSimpleStringA> status;
+	CAutoArray<CSimpleStringA> processId;
+	CAutoArray<CSimpleStringA> versionNo;
+	CAutoArray<CSimpleStringA> lastStartTime;
+
+	void Serialize(SpBuffer &Buf)
+	{
+		auto & buf = Buf & result & additionalMsg & entityName & status & processId & versionNo & lastStartTime;
+	}
+
+};
+
 
 ///////////////////////////
 

+ 27 - 0
Module/mod_guiconsole/GUIConsole_server_g.h

@@ -86,6 +86,13 @@ public:
 				Error = Error_MethodSignatureFailed;
 			}
 			break;
+		case GUIConsoleService_Method_GetAllEntityList:
+			if (dwSignature == GUIConsoleService_MethodSignature_GetAllEntityList) {
+				bOverlap = true;
+			} else {
+				Error = Error_MethodSignatureFailed;
+			}
+			break;
 		default:
 			Error = Error_MethodNotFound;
 			break;
@@ -137,6 +144,11 @@ public:
 				Error = Error_MethodSignatureFailed;
 			}
 			break;
+		case GUIConsoleService_Method_GetAllEntityList:
+			if (dwSignature != GUIConsoleService_MethodSignature_GetAllEntityList) {
+				Error = Error_MethodSignatureFailed;
+			}
+			break;
 		default:
 			Error = Error_MethodNotFound;
 			break;
@@ -184,6 +196,11 @@ public:
 	/// override by user
 	}
 
+	virtual void Handle_GetAllEntityList(SpReqAnsContext<GUIConsoleService_GetAllEntityList_Req, GUIConsoleService_GetAllEntityList_Ans>::Pointer ctx)
+	{
+	/// override by user
+	}
+
 	virtual void OnRequest(CSmartPointer<ITransactionContext> pTransactionContext)
 	{
 		CAutoBuffer Buf;
@@ -280,6 +297,16 @@ public:
 						Handle_VTM_controlEntity(ctx);
 					}
 					break;
+				case GUIConsoleService_Method_GetAllEntityList:
+					{
+						SpReqAnsContext<GUIConsoleService_GetAllEntityList_Req,GUIConsoleService_GetAllEntityList_Ans>::Pointer ctx;
+						ctx.Attach(new SpReqAnsContext<GUIConsoleService_GetAllEntityList_Req,GUIConsoleService_GetAllEntityList_Ans>(pTransactionContext));
+						SpBuffer2Object(Buf, ctx->Req);
+						pTransactionContext->GetLinkContext(ctx->link);
+						EntityResource::setLink(ctx->link);
+						Handle_GetAllEntityList(ctx);
+					}
+					break;
 				default:
 					assert(0);
 					break;

+ 1 - 1
Module/mod_guiconsole/GuiConsole.xml

@@ -69,7 +69,7 @@
 		</twoway>
 		<twoway name="VTMSystemControl" overlap="true">
 			<req>
-				<param name="rebootFunction" type="int"/>
+				<param name="rebootFunction" type="string"/>
 				<param name="reserved2" type="int"/>
 				<param name="reserved3" type="string"/>
 			</req>

+ 1 - 0
Module/mod_guiconsole/guiconsole_define.h

@@ -10,6 +10,7 @@ struct EntityEntry
 	int Pid;
 	int DevelopID;
 	int DebugLevel;
+	CSmallDateTime lastStartTime;
 
 	static const char* GetTypeName(int type)
 	{

+ 6 - 4
Module/mod_guiconsole/mod_GuiConsole.h

@@ -28,6 +28,8 @@ public:
 	virtual void Handle_VTMSystemControl(SpReqAnsContext<GUIConsoleService_VTMSystemControl_Req, GUIConsoleService_VTMSystemControl_Ans>::Pointer ctx);
 
 	virtual void Handle_VTM_controlEntity(SpReqAnsContext<GUIConsoleService_VTM_controlEntity_Req, GUIConsoleService_VTM_controlEntity_Ans>::Pointer ctx);
+
+	virtual void Handle_GetAllEntityList(SpReqAnsContext<GUIConsoleService_GetAllEntityList_Req, GUIConsoleService_GetAllEntityList_Ans>::Pointer ctx);
 private:
 	CGUIConsoleEntity* m_pEntity;
 };
@@ -62,8 +64,8 @@ public:
 	std::pair<DWORD, std::string> closeEntityMonitor();
 	std::pair<DWORD, std::string> openPerformanceSender();
 	std::pair<DWORD, std::string> closePerformanceSender();
-	std::pair<DWORD, std::string> VTMSystemControl();
-	std::pair<DWORD, std::string> VTM_controlEntity();
+	std::pair<DWORD, std::string> VTMSystemControl(SpReqAnsContext<GUIConsoleService_VTMSystemControl_Req, GUIConsoleService_VTMSystemControl_Ans>::Pointer ctx);
+	std::pair<DWORD, std::string> VTM_controlEntity(SpReqAnsContext<GUIConsoleService_VTM_controlEntity_Req, GUIConsoleService_VTM_controlEntity_Ans>::Pointer ctx);
 
 private:
 	// ILogListener
@@ -81,14 +83,14 @@ private:
 	virtual void OnUserStateHook(const char* pszEntityName, DWORD dwState, DWORD dwLastState) {}
 
 
-private:
+public:
 	ErrorCodeEnum AsyncStartEntity(const char* entity_name, const char* cmdline, void* pData);
 	ErrorCodeEnum AsyncStopEntity(const char* entity_name, void* pData);
 	ErrorCodeEnum AsyncPauseEntity(const char* entity_name, void* pData);
 	ErrorCodeEnum AsyncContinueEntity(const char* entity_name, void* pData);
 	ErrorCodeEnum AsyncTerminateEntity(const char* entity_name, void* pData);
 	ErrorCodeEnum GetEntity(const char* entity_name, EntityEntry& e);
-	ErrorCodeEnum GetAllEntity(CAutoArray<EntityEntry>& Entities);
+	std::pair<DWORD, std::string> GetAllEntity(CAutoArray<EntityEntry>& Entities);
 	//ICallbackListener
 	virtual void OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp);
 

+ 87 - 13
Module/mod_guiconsole/mod_guiconsole.cpp

@@ -1,7 +1,7 @@
 #include "mod_GuiConsole.h"
 #include "publicFunExport.h"
 #include <EventCode.h>
-#include <mod_guiconsole/GUIConsole_msg_g.h>
+#include "GUIConsole_msg_g.h"
 
 
 bool isPad = false;
@@ -137,15 +137,47 @@ std::pair<DWORD, std::string> CGUIConsoleEntity::closePerformanceSender()
 	return std::pair<DWORD, std::string>(Error_Succeed, "");
 }
 
-std::pair<DWORD, std::string> CGUIConsoleEntity::VTMSystemControl()
+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(ErrorCodeEnum::)
+
+
+	if(!ctx->Req.rebootFunction.Compare("RestartApp", true))
+		
 	return std::pair<DWORD, std::string>(Error_Succeed, "");
 }
 
-std::pair<DWORD, std::string> CGUIConsoleEntity::VTM_controlEntity()
+std::pair<DWORD, std::string> CGUIConsoleEntity::VTM_controlEntity(SpReqAnsContext<GUIConsoleService_VTM_controlEntity_Req, GUIConsoleService_VTM_controlEntity_Ans>::Pointer ctx)
 {
-	
-	return std::pair<DWORD, std::string>(Error_Succeed, "");
+	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);
+
+
+	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()
@@ -201,10 +233,39 @@ void CGUIConsoleSession::Handle_VTMSystemControl(SpReqAnsContext<GUIConsoleServi
 
 void CGUIConsoleSession::Handle_VTM_controlEntity(SpReqAnsContext<GUIConsoleService_VTM_controlEntity_Req, GUIConsoleService_VTM_controlEntity_Ans>::Pointer ctx)
 {
-	auto ret = m_pEntity->VTM_controlEntity();
+	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());
+
+	CSimpleStringA activeVer;
+	m_pEntity->GetFunction()->GetRunningVersion(activeVer);
+	for (int i = 0; i < Entities.GetCount(); ++i) {
+		ctx->Ans.entityName[i] = Entities[i].Name;
+		ctx->Ans.status[i] = Entities[i].GetStateName(Entities[i].State);
+		ctx->Ans.processId[i] = Entities[i].Pid;
+		ctx->Ans.versionNo[i] = activeVer;
+		ctx->Ans.lastStartTime[i] = Entities[i].lastStartTime.ToTimeString();
+	}
+	ctx->Answer(Error_Succeed);
+}
+
+
+
 ErrorCodeEnum CGUIConsoleEntity::AsyncStartEntity(const char* entity_name, const char* cmdline, void* pData)
 {
 	CSmartPointer<IEntityFunction> pFunc = GetFunction();
@@ -330,25 +391,38 @@ ErrorCodeEnum CGUIConsoleEntity::GetEntity(const char* entity_name, EntityEntry&
 			e.Pid = (int)RunInfo.dwProcessID;
 			e.DevelopID = (int)StaticInfo.wEntityDevelopID;
 			e.DebugLevel = RunInfo.eDebugLevel;
+			e.lastStartTime = RunInfo.tmLastStart;
 		}
 	}
 	return Error;
 }
 
 
-ErrorCodeEnum CGUIConsoleEntity::GetAllEntity(CAutoArray<EntityEntry>& Entities)
+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 == Error_Succeed) {
-		Entities.Init(strEntityNames.GetCount());
-		for (int i = 0; i < strEntityNames.GetCount(); ++i) {
-			Error = GetEntity(strEntityNames[i], Entities[i]);
-		}
+	if (Error_Succeed != Error)
+	{
+		LogWarn(SeverityLevelEnum::Severity_Middle, Error, WARN_GUICONSOLE_GETALLENTITY_REGISTERED, "GetAllEntity-GetAllRegistedEntity failed");
+		return std::make_pair(WARN_GUICONSOLE_GETALLENTITY_REGISTERED, "");
 	}
-	return Error;
+	
+	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)