Преглед изворни кода

Z991239-751 #comment module文件夹大小写敏感

80374374 пре 5 година
родитељ
комит
32686b6082

+ 0 - 0
module/CMakeLists.txt → Module/CMakeLists.txt


+ 0 - 0
module/include/modVer.h.in → Module/include/modVer.h.in


+ 23 - 23
module/mod_rpc/format.hpp → Module/mod_rpc/format.hpp

@@ -1,23 +1,23 @@
-#include "boost/format.hpp"
-#include <iostream>
-
-template<class TFirst>
-void string_format(boost::format& fmt, TFirst&& first)
-{
-    fmt% first;
-}
-
-template<class TFirst, class... TOther>
-void string_format(boost::format& fmt, TFirst&& first, TOther&&... other)
-{
-    fmt% first;
-    string_format(fmt, other...);
-}
-
-template<class TFirst, class... TOther>
-std::string string_format(const char* format, TFirst&& first, TOther&&... other)
-{
-    boost::format fmt(format);
-    string_format(fmt, first, other...);
-    return fmt.str();
-}
+#include "boost/format.hpp"
+#include <iostream>
+
+template<class TFirst>
+void string_format(boost::format& fmt, TFirst&& first)
+{
+    fmt% first;
+}
+
+template<class TFirst, class... TOther>
+void string_format(boost::format& fmt, TFirst&& first, TOther&&... other)
+{
+    fmt% first;
+    string_format(fmt, other...);
+}
+
+template<class TFirst, class... TOther>
+std::string string_format(const char* format, TFirst&& first, TOther&&... other)
+{
+    boost::format fmt(format);
+    string_format(fmt, first, other...);
+    return fmt.str();
+}

+ 591 - 591
module/mod_rpc/guitask.cpp → Module/mod_rpc/guitask.cpp

@@ -1,591 +1,591 @@
-
-#include "SpBase.h"
-#include "guitask.h"
-
-struct callback_entry : public IReleasable
-{
-	virtual ~callback_entry() {}
-
-	CSimpleStringA EntityName;
-	union {
-		void* pRawData;
-		int state;
-	};
-	int op;
-	ErrorCodeEnum ErrorResult;
-};
-
-#define OP_START_ENTITY		1
-#define OP_STOP_ENTITY		0
-#define OP_PAUSE_ENTITY		2
-#define OP_TERMINATE_ENTITY 3
-#define OP_CONTINUE_ENTITY	4
-#define OP_FIRE_ENTITY_STATE		5
-
-GUITask::GUITask() : m_pEntity(NULL), m_hWndMainFrame(NULL), m_hThread(NULL)
-{
-	m_hEventStartReady = ::CreateEventA(NULL, TRUE, FALSE, NULL);
-	m_hEventStopReady = ::CreateEventA(NULL, TRUE, FALSE, NULL);
-}
-
-GUITask::~GUITask()
-{
-	CloseHandle(m_hEventStopReady);
-	CloseHandle(m_hEventStartReady);
-}
-GUITask g_task;
-
-namespace rpcFunc
-{
-	
-	bool StartEntity(rpc_conn conn, std::string entityName)
-	{
-		ErrorCodeEnum Error = g_task.AsyncStartEntity(entityName.c_str(), NULL, NULL);
-		if (Error == Error_Succeed) {
-			Dbg("startEntiy %s success!!", entityName.c_str());
-			return true;
-		}
-		Dbg("start %s failed, error = 0x%08X\r\n", entityName.c_str(), Error);
-		return false;
-	}
-
-	bool StopEntity(rpc_conn conn, std::string entityName)
-	{
-		ErrorCodeEnum Error = g_task.AsyncStopEntity(entityName.c_str(), NULL);
-		if (Error == Error_Succeed) {
-			Dbg("StopEntity %s success!!", entityName.c_str());
-			return true;
-		}
-
-		Dbg("stop %s failed, error = 0x%08X\r\n", entityName.c_str(), Error);
-		return false;
-	}
-
-	bool PauseEntity(rpc_conn conn, std::string entityName)
-	{
-		ErrorCodeEnum Error = g_task.AsyncPauseEntity(entityName.c_str(), NULL);
-		if (Error == Error_Succeed) {
-			Dbg("PauseEntity %s success!!", entityName.c_str());
-			return true;
-		}
-		Dbg("pause %s failed, error = 0x%08X\r\n", entityName.c_str(), Error);
-		return false;
-	}
-
-	bool ContinueEntity(rpc_conn conn, std::string entityName)
-	{
-		ErrorCodeEnum Error = g_task.AsyncContinueEntity(entityName.c_str(), NULL);
-		if (Error == Error_Succeed) {
-			Dbg("ContinueEntity %s success!!", entityName.c_str());
-			return true;
-		}
-		Dbg("continue %s failed, error = 0x%08X\r\n", entityName.c_str(), Error);
-		return false;
-	}
-
-	bool TerminateEntity(rpc_conn conn, std::string entityName)
-	{
-		ErrorCodeEnum Error = g_task.AsyncTerminateEntity(entityName.c_str(), NULL);
-		if (Error == Error_Succeed) {
-			Dbg("TerminateEntity %s success!!", entityName.c_str());
-			return true;
-		}
-		Dbg("Terminate %s failed, error = 0x%08X\r\n", entityName.c_str(), Error);
-		return false;
-	}
-
-	template <class T> std::vector<T> autoArryTovector(const CAutoArray<T>* p)
-	{
-		std::vector<T> dst;
-		for (size_t i = 0; p != nullptr && i < p->GetCount(); i++)
-			dst.push_back(*p[i]);
-		return dst;
-	}
-
-	EntityEntryPlusVec GetAllEntity(rpc_conn conn)
-	{
-		CAutoArray<EntityEntry> Entities;
-		ErrorCodeEnum Error = g_task.GetAllEntity(Entities);
-		if (Error == Error_Succeed)
-			Dbg("GetAllEntity success!!, entityNum:%d", Entities.GetCount());
-		else
-			Dbg("GetAllEntity failed, error = 0x%08X\r\n", Error);
-		std::vector<EntityEntryPlus> dst;
-		for (size_t i = 0; i < Entities.GetCount(); i++)
-			dst.push_back({ Entities[i].Name.GetData(), Entities[i].ModuleName.GetData(), Entities[i].Type, Entities[i].State, Entities[i].Id, Entities[i].Pid, Entities[i].DevelopID, Entities[i].DebugLevel });
-		EntityEntryPlusVec ret;
-		ret.entityArr = dst;
-		return ret;
-	}
-
-}
-
-using namespace rpcFunc;
-
-
-
-bool GUITask::openrpcServer(int port)
-{
-	std::thread thd([&] {
-		m_server.reset(new rpc_server(port, std::thread::hardware_concurrency()));
-
-		m_server->register_handler("StartEntity", StartEntity);
-		m_server->register_handler("StopEntity", StopEntity);
-		m_server->register_handler("PauseEntity", PauseEntity);
-		m_server->register_handler("ContinueEntity", ContinueEntity);
-		m_server->register_handler("TerminateEntity", TerminateEntity);
-		m_server->register_handler("GetAllEntity", rpcFunc::GetAllEntity);
-
-
-		m_server->register_handler("publish", [&](rpc_conn conn, std::string key, std::string token, std::string val) {
-			m_server->publish(std::move(key), std::move(val));
-		});
-
-		m_server->run();
-	});
-
-	thd.detach();
-	Dbg("rpc start, async run");
-
-	return true;
-}
-
-void GUITask::publishMsg(outputMsg out)
-{
-	m_server->publish("outMsg", out);
-}
-
-template<class TFirst, class... TOther>
-void outputMsgToGUI(const char* format, TFirst&& first, TOther&&... other)
-{
-	auto msg = string_format(format, first, other);
-	g_task.publishMsg({ "togui", 4 /*Debug*/, 1 /*Low*/, 0, 0, msg });
-}
-
-
-
-ErrorCodeEnum GUITask::RegistEntityStateEvent()
-{
-	CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
-	CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
-	if (pFuncPrivilege != NULL) {
-		return pFuncPrivilege->RegistEntityStateEvent(NULL, this); // NULL to register for all
-	} else {
-		return Error_NoPrivilege;
-	}
-}
-
-ErrorCodeEnum GUITask::UnregistEntityStateEvent()
-{
-	CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
-	CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
-	if (pFuncPrivilege != NULL)
-		return pFuncPrivilege->UnregistEntityStateEvent(NULL);
-	else 
-		return Error_NoPrivilege;
-
-}
-
-ErrorCodeEnum GUITask::ReqFrameworkQuit(bool bRebootOS)
-{
-	CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
-	CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
-	if (pFuncPrivilege != NULL) 
-		return pFuncPrivilege->Reboot(RebootTrigger_ManualLocal, bRebootOS ? RebootWay_OS : RebootWay_Framework );
-
-	return Error_Unexpect;
-}
-
-ErrorCodeEnum GUITask::SubscribeLog()
-{
-	return m_pEntity->GetFunction()->SubscribeLog(m_logSubID,  this, Log_Ignore, Severity_None, Error_IgnoreAll, -2, NULL, false);
-}
-
-ErrorCodeEnum GUITask::UnSubscribeLog()
-{
-	if ((__int64)m_logSubID != 0)
-	{
-		m_pEntity->GetFunction()->UnsubscribeLog(m_logSubID);
-		m_logSubID = 0;
-	}
-
-	return Error_Succeed;
-}
-
-ErrorCodeEnum GUITask::SetDebugLevel(const char *pszEntity, int nLevel)
-{
-	return m_pEntity->GetFunction()->GetPrivilegeFunction()->SetSysDebugLevel(pszEntity, (DebugLevelEnum)nLevel, true);
-}
-
-ErrorCodeEnum GUITask::GetShellDebugLevel(int &nLevel)
-{
-	CSystemRunInfo info ={};
-	auto rc = m_pEntity->GetFunction()->GetSystemRunInfo(info);
-	if (rc == Error_Succeed)
-		nLevel = info.eDebugLevel;
-
-	return rc;
-}
-
-
-ErrorCodeEnum GUITask::BeginAccessAuth()
-{
-	return Error_Succeed;
-}
-
-ErrorCodeEnum GUITask::BeginInitialize()
-{
-	return Error_Succeed;
-}
-
-
-ErrorCodeEnum GUITask::DeleteKeySet()
-{
-	return Error_Succeed;
-}
-
-ErrorCodeEnum GUITask::GetFrameworkInfo(CSimpleStringA &strInfo)
-{
-	CSystemStaticInfo info;
-	memset(&info, 0, sizeof(info));
-	auto rc = m_pEntity->GetFunction()->GetSystemStaticInfo(info);
-	if (rc == Error_Succeed)
-		strInfo = CSimpleStringA::Format("[%s] [%s]", (const char*) info.strTerminalID, (const char*)info.InstallVersion.ToString());
-
-	return rc;
-}
-
-void GUITask::Kickoff(CEntityBase* pEntity)
-{
-	m_pEntity = pEntity;
-	
-	RegistEntityStateEvent();
-}
-
-ErrorCodeEnum GUITask::AsyncStartEntity(const char *entity_name, const char *cmdline, void *pData)
-{
-	CSmartPointer<IEntityFunction> pFunc = m_pEntity->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 GUITask::AsyncStopEntity(const char *entity_name, void *pData)
-{
-	CSmartPointer<IEntityFunction> pFunc = m_pEntity->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 GUITask::AsyncPauseEntity(const char *entity_name, void *pData)
-{
-	CSmartPointer<IEntityFunction> pFunc = m_pEntity->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 GUITask::AsyncContinueEntity(const char *entity_name, void *pData)
-{
-	CSmartPointer<IEntityFunction> pFunc = m_pEntity->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 GUITask::AsyncTerminateEntity(const char *entity_name, void *pData)
-{
-	CSmartPointer<IEntityFunction> pFunc = m_pEntity->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 GUITask::GetAllEntity(CAutoArray<EntityEntry> &Entities)
-{
-	CSmartPointer<IEntityFunction> spFunc = m_pEntity->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;
-}
-
-ErrorCodeEnum GUITask::GetEntity(const char *entity_name, EntityEntry &e)
-{
-	CSmartPointer<IEntityFunction> spFunc = m_pEntity->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 GUITask::GetCustomizeStartMenuList(CAutoArray<StartMenuEntry> &StartItems)
-{
-	CSmartPointer<IEntityFunction> spFunc = m_pEntity->GetFunction();
-	CSmartPointer<IConfigInfo> spConfig;
-	LOG_ASSERT(spFunc != NULL);
-	int cnt = 0;
-	ErrorCodeEnum Error = spFunc->OpenConfig(Config_Software, spConfig);
-	if (Error != Error_Succeed)
-		return Error;
-	Error = spConfig->ReadConfigValueInt("StartMenu", "Number", cnt);
-	if (Error != Error_Succeed)
-		return Error;
-	StartItems.Init(cnt);
-	for (int i = 0; i < cnt; ++i) {
-		char tmp[128];
-		CSimpleStringA strValue;
-		_itoa(i+1, tmp, 10);
-		Error = spConfig->ReadConfigValue("StartMenu", tmp, strValue);
-		const char *p = strValue;
-		if (Error != Error_Succeed || p == NULL || strValue.GetLength() == 0)
-			break;
-		int kk = 0;
-		while (*p && *p != ' ') {
-			tmp[kk++] = *p;
-			p++;
-		}
-		tmp[kk] = 0;
-		StartItems[i].strEntity = tmp;
-		while (*p && *p == ' ')
-			p++;
-		if (*p) {
-			StartItems[i].strCmdLine = p;
-		} else {
-			StartItems[i].strCmdLine = "";
-		}
-	}
-	return Error;
-}
-
-void GUITask::OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp)
-{
-
-}
-
-
-ErrorCodeEnum GUITask::OutputMsg(const char *pMsg)
-{
-	return Error_Succeed;
-}
-
-
-void GUITask::OnEntityStateHook(const char *pszEntityName,const char *pszTriggerEntity,EntityStateEnum eState,EntityStateEnum eLastState)
-{
-	CEntityRunInfo Info;
-	CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
-	pFunc->GetEntityRunInfo(pszEntityName, Info);
-
-	entityStateChange cur = { pszEntityName , eState , Info.dwProcessID };
-	m_server->publish("EntityStateChange", cur);
-}
-
-void GUITask::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)
-{
-	
-	// 忽略GPIO事件
-	if (dwUserCode == 0x2090000A || dwUserCode == 0x20900009)
-		return;
-
-	if (pszMessage!=NULL && strlen(pszMessage)>2)
-	{
-		CSimpleStringA str = pszMessage;
-		if (str[str.GetLength()-2] == '\r' && str[str.GetLength()-1]=='\n')
-			str[str.GetLength()-2] = 0;
-						
-		if (eLogType == Log_Error)
-			m_lastErrorMsg = str = CSimpleStringA::Format("[%s] Error:{%s}(sc:0x%X, uc:0x%X)\r\n", pszEntityName, (const char*)str, dwSysError, dwUserCode);
-		else if(eLogType == Log_Warning)
-			str = CSimpleStringA::Format("[%s] Warn:{%s}(sc:0x%X, uc:0x%X)\r\n", pszEntityName, (const char*)str, dwSysError, dwUserCode);
-		else if(eLogType == Log_Event)
-			str = CSimpleStringA::Format("[%s] Event:{%s}(uc:0x%X)\r\n", pszEntityName, (const char*)str, dwUserCode);
-		else if (eLogType == Log_Debug)
-			str = CSimpleStringA::Format("[%s] Debug:{%s}\r\n", pszEntityName, (const char*)str);
-
-		publishMsg({ "togui" ,  4 /*Debug*/, 1 /*Low*/, 0, 0 , str.GetData() });
-	}
-}
-
-CEntityBase* GUITask::GetEntity()
-{
-	return m_pEntity;
-}
-
-ErrorCodeEnum GUITask::ShowMaintainView(bool bShow, bool bHighLevel)
-{
-	return Error_Succeed;
-}
-
-ErrorCodeEnum GUITask::SetWindowPosition(bool bTop)
-{
-	CSystemStaticInfo info;
-	memset(&info, 0, sizeof(info));
-	auto rc = m_pEntity->GetFunction()->GetSystemStaticInfo(info);
-	if (stricmp(info.strMachineType, "RVC.IL") == 0)
-		return Error_Succeed;			
-
-	if (m_hWndMainFrame) 
-	{
-		if (bTop)
-		{
-			ShowWindow(m_hWndMainFrame, SW_NORMAL);
-			SetWindowPos(m_hWndMainFrame, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
-
-			// 启动软键盘
-			// WinExec("osk.exe", SW_NORMAL);
-			//ShellExecuteA(NULL, "open", "osk.exe", NULL, NULL, SW_SHOW);
-		}
-		else
-		{
-			SetWindowPos(m_hWndMainFrame, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
-			ShowWindow(m_hWndMainFrame, SW_MINIMIZE);
-
-			// 关闭软键盘
-			//CloseSoftKeyboard();
-		}
-
-		return Error_Succeed;
-	}
-	else
-		return Error_NotExist;
-}
-
-ErrorCodeEnum GUITask::ShowBeginInit(bool bShow)
-{
-	return Error_Succeed;
-}
-
-void GUITask::CloseSoftKeyboard()
-{
-	HANDLE hProcessHandle;
-	ULONG nProcessID;
-	HWND kbWindow;
-	kbWindow = ::FindWindow(NULL, _T("屏幕键盘"));
-	if (NULL != kbWindow)
-	{
-		::GetWindowThreadProcessId(kbWindow, &nProcessID);
-		hProcessHandle = ::OpenProcess(PROCESS_TERMINATE, FALSE, nProcessID);
-		::TerminateProcess(hProcessHandle, 4);
-	}
-}
-ErrorCodeEnum GUITask::ShowBlueScreen()
-{
-	auto pEntityFunc = m_pEntity->GetFunction();
-	auto pPrevFunc = pEntityFunc->GetPrivilegeFunction();
-	const char *pMsg = "System Failure!System Failure!System Failure!System Failure!System Failure!System Failure!System Failure!System Failure!\r\n系统启动失败,请联系总行开发人员解决!";
-
-	pPrevFunc->DisplayBlueScreen(pMsg);
-	return Error_Succeed;
-}
-
-ErrorCodeEnum GUITask::ShowFatalError()
-{
-	auto pEntityFunc = m_pEntity->GetFunction();
-	const char *pMsg = "开放系统管理员初级培训及认证报名通知.开放系统管理员初级培训及认证报名通知.开放系统管理员初级培训及认证报名通知.开放系统管理员初级培训及认证报名通知.开放系统管理员初级培训及认证报名通知.";
-	pEntityFunc->ShowFatalError(pMsg);
-	return Error_Succeed;
-}
-
-ErrorCodeEnum GUITask::HideBlueScreen()
-{
-	auto pEntityFunc = m_pEntity->GetFunction();
-	auto pPrevFunc = pEntityFunc->GetPrivilegeFunction();
-	return pPrevFunc->UndisplayBlueScreen();
-}
-
-ErrorCodeEnum GUITask::ShowOutputConsole()
-{
-	auto pFunc = m_pEntity->GetFunction()->GetPrivilegeFunction();
-	return pFunc->ShowOuputConsole();
-}
-
-ErrorCodeEnum GUITask::CloseOutputConsole()
-{
-	auto pFunc = m_pEntity->GetFunction()->GetPrivilegeFunction();
-	return pFunc->CloseOuputConsole();
-}
-
+
+#include "SpBase.h"
+#include "guitask.h"
+
+struct callback_entry : public IReleasable
+{
+	virtual ~callback_entry() {}
+
+	CSimpleStringA EntityName;
+	union {
+		void* pRawData;
+		int state;
+	};
+	int op;
+	ErrorCodeEnum ErrorResult;
+};
+
+#define OP_START_ENTITY		1
+#define OP_STOP_ENTITY		0
+#define OP_PAUSE_ENTITY		2
+#define OP_TERMINATE_ENTITY 3
+#define OP_CONTINUE_ENTITY	4
+#define OP_FIRE_ENTITY_STATE		5
+
+GUITask::GUITask() : m_pEntity(NULL), m_hWndMainFrame(NULL), m_hThread(NULL)
+{
+	m_hEventStartReady = ::CreateEventA(NULL, TRUE, FALSE, NULL);
+	m_hEventStopReady = ::CreateEventA(NULL, TRUE, FALSE, NULL);
+}
+
+GUITask::~GUITask()
+{
+	CloseHandle(m_hEventStopReady);
+	CloseHandle(m_hEventStartReady);
+}
+GUITask g_task;
+
+namespace rpcFunc
+{
+	
+	bool StartEntity(rpc_conn conn, std::string entityName)
+	{
+		ErrorCodeEnum Error = g_task.AsyncStartEntity(entityName.c_str(), NULL, NULL);
+		if (Error == Error_Succeed) {
+			Dbg("startEntiy %s success!!", entityName.c_str());
+			return true;
+		}
+		Dbg("start %s failed, error = 0x%08X\r\n", entityName.c_str(), Error);
+		return false;
+	}
+
+	bool StopEntity(rpc_conn conn, std::string entityName)
+	{
+		ErrorCodeEnum Error = g_task.AsyncStopEntity(entityName.c_str(), NULL);
+		if (Error == Error_Succeed) {
+			Dbg("StopEntity %s success!!", entityName.c_str());
+			return true;
+		}
+
+		Dbg("stop %s failed, error = 0x%08X\r\n", entityName.c_str(), Error);
+		return false;
+	}
+
+	bool PauseEntity(rpc_conn conn, std::string entityName)
+	{
+		ErrorCodeEnum Error = g_task.AsyncPauseEntity(entityName.c_str(), NULL);
+		if (Error == Error_Succeed) {
+			Dbg("PauseEntity %s success!!", entityName.c_str());
+			return true;
+		}
+		Dbg("pause %s failed, error = 0x%08X\r\n", entityName.c_str(), Error);
+		return false;
+	}
+
+	bool ContinueEntity(rpc_conn conn, std::string entityName)
+	{
+		ErrorCodeEnum Error = g_task.AsyncContinueEntity(entityName.c_str(), NULL);
+		if (Error == Error_Succeed) {
+			Dbg("ContinueEntity %s success!!", entityName.c_str());
+			return true;
+		}
+		Dbg("continue %s failed, error = 0x%08X\r\n", entityName.c_str(), Error);
+		return false;
+	}
+
+	bool TerminateEntity(rpc_conn conn, std::string entityName)
+	{
+		ErrorCodeEnum Error = g_task.AsyncTerminateEntity(entityName.c_str(), NULL);
+		if (Error == Error_Succeed) {
+			Dbg("TerminateEntity %s success!!", entityName.c_str());
+			return true;
+		}
+		Dbg("Terminate %s failed, error = 0x%08X\r\n", entityName.c_str(), Error);
+		return false;
+	}
+
+	template <class T> std::vector<T> autoArryTovector(const CAutoArray<T>* p)
+	{
+		std::vector<T> dst;
+		for (size_t i = 0; p != nullptr && i < p->GetCount(); i++)
+			dst.push_back(*p[i]);
+		return dst;
+	}
+
+	EntityEntryPlusVec GetAllEntity(rpc_conn conn)
+	{
+		CAutoArray<EntityEntry> Entities;
+		ErrorCodeEnum Error = g_task.GetAllEntity(Entities);
+		if (Error == Error_Succeed)
+			Dbg("GetAllEntity success!!, entityNum:%d", Entities.GetCount());
+		else
+			Dbg("GetAllEntity failed, error = 0x%08X\r\n", Error);
+		std::vector<EntityEntryPlus> dst;
+		for (size_t i = 0; i < Entities.GetCount(); i++)
+			dst.push_back({ Entities[i].Name.GetData(), Entities[i].ModuleName.GetData(), Entities[i].Type, Entities[i].State, Entities[i].Id, Entities[i].Pid, Entities[i].DevelopID, Entities[i].DebugLevel });
+		EntityEntryPlusVec ret;
+		ret.entityArr = dst;
+		return ret;
+	}
+
+}
+
+using namespace rpcFunc;
+
+
+
+bool GUITask::openrpcServer(int port)
+{
+	std::thread thd([&] {
+		m_server.reset(new rpc_server(port, std::thread::hardware_concurrency()));
+
+		m_server->register_handler("StartEntity", StartEntity);
+		m_server->register_handler("StopEntity", StopEntity);
+		m_server->register_handler("PauseEntity", PauseEntity);
+		m_server->register_handler("ContinueEntity", ContinueEntity);
+		m_server->register_handler("TerminateEntity", TerminateEntity);
+		m_server->register_handler("GetAllEntity", rpcFunc::GetAllEntity);
+
+
+		m_server->register_handler("publish", [&](rpc_conn conn, std::string key, std::string token, std::string val) {
+			m_server->publish(std::move(key), std::move(val));
+		});
+
+		m_server->run();
+	});
+
+	thd.detach();
+	Dbg("rpc start, async run");
+
+	return true;
+}
+
+void GUITask::publishMsg(outputMsg out)
+{
+	m_server->publish("outMsg", out);
+}
+
+template<class TFirst, class... TOther>
+void outputMsgToGUI(const char* format, TFirst&& first, TOther&&... other)
+{
+	auto msg = string_format(format, first, other);
+	g_task.publishMsg({ "togui", 4 /*Debug*/, 1 /*Low*/, 0, 0, msg });
+}
+
+
+
+ErrorCodeEnum GUITask::RegistEntityStateEvent()
+{
+	CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
+	CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
+	if (pFuncPrivilege != NULL) {
+		return pFuncPrivilege->RegistEntityStateEvent(NULL, this); // NULL to register for all
+	} else {
+		return Error_NoPrivilege;
+	}
+}
+
+ErrorCodeEnum GUITask::UnregistEntityStateEvent()
+{
+	CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
+	CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
+	if (pFuncPrivilege != NULL)
+		return pFuncPrivilege->UnregistEntityStateEvent(NULL);
+	else 
+		return Error_NoPrivilege;
+
+}
+
+ErrorCodeEnum GUITask::ReqFrameworkQuit(bool bRebootOS)
+{
+	CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
+	CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
+	if (pFuncPrivilege != NULL) 
+		return pFuncPrivilege->Reboot(RebootTrigger_ManualLocal, bRebootOS ? RebootWay_OS : RebootWay_Framework );
+
+	return Error_Unexpect;
+}
+
+ErrorCodeEnum GUITask::SubscribeLog()
+{
+	return m_pEntity->GetFunction()->SubscribeLog(m_logSubID,  this, Log_Ignore, Severity_None, Error_IgnoreAll, -2, NULL, false);
+}
+
+ErrorCodeEnum GUITask::UnSubscribeLog()
+{
+	if ((__int64)m_logSubID != 0)
+	{
+		m_pEntity->GetFunction()->UnsubscribeLog(m_logSubID);
+		m_logSubID = 0;
+	}
+
+	return Error_Succeed;
+}
+
+ErrorCodeEnum GUITask::SetDebugLevel(const char *pszEntity, int nLevel)
+{
+	return m_pEntity->GetFunction()->GetPrivilegeFunction()->SetSysDebugLevel(pszEntity, (DebugLevelEnum)nLevel, true);
+}
+
+ErrorCodeEnum GUITask::GetShellDebugLevel(int &nLevel)
+{
+	CSystemRunInfo info ={};
+	auto rc = m_pEntity->GetFunction()->GetSystemRunInfo(info);
+	if (rc == Error_Succeed)
+		nLevel = info.eDebugLevel;
+
+	return rc;
+}
+
+
+ErrorCodeEnum GUITask::BeginAccessAuth()
+{
+	return Error_Succeed;
+}
+
+ErrorCodeEnum GUITask::BeginInitialize()
+{
+	return Error_Succeed;
+}
+
+
+ErrorCodeEnum GUITask::DeleteKeySet()
+{
+	return Error_Succeed;
+}
+
+ErrorCodeEnum GUITask::GetFrameworkInfo(CSimpleStringA &strInfo)
+{
+	CSystemStaticInfo info;
+	memset(&info, 0, sizeof(info));
+	auto rc = m_pEntity->GetFunction()->GetSystemStaticInfo(info);
+	if (rc == Error_Succeed)
+		strInfo = CSimpleStringA::Format("[%s] [%s]", (const char*) info.strTerminalID, (const char*)info.InstallVersion.ToString());
+
+	return rc;
+}
+
+void GUITask::Kickoff(CEntityBase* pEntity)
+{
+	m_pEntity = pEntity;
+	
+	RegistEntityStateEvent();
+}
+
+ErrorCodeEnum GUITask::AsyncStartEntity(const char *entity_name, const char *cmdline, void *pData)
+{
+	CSmartPointer<IEntityFunction> pFunc = m_pEntity->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 GUITask::AsyncStopEntity(const char *entity_name, void *pData)
+{
+	CSmartPointer<IEntityFunction> pFunc = m_pEntity->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 GUITask::AsyncPauseEntity(const char *entity_name, void *pData)
+{
+	CSmartPointer<IEntityFunction> pFunc = m_pEntity->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 GUITask::AsyncContinueEntity(const char *entity_name, void *pData)
+{
+	CSmartPointer<IEntityFunction> pFunc = m_pEntity->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 GUITask::AsyncTerminateEntity(const char *entity_name, void *pData)
+{
+	CSmartPointer<IEntityFunction> pFunc = m_pEntity->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 GUITask::GetAllEntity(CAutoArray<EntityEntry> &Entities)
+{
+	CSmartPointer<IEntityFunction> spFunc = m_pEntity->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;
+}
+
+ErrorCodeEnum GUITask::GetEntity(const char *entity_name, EntityEntry &e)
+{
+	CSmartPointer<IEntityFunction> spFunc = m_pEntity->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 GUITask::GetCustomizeStartMenuList(CAutoArray<StartMenuEntry> &StartItems)
+{
+	CSmartPointer<IEntityFunction> spFunc = m_pEntity->GetFunction();
+	CSmartPointer<IConfigInfo> spConfig;
+	LOG_ASSERT(spFunc != NULL);
+	int cnt = 0;
+	ErrorCodeEnum Error = spFunc->OpenConfig(Config_Software, spConfig);
+	if (Error != Error_Succeed)
+		return Error;
+	Error = spConfig->ReadConfigValueInt("StartMenu", "Number", cnt);
+	if (Error != Error_Succeed)
+		return Error;
+	StartItems.Init(cnt);
+	for (int i = 0; i < cnt; ++i) {
+		char tmp[128];
+		CSimpleStringA strValue;
+		_itoa(i+1, tmp, 10);
+		Error = spConfig->ReadConfigValue("StartMenu", tmp, strValue);
+		const char *p = strValue;
+		if (Error != Error_Succeed || p == NULL || strValue.GetLength() == 0)
+			break;
+		int kk = 0;
+		while (*p && *p != ' ') {
+			tmp[kk++] = *p;
+			p++;
+		}
+		tmp[kk] = 0;
+		StartItems[i].strEntity = tmp;
+		while (*p && *p == ' ')
+			p++;
+		if (*p) {
+			StartItems[i].strCmdLine = p;
+		} else {
+			StartItems[i].strCmdLine = "";
+		}
+	}
+	return Error;
+}
+
+void GUITask::OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp)
+{
+
+}
+
+
+ErrorCodeEnum GUITask::OutputMsg(const char *pMsg)
+{
+	return Error_Succeed;
+}
+
+
+void GUITask::OnEntityStateHook(const char *pszEntityName,const char *pszTriggerEntity,EntityStateEnum eState,EntityStateEnum eLastState)
+{
+	CEntityRunInfo Info;
+	CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
+	pFunc->GetEntityRunInfo(pszEntityName, Info);
+
+	entityStateChange cur = { pszEntityName , eState , Info.dwProcessID };
+	m_server->publish("EntityStateChange", cur);
+}
+
+void GUITask::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)
+{
+	
+	// 忽略GPIO事件
+	if (dwUserCode == 0x2090000A || dwUserCode == 0x20900009)
+		return;
+
+	if (pszMessage!=NULL && strlen(pszMessage)>2)
+	{
+		CSimpleStringA str = pszMessage;
+		if (str[str.GetLength()-2] == '\r' && str[str.GetLength()-1]=='\n')
+			str[str.GetLength()-2] = 0;
+						
+		if (eLogType == Log_Error)
+			m_lastErrorMsg = str = CSimpleStringA::Format("[%s] Error:{%s}(sc:0x%X, uc:0x%X)\r\n", pszEntityName, (const char*)str, dwSysError, dwUserCode);
+		else if(eLogType == Log_Warning)
+			str = CSimpleStringA::Format("[%s] Warn:{%s}(sc:0x%X, uc:0x%X)\r\n", pszEntityName, (const char*)str, dwSysError, dwUserCode);
+		else if(eLogType == Log_Event)
+			str = CSimpleStringA::Format("[%s] Event:{%s}(uc:0x%X)\r\n", pszEntityName, (const char*)str, dwUserCode);
+		else if (eLogType == Log_Debug)
+			str = CSimpleStringA::Format("[%s] Debug:{%s}\r\n", pszEntityName, (const char*)str);
+
+		publishMsg({ "togui" ,  4 /*Debug*/, 1 /*Low*/, 0, 0 , str.GetData() });
+	}
+}
+
+CEntityBase* GUITask::GetEntity()
+{
+	return m_pEntity;
+}
+
+ErrorCodeEnum GUITask::ShowMaintainView(bool bShow, bool bHighLevel)
+{
+	return Error_Succeed;
+}
+
+ErrorCodeEnum GUITask::SetWindowPosition(bool bTop)
+{
+	CSystemStaticInfo info;
+	memset(&info, 0, sizeof(info));
+	auto rc = m_pEntity->GetFunction()->GetSystemStaticInfo(info);
+	if (stricmp(info.strMachineType, "RVC.IL") == 0)
+		return Error_Succeed;			
+
+	if (m_hWndMainFrame) 
+	{
+		if (bTop)
+		{
+			ShowWindow(m_hWndMainFrame, SW_NORMAL);
+			SetWindowPos(m_hWndMainFrame, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
+
+			// 启动软键盘
+			// WinExec("osk.exe", SW_NORMAL);
+			//ShellExecuteA(NULL, "open", "osk.exe", NULL, NULL, SW_SHOW);
+		}
+		else
+		{
+			SetWindowPos(m_hWndMainFrame, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
+			ShowWindow(m_hWndMainFrame, SW_MINIMIZE);
+
+			// 关闭软键盘
+			//CloseSoftKeyboard();
+		}
+
+		return Error_Succeed;
+	}
+	else
+		return Error_NotExist;
+}
+
+ErrorCodeEnum GUITask::ShowBeginInit(bool bShow)
+{
+	return Error_Succeed;
+}
+
+void GUITask::CloseSoftKeyboard()
+{
+	HANDLE hProcessHandle;
+	ULONG nProcessID;
+	HWND kbWindow;
+	kbWindow = ::FindWindow(NULL, _T("屏幕键盘"));
+	if (NULL != kbWindow)
+	{
+		::GetWindowThreadProcessId(kbWindow, &nProcessID);
+		hProcessHandle = ::OpenProcess(PROCESS_TERMINATE, FALSE, nProcessID);
+		::TerminateProcess(hProcessHandle, 4);
+	}
+}
+ErrorCodeEnum GUITask::ShowBlueScreen()
+{
+	auto pEntityFunc = m_pEntity->GetFunction();
+	auto pPrevFunc = pEntityFunc->GetPrivilegeFunction();
+	const char *pMsg = "System Failure!System Failure!System Failure!System Failure!System Failure!System Failure!System Failure!System Failure!\r\n系统启动失败,请联系总行开发人员解决!";
+
+	pPrevFunc->DisplayBlueScreen(pMsg);
+	return Error_Succeed;
+}
+
+ErrorCodeEnum GUITask::ShowFatalError()
+{
+	auto pEntityFunc = m_pEntity->GetFunction();
+	const char *pMsg = "开放系统管理员初级培训及认证报名通知.开放系统管理员初级培训及认证报名通知.开放系统管理员初级培训及认证报名通知.开放系统管理员初级培训及认证报名通知.开放系统管理员初级培训及认证报名通知.";
+	pEntityFunc->ShowFatalError(pMsg);
+	return Error_Succeed;
+}
+
+ErrorCodeEnum GUITask::HideBlueScreen()
+{
+	auto pEntityFunc = m_pEntity->GetFunction();
+	auto pPrevFunc = pEntityFunc->GetPrivilegeFunction();
+	return pPrevFunc->UndisplayBlueScreen();
+}
+
+ErrorCodeEnum GUITask::ShowOutputConsole()
+{
+	auto pFunc = m_pEntity->GetFunction()->GetPrivilegeFunction();
+	return pFunc->ShowOuputConsole();
+}
+
+ErrorCodeEnum GUITask::CloseOutputConsole()
+{
+	auto pFunc = m_pEntity->GetFunction()->GetPrivilegeFunction();
+	return pFunc->CloseOuputConsole();
+}
+

+ 214 - 214
module/mod_rpc/guitask.h → Module/mod_rpc/guitask.h

@@ -1,215 +1,215 @@
-#ifndef __GUI_TASK_H
-#define __GUI_TASK_H
-
-#pragma once
-
-#include "SpBase.h"
-#include "SpFSM.h"
-
-#include "rpc_server.h"
-using namespace rest_rpc;
-using namespace rpc_service;
-#include <fstream>
-#include <memory>
-#include <vector>
-
-#include "qps.h"
-#include "format.hpp"
-
-struct EntityEntryPlus
-{
-	std::string Name;
-	std::string ModuleName;
-	int Type;
-	int State;
-	int Id;
-	int Pid;
-	int DevelopID;
-	int DebugLevel;
-
-	MSGPACK_DEFINE(Name, ModuleName, Type, State, Id, Pid, DevelopID, DebugLevel);
-};
-
-struct EntityEntryPlusVec {
-	std::vector<EntityEntryPlus> entityArr;
-
-	MSGPACK_DEFINE(entityArr);
-
-	virtual bool Read(msgpack::object& obj)
-	{
-		obj.convert(*this);
-		return true;
-	}
-
-	virtual bool Write(msgpack::packer<msgpack::sbuffer>& pack)
-	{
-		pack.pack(*this);
-		return true;
-	}
-};
-
-struct outputMsg {
-	std::string entityName;
-	int logType;
-	int logLevel;
-	LONG sysError;
-	LONG userCode;
-	std::string msg;
-
-	static const char* GetLogType(int state)
-	{
-		static const char* _names[] = {
-			"Ignore","Event","Warning","Error","Debug"
-		};
-		return _names[state % ARRAYSIZE(_names)];
-	}
-
-	MSGPACK_DEFINE(entityName, logType, logLevel, sysError, userCode, msg);
-};
-
-
-struct entityStateChange
-{
-	std::string entityName;
-	int state;
-	int pid;
-	MSGPACK_DEFINE(entityName, state, pid);
-};
-
-
-struct EntityEntry
-{
-	CSimpleStringA Name;
-	CSimpleStringA ModuleName;
-	int Type;
-	int State;
-	int Id;
-	int Pid;
-	int DevelopID;
-	int DebugLevel;
-
-	static const char *GetTypeName(int type)
-	{
-		static const char *_names[] = {
-			"auto",
-			"manual"
-		};
-		return _names[type % ARRAYSIZE(_names)];
-	}
-
-	static const char *GetStateName(int state)
-	{
-		static const char *_names[] = {
-			"NoStart",
-			"Starting",
-			"Idle",
-			"Busy",
-			"Pause",
-			"UnLoading",
-			"Lost",
-			"Close",
-			"Killed",
-		};
-		return _names[state % ARRAYSIZE(_names)];
-	}
-
-	static const char *GetErrorName(ErrorCodeEnum Error)
-	{
-		return "Unknown Error";
-	}
-};
-
-struct StartMenuEntry
-{
-	CSimpleStringA strEntity;
-	CSimpleStringA strCmdLine;
-};
-
-
-class GUITask : public ICallbackListener, public IEntityStateListener, public ILogListener
-{
-public:
-	GUITask();
-	virtual ~GUITask();
-
-	void Kickoff(CEntityBase* pEntity);
-	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 GetAllEntity(CAutoArray<EntityEntry> &Entities);
-	ErrorCodeEnum GetEntity(const char *entity_name, EntityEntry &e);
-	ErrorCodeEnum GetCustomizeStartMenuList(CAutoArray<StartMenuEntry> &StartItems);
-	ErrorCodeEnum SubscribeLog();
-	ErrorCodeEnum UnSubscribeLog();
-	inline bool HasSubscibeLog(){return (__int64)m_logSubID != 0;}
-	ErrorCodeEnum SetDebugLevel(const char *pszEntity, int nLevel);
-	ErrorCodeEnum GetShellDebugLevel(int &nLevel);
-	ErrorCodeEnum GetFrameworkInfo(CSimpleStringA &strInfo);
-	ErrorCodeEnum ReqFrameworkQuit(bool bRebootOS);
-	ErrorCodeEnum BeginInitialize();	
-	ErrorCodeEnum DeleteKeySet();
-	ErrorCodeEnum BeginAccessAuth();
-	CEntityBase* GetEntity();
-	ErrorCodeEnum ShowMaintainView(bool bShow, bool bHighLevel);
-	ErrorCodeEnum SetWindowPosition(bool bTop);	
-	ErrorCodeEnum ShowBeginInit(bool bShow);
-	void CloseSoftKeyboard();
-
-	ErrorCodeEnum ShowBlueScreen();
-	ErrorCodeEnum ShowFatalError();
-	ErrorCodeEnum HideBlueScreen();
-
-	ErrorCodeEnum ShowOutputConsole();
-	ErrorCodeEnum CloseOutputConsole();
-
-	// IEntityStateListener
-	virtual void OnEntityStateHook(const char *pszEntityName,const char *pszTriggerEntity,EntityStateEnum eState,EntityStateEnum eLastState);
-	virtual void OnCeateConnection(const char *pszCallerEntity,const char *pszServiceEntity) {}
-	virtual void OnCloseConnection(const char *pszCallerEntity,const char *pszServiceEntity) {}
-	virtual void OnUserStateHook(const char *pszEntityName,DWORD dwState,DWORD dwLastState)	{
-		//Dbg("OnUserStateHook: %s, %d -> %d", pszEntityName, dwLastState, dwState);	
-	}
-
-	// ICallbackListener
-	virtual void OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp);
-
-	// ILogListener
-	virtual void 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);
-
-	CSimpleString m_lastErrorMsg;
-
-	//rpc call function
-	bool openrpcServer(int port);
-	void publishMsg(outputMsg out);
-
-private:
-	std::unique_ptr<rpc_server> m_server;
-
-private:
-	ErrorCodeEnum OutputMsg(const char *pMsg);
-	ErrorCodeEnum RegistEntityStateEvent();
-	ErrorCodeEnum UnregistEntityStateEvent();	
-
-
-private:
-	HANDLE m_hEventStartReady;
-	HANDLE m_hEventStopReady;
-	HANDLE m_hThread;
-	HWND m_hWndMainFrame;
-	CEntityBase *m_pEntity;
-
-	CUUID m_logSubID;
-	bool m_bHighLevel;
-};
-
-
-extern GUITask g_task;
-
-template<class TFirst, class... TOther>
-void outputMsgToGUI(const char* format, TFirst&& first, TOther&&... other);
-
+#ifndef __GUI_TASK_H
+#define __GUI_TASK_H
+
+#pragma once
+
+#include "SpBase.h"
+#include "SpFSM.h"
+
+#include "rpc_server.h"
+using namespace rest_rpc;
+using namespace rpc_service;
+#include <fstream>
+#include <memory>
+#include <vector>
+
+#include "qps.h"
+#include "format.hpp"
+
+struct EntityEntryPlus
+{
+	std::string Name;
+	std::string ModuleName;
+	int Type;
+	int State;
+	int Id;
+	int Pid;
+	int DevelopID;
+	int DebugLevel;
+
+	MSGPACK_DEFINE(Name, ModuleName, Type, State, Id, Pid, DevelopID, DebugLevel);
+};
+
+struct EntityEntryPlusVec {
+	std::vector<EntityEntryPlus> entityArr;
+
+	MSGPACK_DEFINE(entityArr);
+
+	virtual bool Read(msgpack::object& obj)
+	{
+		obj.convert(*this);
+		return true;
+	}
+
+	virtual bool Write(msgpack::packer<msgpack::sbuffer>& pack)
+	{
+		pack.pack(*this);
+		return true;
+	}
+};
+
+struct outputMsg {
+	std::string entityName;
+	int logType;
+	int logLevel;
+	LONG sysError;
+	LONG userCode;
+	std::string msg;
+
+	static const char* GetLogType(int state)
+	{
+		static const char* _names[] = {
+			"Ignore","Event","Warning","Error","Debug"
+		};
+		return _names[state % ARRAYSIZE(_names)];
+	}
+
+	MSGPACK_DEFINE(entityName, logType, logLevel, sysError, userCode, msg);
+};
+
+
+struct entityStateChange
+{
+	std::string entityName;
+	int state;
+	int pid;
+	MSGPACK_DEFINE(entityName, state, pid);
+};
+
+
+struct EntityEntry
+{
+	CSimpleStringA Name;
+	CSimpleStringA ModuleName;
+	int Type;
+	int State;
+	int Id;
+	int Pid;
+	int DevelopID;
+	int DebugLevel;
+
+	static const char *GetTypeName(int type)
+	{
+		static const char *_names[] = {
+			"auto",
+			"manual"
+		};
+		return _names[type % ARRAYSIZE(_names)];
+	}
+
+	static const char *GetStateName(int state)
+	{
+		static const char *_names[] = {
+			"NoStart",
+			"Starting",
+			"Idle",
+			"Busy",
+			"Pause",
+			"UnLoading",
+			"Lost",
+			"Close",
+			"Killed",
+		};
+		return _names[state % ARRAYSIZE(_names)];
+	}
+
+	static const char *GetErrorName(ErrorCodeEnum Error)
+	{
+		return "Unknown Error";
+	}
+};
+
+struct StartMenuEntry
+{
+	CSimpleStringA strEntity;
+	CSimpleStringA strCmdLine;
+};
+
+
+class GUITask : public ICallbackListener, public IEntityStateListener, public ILogListener
+{
+public:
+	GUITask();
+	virtual ~GUITask();
+
+	void Kickoff(CEntityBase* pEntity);
+	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 GetAllEntity(CAutoArray<EntityEntry> &Entities);
+	ErrorCodeEnum GetEntity(const char *entity_name, EntityEntry &e);
+	ErrorCodeEnum GetCustomizeStartMenuList(CAutoArray<StartMenuEntry> &StartItems);
+	ErrorCodeEnum SubscribeLog();
+	ErrorCodeEnum UnSubscribeLog();
+	inline bool HasSubscibeLog(){return (__int64)m_logSubID != 0;}
+	ErrorCodeEnum SetDebugLevel(const char *pszEntity, int nLevel);
+	ErrorCodeEnum GetShellDebugLevel(int &nLevel);
+	ErrorCodeEnum GetFrameworkInfo(CSimpleStringA &strInfo);
+	ErrorCodeEnum ReqFrameworkQuit(bool bRebootOS);
+	ErrorCodeEnum BeginInitialize();	
+	ErrorCodeEnum DeleteKeySet();
+	ErrorCodeEnum BeginAccessAuth();
+	CEntityBase* GetEntity();
+	ErrorCodeEnum ShowMaintainView(bool bShow, bool bHighLevel);
+	ErrorCodeEnum SetWindowPosition(bool bTop);	
+	ErrorCodeEnum ShowBeginInit(bool bShow);
+	void CloseSoftKeyboard();
+
+	ErrorCodeEnum ShowBlueScreen();
+	ErrorCodeEnum ShowFatalError();
+	ErrorCodeEnum HideBlueScreen();
+
+	ErrorCodeEnum ShowOutputConsole();
+	ErrorCodeEnum CloseOutputConsole();
+
+	// IEntityStateListener
+	virtual void OnEntityStateHook(const char *pszEntityName,const char *pszTriggerEntity,EntityStateEnum eState,EntityStateEnum eLastState);
+	virtual void OnCeateConnection(const char *pszCallerEntity,const char *pszServiceEntity) {}
+	virtual void OnCloseConnection(const char *pszCallerEntity,const char *pszServiceEntity) {}
+	virtual void OnUserStateHook(const char *pszEntityName,DWORD dwState,DWORD dwLastState)	{
+		//Dbg("OnUserStateHook: %s, %d -> %d", pszEntityName, dwLastState, dwState);	
+	}
+
+	// ICallbackListener
+	virtual void OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp);
+
+	// ILogListener
+	virtual void 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);
+
+	CSimpleString m_lastErrorMsg;
+
+	//rpc call function
+	bool openrpcServer(int port);
+	void publishMsg(outputMsg out);
+
+private:
+	std::unique_ptr<rpc_server> m_server;
+
+private:
+	ErrorCodeEnum OutputMsg(const char *pMsg);
+	ErrorCodeEnum RegistEntityStateEvent();
+	ErrorCodeEnum UnregistEntityStateEvent();	
+
+
+private:
+	HANDLE m_hEventStartReady;
+	HANDLE m_hEventStopReady;
+	HANDLE m_hThread;
+	HWND m_hWndMainFrame;
+	CEntityBase *m_pEntity;
+
+	CUUID m_logSubID;
+	bool m_bHighLevel;
+};
+
+
+extern GUITask g_task;
+
+template<class TFirst, class... TOther>
+void outputMsgToGUI(const char* format, TFirst&& first, TOther&&... other);
+
 #endif // __GUI_TASK_H

+ 0 - 0
module/mod_rpc/mod_rpc.cpp → Module/mod_rpc/mod_rpc.cpp


+ 0 - 0
module/mod_rpc/qps.h → Module/mod_rpc/qps.h


+ 0 - 0
module/mod_rpc/rpcServer/client_util.hpp → Module/mod_rpc/rpcServer/client_util.hpp


+ 0 - 0
module/mod_rpc/rpcServer/codec.h → Module/mod_rpc/rpcServer/codec.h


+ 0 - 0
module/mod_rpc/rpcServer/connection.h → Module/mod_rpc/rpcServer/connection.h


+ 0 - 0
module/mod_rpc/rpcServer/const_vars.h → Module/mod_rpc/rpcServer/const_vars.h


+ 0 - 0
module/mod_rpc/rpcServer/cplusplus_14.h → Module/mod_rpc/rpcServer/cplusplus_14.h


+ 0 - 0
module/mod_rpc/rpcServer/io_service_pool.h → Module/mod_rpc/rpcServer/io_service_pool.h


+ 0 - 0
module/mod_rpc/rpcServer/meta_util.hpp → Module/mod_rpc/rpcServer/meta_util.hpp


+ 0 - 0
module/mod_rpc/rpcServer/router.h → Module/mod_rpc/rpcServer/router.h


+ 0 - 0
module/mod_rpc/rpcServer/rpc_client.hpp → Module/mod_rpc/rpcServer/rpc_client.hpp


+ 0 - 0
module/mod_rpc/rpcServer/rpc_server.h → Module/mod_rpc/rpcServer/rpc_server.h


+ 0 - 0
module/mod_rpc/rpcServer/string_view.hpp → Module/mod_rpc/rpcServer/string_view.hpp


+ 0 - 0
module/mod_rpc/rpcServer/use_asio.hpp → Module/mod_rpc/rpcServer/use_asio.hpp


+ 0 - 0
module/module_list.md → Module/module_list.md