123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819 |
- #include "stdafx2.h"
- #include "SpBase.h"
- #include "guitask.h"
- #include "mainfrm.h"
- #include "SpIni.h"
- #include "path.h"
- #include "AccessAuthorization_client_g.h"
- using namespace AccessAuthorization;
- #include "mod_CenterSetting/Event.h"
- int level = 2;
- GUITask::GUITask() : m_pEntity(NULL), m_hWndMainFrame(NULL), m_hThread(NULL), m_hThread2(NULL), m_hWndStartPage(NULL),
- m_idleNum(0), m_totalNum(0)
- {
- m_hEventStartReady = ::CreateEventA(NULL, TRUE, FALSE, NULL);
- m_hEventStopReady = ::CreateEventA(NULL, TRUE, FALSE, NULL);
- m_hWndStartPage =NULL;
- }
- GUITask::~GUITask()
- {
- CloseHandle(m_hEventStopReady);
- CloseHandle(m_hEventStartReady);
- }
- ErrorCodeEnum GUITask::Kickoff(CEntityBase *pEntity)
- {
- LOG_FUNCTION();
-
- #if defined(RVC_OS_WIN)
- if (m_hThread) {
- return Error_Duplication;
- }
-
- m_pEntity = pEntity;
- m_pEntity->GetFunction()->RegistSysVarEvent("UIState", this);
- CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- ErrorCodeEnum errCode = pFuncPrivilege->RegistEntityStateEvent(NULL,this);
- if (errCode != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("RegistEntityState failed(%d).",errCode);
- return Error_Unexpect;
- }
- m_totalNum = GetWillWorkEntityCountFromHealthmanager();
- if (m_totalNum == 0) {
- CAutoArray<EntityEntry> Entities;
- ErrorCodeEnum err = GetAllEntity(Entities);
- m_totalNum = Entities.GetCount();
- }
- m_hThread = (HANDLE)_beginthreadex(0, 0, &__Process, this, 0, 0);
- if (!m_hThread) {
- return Error_Resource;
- }
- WaitForSingleObject(m_hEventStartReady, INFINITE);
- //SubscribeLog();
- return RegistEntityStateEvent();
- #else
- return Error_NotSupport;
- #endif //RVC_OS_WIN
- }
- ErrorCodeEnum GUITask::Close()
- {
- #if defined(RVC_OS_WIN)
- if (!m_hThread) {
- return Error_NotInit;
- }
- UnSubscribeLog();
- UnregistEntityStateEvent();
- if (m_hWndMainFrame) {
- PostMessageA(m_hWndMainFrame, WM_CLOSE, -1, -1);
- WaitForSingleObject(m_hEventStopReady, INFINITE);
- }
- WaitForSingleObject(m_hThread, INFINITE);
- CloseHandle(m_hThread);
- m_hThread = 0;
- #endif //RVC_OS_WIN
- return Error_Succeed;
- }
- #if defined(RVC_OS_WIN)
- CAppModule _Module;
- #endif //RVC_OS_WIN
- void GUITask::Process()
- {
- #if defined(RVC_OS_WIN)
- ResetEvent(m_hEventStartReady);
- m_pEntity->GetFunction()->InitLogCurrentThread();
- HRESULT hRes = ::CoInitialize(NULL);
- // If you are running on NT 4.0 or higher you can use the following call instead to
- // make the EXE free threaded. This means that calls come in on a random RPC thread.
- // HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
- ATLASSERT(SUCCEEDED(hRes));
- // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
- ::DefWindowProc(NULL, 0, 0, 0L);
- AtlInitCommonControls(ICC_COOL_CLASSES | ICC_BAR_CLASSES); // add flags to support other controls
- hRes = _Module.Init(NULL, ModuleBase::GetModuleBase()->GetInstance());
- ATLASSERT(SUCCEEDED(hRes));
- ATL::AtlAxWinInit();
- CMessageLoop theLoop;
- _Module.AddMessageLoop(&theLoop);
- CMainFrame wndMain(this);
- if(wndMain.CreateEx() == NULL)
- {
- ATLTRACE(_T("Main window creation failed!\n"));
- return;
- }
- m_hWndMainFrame = wndMain.m_hWnd;
- CSmartPointer<IConfigInfo> pConfig;
- auto rc = m_pEntity->GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
- CSimpleStringA csimpleStrMachineTypeCfg(true);
- StartPageDlg dlg(this);
- if (IS_SUCCEED(rc)) {
- rc = pConfig->ReadConfigValue("NonExclusive", "NewStartPage", csimpleStrMachineTypeCfg);
- CSystemStaticInfo staticInfo;
- m_pEntity->GetFunction()->GetSystemStaticInfo(staticInfo);
- if (csimpleStrMachineTypeCfg.IndexOf(staticInfo.strMachineType) >= 0) {
- TerminalBaseInfo info;
- info.strMachineType = staticInfo.strMachineType;
- info.strTerminalNo = staticInfo.strTerminalID;
- info.strSoftwareVersion = staticInfo.InstallVersion.ToString();
- dlg.SetTerminalBasicInfo(info);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Enter newpage...");
- if (dlg.Create(NULL) == NULL) {
- ATLTRACE(_T("Main window creation failed!\n"));
- return;
- }
- m_hWndStartPage = dlg.m_hWnd;
- }
- }
- SetEvent(m_hEventStartReady);
- wndMain.ShowWindow(SW_MINIMIZE);
- if(m_hWndStartPage)
- dlg.ShowWindow(SW_SHOW);
- else
- ShowOutputConsole();
- int nRet = theLoop.Run();
- _Module.RemoveMessageLoop();
- _Module.Term();
- ::CoUninitialize();
- SetEvent(m_hEventStopReady);
- m_hWndMainFrame = NULL;
- #endif //RVC_OS_WIN
- }
- 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)
- {
- CSmartPointer<IConfigInfo> pConfig;
- auto rc = m_pEntity->GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
- int iNoRestart;
- CSimpleStringA csimpleStrMachineTypeCfg;
- rc = pConfig->ReadConfigValue("NonExclusive", "NonGuardian", csimpleStrMachineTypeCfg);
- CSystemStaticInfo staticInfo;
- m_pEntity->GetFunction()->GetSystemStaticInfo(staticInfo);
- if(csimpleStrMachineTypeCfg.IndexOf(staticInfo.strMachineType)>=0)
- return pFuncPrivilege->Reboot(RebootTrigger_ManualLocal, bRebootOS ? RebootWay_OS : RebootWay_Power );
- return pFuncPrivilege->Reboot(RebootTrigger_ManualLocal, bRebootOS ? RebootWay_OS : RebootWay_Framework );
- }
- return Error_Unexpect;
- }
- ErrorCodeEnum GUITask::SubscribeLog()
- {
- #if defined(_MSC_VER)
- return m_pEntity->GetFunction()->SubscribeLog(m_logSubID, this, Log_Ignore, Severity_None, Error_IgnoreAll, -1, NULL, false);
- #else
- return Error_NotSupport;
- #endif //_MSC_VER
- }
- ErrorCodeEnum GUITask::UnSubscribeLog()
- {
- if (HasSubscibeLog())
- {
- 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()
- {
- AccessAuthService_ClientBase *pClient = new AccessAuthService_ClientBase(m_pEntity);
- auto rc = pClient->Connect();
- if (rc == Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("connect to entity [AccessAuthorization] succeed, start access auth now");
- rc = (*pClient)(EntityResource::getLink().upgradeLink())->Regist();
- pClient->GetFunction()->CloseSession();
- }
- else
- {
- LogWarn(Severity_Low, rc, 0, "connect to entity [AccessAuthorization] fail");
- pClient->SafeDelete();
- }
-
- return rc;
- }
- ErrorCodeEnum GUITask::BeginInitialize()
- {
- return Error_NotImpl;
- }
- #include "mod_GuiConsole.h"
- ErrorCodeEnum GUITask::DeleteKeySet()
- {
- #if defined(_MSC_VER)
- HCRYPTPROV hProv(0);
- if (!CryptAcquireContext(&hProv, "RVC", MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_MACHINE_KEYSET | CRYPT_DELETEKEYSET)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("delete keyset fail: %d", GetLastError());
- return Error_Unexpect;
- } else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("delete keyset succ");
- return Error_Succeed;
- }
- #else
- return Error_NotImpl;
- #endif //_MSC_VER
- }
- 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;
- }
- 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;
- }
- }
- UINT CalcKeyCountUnderSection(const char* pszFile, const char* pszSection)
- {
- UINT result(0);
- #if defined(_MSC_VER)
- DWORD dwInitialCapacity = 16;
- DWORD dwSize;
- char* p = NULL;
- const int tries = 70;
- ErrorCodeEnum Error = Error_Succeed;
- int i;
- for (i = 0; i < tries; ++i) {
- p = (char*)realloc(p, dwInitialCapacity);
- dwSize = ::GetPrivateProfileStringA(pszSection, NULL, NULL, p, dwInitialCapacity, pszFile);
- if (dwSize == dwInitialCapacity - 2) { // buffer is too small
- dwInitialCapacity = dwInitialCapacity * 2;
- } else {
- break;
- }
- }
- if (i < tries) {
- int cnt = 0;
- char* t = p;
- size_t n;
- while ((n = strlen(t)) > 0) {
- cnt++;
- t += n + 1;
- }
- result = cnt;
- }
- free(p);
- #endif //_MSC_VER
- return result;
- }
- UINT GUITask::GetWillWorkEntityCountFromHealthmanager()
- {
- UINT count(0);
- CSystemStaticInfo sysInfo;
- CSimpleStringA cfgPath = "", strCoreBoot("CoreBoot"), strSafeLoad("SafeLoad"), strOp("Operating");
- m_pEntity->GetFunction()->GetPath("cfg", cfgPath);
- m_pEntity->GetFunction()->GetSystemStaticInfo(sysInfo);
- strCoreBoot = strCoreBoot + "." + sysInfo.strMachineType;
- strSafeLoad = strSafeLoad + "." + sysInfo.strMachineType;
- strOp = strOp + "." + sysInfo.strMachineType;
- cfgPath = cfgPath + "\\HealthManager.ini";
- count += CalcKeyCountUnderSection(cfgPath, strCoreBoot);
- count += CalcKeyCountUnderSection(cfgPath, strSafeLoad);
- count += CalcKeyCountUnderSection(cfgPath, strOp);
- return count;
- }
- 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)
- {
- int cnt = 0;
- StartItems.Clear();
- return Error_Deprecated;
- }
- void GUITask::OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp)
- {
- #if defined(_MSC_VER)
- 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);
- }
- #endif //_MSC_VER
- }
- ErrorCodeEnum GUITask::OutputMsg(const char *pMsg)
- {
- #if defined(_MSC_VER)
- if (m_hWndMainFrame) {
- PostMessage(m_hWndMainFrame, WM_SHOW_MSG, 0, (LPARAM)strdup(pMsg));
- return Error_Succeed;
- } else
- return Error_NotExist;
- #else
- return Error_NotSupport;
- #endif //_MSC_VER
- }
- void GUITask::OnEntityStateHook(const char *pszEntityName,const char *pszTriggerEntity,EntityStateEnum eState,EntityStateEnum eLastState)
- {
- #if defined(_MSC_VER)
- if (m_hWndMainFrame) {
- callback_entry* entry = new callback_entry();
- entry->EntityName = pszEntityName;
- entry->ErrorResult = Error_Succeed;
- entry->op = OP_FIRE_ENTITY_STATE;
- entry->state = eState;
- DWORD dwProcessID = 0;
- //if (entry->state != EntityState_Close) // 关闭状态进程号清0置后
- {
- CEntityRunInfo Info;
- CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
- pFunc->GetEntityRunInfo(entry->EntityName, Info);
- dwProcessID = Info.dwProcessID;
- }
- PostMessage(m_hWndMainFrame, WM_GUICONSOLE, dwProcessID, (LPARAM)entry);
- }
-
-
- SYSTEMTIME st;
- GetLocalTime(&st);
- CSimpleStringA msg;
- if(eState == EntityState_Starting)
- msg = CSimpleString::Format("[%04d-%02d-%02d %02d:%02d:%02d] 正在启动实体%s...", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, pszEntityName);
- if(eState == EntityState_Idle)
- {
- msg = CSimpleString::Format("[%04d-%02d-%02d %02d:%02d:%02d] %s实体启动成功", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, pszEntityName);
-
- m_idleNum++;
- }
- if(eLastState == EntityState_Idle && eState != EntityState_Idle )
- {
- msg = CSimpleString::Format("[%04d-%02d-%02d %02d:%02d:%02d] %s实体异常,重新启动...", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, pszEntityName);
- m_idleNum--;
- }
- PostMessage(m_hWndStartPage, WM_NUMCHANGE, 0, 0);
- PostMessage(m_hWndStartPage, WM_SHOW_MSG, (WPARAM)strdup(msg), (LPARAM)RGB(171, 171, 171));
-
- #endif //_MSC_VER
- }
- 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, const linkContext& pLinkInfo)
- {
- // 忽略GPIO事件
- if (dwUserCode == 0x2090000A || dwUserCode == 0x20900009)
- return;
- else if (dwUserCode == EVENT_MOD_CENTERSETTING_UPDATE_CENTER)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("检测到集中配置更新了");
- auto generateCenterSettingPath = []() ->std::string {
- char pathbuf[1024] = "";
- int pathlen = ::GetModuleFileNameA(NULL, pathbuf, 1024);//获得GuiConsole路径
- // 替换掉单杠
- int times = 0;
- while (pathlen > 0)
- {
- if (pathbuf[pathlen--] == SPLIT_SLASH)
- times++;
- if (2 == times)
- break;
- }
- pathbuf[++pathlen] = '\0';
- std::string dstPath = pathbuf;
- #if defined(_MSC_VER)
- dstPath.append("\\cfg\\CenterSetting.ini");
- #else
- dstPath.append("/cfg/CenterSetting.LAN.ini");
- #endif //_MSC_VER
- return dstPath;
- };
- //实时更新实体打印的日志等级,这个功能在信创下需要调整,实现方式不一样 gifur@20230816
- auto centersettingPath = generateCenterSettingPath();
- load_debugLevelInCentersetting(centersettingPath.c_str());
- }
-
- 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)
- {
- str = CSimpleStringA::Format("[%s] Error:{%s}(sc:0x%X, uc:0x%X)\r\n", pszEntityName, (const char*)str, dwSysError, dwUserCode);
- #if defined(_MSC_VER)
- PostMessage(m_hWndStartPage, WM_SHOW_MSG, (WPARAM)strdup(str), (LPARAM)RGB(255, 132, 32));
- #endif //_MSC_VER
- }
- 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);
- if(eLevel == Severity_High)
- {
- #if defined(_MSC_VER)
- PostMessage(m_hWndStartPage, WM_SHOW_MSG, (WPARAM)strdup(str), (LPARAM)RGB(255, 132, 32));
- #endif //_MSC_VER
- }
- }
- 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);
- else
- return;
- OutputMsg(str);
- }
- }
- CEntityBase* GUITask::GetEntity()
- {
- return m_pEntity;
- }
- ErrorCodeEnum GUITask::ShowMaintainView(bool bShow, bool bHighLevel)
- {
- #if defined(_MSC_VER)
- if (m_hWndMainFrame) {
- PostMessage(m_hWndMainFrame, WM_SHOW_MAINTAIN_VIEW, bShow ? 1 : 0, bHighLevel ? 1 : 0);
- return Error_Succeed;
- } else
- return Error_NotExist;
- #else
- return Error_NotSupport;
- #endif //_MSC_VER
- }
- ErrorCodeEnum GUITask::SetWindowPosition(bool bTop)
- {
- #if defined(_MSC_VER)
- if (m_hWndMainFrame) {
- if (bTop) {
- ShowWindow(m_hWndMainFrame, SW_NORMAL);
- SetWindowPos(m_hWndMainFrame, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
- SetWindowPos(m_hWndMainFrame, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
- } else {
- SetWindowPos(m_hWndMainFrame, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
- SetWindowPos(m_hWndMainFrame, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
- ShowWindow(m_hWndMainFrame, SW_MINIMIZE);
- }
- return Error_Succeed;
- } else
- return Error_NotExist;
- #else
- return Error_NotSupport;
- #endif //_MSC_VER
- }
- ErrorCodeEnum GUITask::ShowBeginInit(bool bShow)
- {
- #if defined(_MSC_VER)
- if (m_hWndMainFrame) {
- PostMessage(m_hWndMainFrame, WM_SHOW_BEGININIT_VIEW, bShow ? 1 : 0, -1);
- return Error_Succeed;
- } else
- return Error_NotExist;
- #else
- return Error_NotSupport;
- #endif //_MSC_VER
- }
- ErrorCodeEnum GUITask::EnableMobileDialMenu(bool bEnable)
- {
- #if defined(_MSC_VER)
- if (m_hWndMainFrame) {
- PostMessage(m_hWndMainFrame, WM_SHOW_MOBILEDIAL_VIEW, bEnable ? 1 : 0, -1);
- return Error_Succeed;
- } else {
- return Error_NotExist;
- }
- #else
- return Error_NotSupport;
- #endif //_MSC_VER
- }
- void GUITask::CloseSoftKeyboard()
- {
- #if defined(_MSC_VER)
- 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);
- }
- #endif //_MSC_VER
- }
- 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();
- }
- void GUITask::OnSysVarEvent(const char *pszKey,
- const char *pszValue, const char *pszOldValue, const char *pszEntityName)
- {
- if ((_strnicmp(pszKey, "UIState", strlen("UIState")) == 0))
- {
- if (_strnicmp(pszValue, "M", strlen("M")) == 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("close start page");
- #if defined(_MSC_VER)
- if (m_hWndStartPage) {
- PostMessageA(m_hWndStartPage, WM_CLOSE, -1, -1);
- }
- #endif //_MSC_VER
- m_pEntity->GetFunction()->UnregistSysVarEvent("UIState");
- }
- }
- }
- ErrorCodeEnum GUITask::HideGuiConsole()
- {
- #if defined(_MSC_VER)
- ShowWindow(m_hWndMainFrame, SW_HIDE);
- #endif //_MSC_VER
- return Error_Succeed;
- }
|