guitask.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. #include "stdafx2.h"
  2. #include "SpBase.h"
  3. #include "guitask.h"
  4. #include "mainfrm.h"
  5. #include "SpIni.h"
  6. #include "path.h"
  7. #include <winpr/sysinfo.h>
  8. #include "AccessAuthorization_client_g.h"
  9. using namespace AccessAuthorization;
  10. #include "mod_CenterSetting/Event.h"
  11. int level = 2;
  12. GUITask::GUITask() : m_pEntity(NULL), m_hWndMainFrame(NULL), m_hThread(NULL), m_hThread2(NULL), m_hWndStartPage(NULL),
  13. m_idleNum(0), m_totalNum(0)
  14. {
  15. m_hEventStartReady = ::CreateEventA(NULL, TRUE, FALSE, NULL);
  16. m_hEventStopReady = ::CreateEventA(NULL, TRUE, FALSE, NULL);
  17. m_hWndStartPage =NULL;
  18. }
  19. GUITask::~GUITask()
  20. {
  21. CloseHandle(m_hEventStopReady);
  22. CloseHandle(m_hEventStartReady);
  23. }
  24. void GUITask::InitBack(CEntityBase* pEntity)
  25. {
  26. m_pEntity = pEntity;
  27. m_pEntity->GetFunction()->RegistSysVarEvent("UIState", this);
  28. m_pEntity->GetFunction()->RegistSysVarEvent("TerminalStage", this);
  29. }
  30. ErrorCodeEnum GUITask::Kickoff(CEntityBase *pEntity)
  31. {
  32. LOG_FUNCTION();
  33. #if defined(RVC_OS_WIN)
  34. if (m_hThread) {
  35. return Error_Duplication;
  36. }
  37. m_pEntity = pEntity;
  38. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  39. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  40. ErrorCodeEnum errCode = pFuncPrivilege->RegistEntityStateEvent(NULL,this);
  41. if (errCode != Error_Succeed)
  42. {
  43. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("RegistEntityState failed(%d).",errCode);
  44. return Error_Unexpect;
  45. }
  46. m_totalNum = GetWillWorkEntityCountFromHealthmanager();
  47. if (m_totalNum == 0) {
  48. CAutoArray<EntityEntry> Entities;
  49. ErrorCodeEnum err = GetAllEntity(Entities);
  50. m_totalNum = Entities.GetCount();
  51. }
  52. m_hThread = (HANDLE)_beginthreadex(0, 0, &__Process, this, 0, 0);
  53. if (!m_hThread) {
  54. return Error_Resource;
  55. }
  56. WaitForSingleObject(m_hEventStartReady, INFINITE);
  57. //SubscribeLog();
  58. return RegistEntityStateEvent();
  59. #else
  60. return Error_NotSupport;
  61. #endif //RVC_OS_WIN
  62. }
  63. ErrorCodeEnum GUITask::Close()
  64. {
  65. #if defined(RVC_OS_WIN)
  66. if (!m_hThread) {
  67. return Error_NotInit;
  68. }
  69. UnSubscribeLog();
  70. UnregistEntityStateEvent();
  71. if (m_hWndMainFrame) {
  72. PostMessageA(m_hWndMainFrame, WM_CLOSE, -1, -1);
  73. WaitForSingleObject(m_hEventStopReady, INFINITE);
  74. }
  75. WaitForSingleObject(m_hThread, INFINITE);
  76. CloseHandle(m_hThread);
  77. m_hThread = 0;
  78. #endif //RVC_OS_WIN
  79. return Error_Succeed;
  80. }
  81. #if defined(RVC_OS_WIN)
  82. CAppModule _Module;
  83. #endif //RVC_OS_WIN
  84. void GUITask::Process()
  85. {
  86. #if defined(RVC_OS_WIN)
  87. ResetEvent(m_hEventStartReady);
  88. m_pEntity->GetFunction()->InitLogCurrentThread();
  89. HRESULT hRes = ::CoInitialize(NULL);
  90. // If you are running on NT 4.0 or higher you can use the following call instead to
  91. // make the EXE free threaded. This means that calls come in on a random RPC thread.
  92. // HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
  93. ATLASSERT(SUCCEEDED(hRes));
  94. // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
  95. ::DefWindowProc(NULL, 0, 0, 0L);
  96. AtlInitCommonControls(ICC_COOL_CLASSES | ICC_BAR_CLASSES); // add flags to support other controls
  97. hRes = _Module.Init(NULL, ModuleBase::GetModuleBase()->GetInstance());
  98. ATLASSERT(SUCCEEDED(hRes));
  99. ATL::AtlAxWinInit();
  100. CMessageLoop theLoop;
  101. _Module.AddMessageLoop(&theLoop);
  102. CMainFrame wndMain(this);
  103. if(wndMain.CreateEx() == NULL)
  104. {
  105. ATLTRACE(_T("Main window creation failed!\n"));
  106. return;
  107. }
  108. m_hWndMainFrame = wndMain.m_hWnd;
  109. CSmartPointer<IConfigInfo> pConfig;
  110. auto rc = m_pEntity->GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
  111. CSimpleStringA csimpleStrMachineTypeCfg(true);
  112. StartPageDlg dlg(this);
  113. //oilyang@20231017 directly show window of boot
  114. //if (IS_SUCCEED(rc)) {
  115. // rc = pConfig->ReadConfigValue("NonExclusive", "NewStartPage", csimpleStrMachineTypeCfg);
  116. CSystemStaticInfo staticInfo;
  117. m_pEntity->GetFunction()->GetSystemStaticInfo(staticInfo);
  118. //if (csimpleStrMachineTypeCfg.IndexOf(staticInfo.strMachineType) >= 0) {
  119. TerminalBaseInfo info;
  120. info.strMachineType = staticInfo.strMachineType;
  121. info.strTerminalNo = staticInfo.strTerminalID;
  122. info.strSoftwareVersion = staticInfo.InstallVersion.ToString();
  123. dlg.SetTerminalBasicInfo(info);
  124. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Enter newpage...");
  125. if (dlg.Create(NULL) == NULL) {
  126. ATLTRACE(_T("Main window creation failed!\n"));
  127. return;
  128. }
  129. m_hWndStartPage = dlg.m_hWnd;
  130. //}
  131. //}
  132. SetEvent(m_hEventStartReady);
  133. wndMain.ShowWindow(SW_MINIMIZE);
  134. if(m_hWndStartPage)
  135. dlg.ShowWindow(SW_SHOW);
  136. else
  137. ShowOutputConsole();
  138. int nRet = theLoop.Run();
  139. _Module.RemoveMessageLoop();
  140. _Module.Term();
  141. ::CoUninitialize();
  142. SetEvent(m_hEventStopReady);
  143. m_hWndMainFrame = NULL;
  144. #endif //RVC_OS_WIN
  145. }
  146. ErrorCodeEnum GUITask::RegistEntityStateEvent()
  147. {
  148. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  149. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  150. if (pFuncPrivilege != NULL) {
  151. return pFuncPrivilege->RegistEntityStateEvent(NULL, this); // NULL to register for all
  152. } else {
  153. return Error_NoPrivilege;
  154. }
  155. }
  156. ErrorCodeEnum GUITask::UnregistEntityStateEvent()
  157. {
  158. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  159. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  160. if (pFuncPrivilege != NULL) {
  161. return pFuncPrivilege->UnregistEntityStateEvent(NULL);
  162. } else {
  163. return Error_NoPrivilege;
  164. }
  165. }
  166. ErrorCodeEnum GUITask::ReqFrameworkQuit(bool bRebootOS)
  167. {
  168. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  169. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  170. if (pFuncPrivilege != NULL)
  171. {
  172. CSmartPointer<IConfigInfo> pConfig;
  173. auto rc = m_pEntity->GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
  174. int iNoRestart;
  175. CSimpleStringA csimpleStrMachineTypeCfg;
  176. rc = pConfig->ReadConfigValue("NonExclusive", "NonGuardian", csimpleStrMachineTypeCfg);
  177. CSystemStaticInfo staticInfo;
  178. m_pEntity->GetFunction()->GetSystemStaticInfo(staticInfo);
  179. if(csimpleStrMachineTypeCfg.IndexOf(staticInfo.strMachineType)>=0)
  180. return pFuncPrivilege->Reboot(RebootTrigger_ManualLocal, bRebootOS ? RebootWay_OS : RebootWay_Power );
  181. return pFuncPrivilege->Reboot(RebootTrigger_ManualLocal, bRebootOS ? RebootWay_OS : RebootWay_Framework );
  182. }
  183. return Error_Unexpect;
  184. }
  185. ErrorCodeEnum GUITask::SubscribeLog()
  186. {
  187. #if defined(_MSC_VER)
  188. return m_pEntity->GetFunction()->SubscribeLog(m_logSubID, this, Log_Ignore, Severity_None, Error_IgnoreAll, -1, NULL, false);
  189. #else
  190. return Error_NotSupport;
  191. #endif //_MSC_VER
  192. }
  193. ErrorCodeEnum GUITask::UnSubscribeLog()
  194. {
  195. if (HasSubscibeLog())
  196. {
  197. m_pEntity->GetFunction()->UnsubscribeLog(m_logSubID);
  198. m_logSubID = 0;
  199. }
  200. return Error_Succeed;
  201. }
  202. ErrorCodeEnum GUITask::SetDebugLevel(const char *pszEntity, int nLevel)
  203. {
  204. return m_pEntity->GetFunction()->GetPrivilegeFunction()->SetSysDebugLevel(pszEntity, (DebugLevelEnum)nLevel, true);
  205. }
  206. ErrorCodeEnum GUITask::GetShellDebugLevel(int &nLevel)
  207. {
  208. CSystemRunInfo info ={};
  209. auto rc = m_pEntity->GetFunction()->GetSystemRunInfo(info);
  210. if (rc == Error_Succeed)
  211. nLevel = info.eDebugLevel;
  212. return rc;
  213. }
  214. ErrorCodeEnum GUITask::BeginAccessAuth()
  215. {
  216. AccessAuthService_ClientBase *pClient = new AccessAuthService_ClientBase(m_pEntity);
  217. auto rc = pClient->Connect();
  218. if (rc == Error_Succeed)
  219. {
  220. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("connect to entity [AccessAuthorization] succeed, start access auth now");
  221. rc = (*pClient)(EntityResource::getLink().upgradeLink())->Regist();
  222. pClient->GetFunction()->CloseSession();
  223. }
  224. else
  225. {
  226. LogWarn(Severity_Low, rc, 0, "connect to entity [AccessAuthorization] fail");
  227. pClient->SafeDelete();
  228. }
  229. return rc;
  230. }
  231. ErrorCodeEnum GUITask::BeginInitialize()
  232. {
  233. return Error_NotImpl;
  234. }
  235. #include "mod_GuiConsole.h"
  236. ErrorCodeEnum GUITask::DeleteKeySet()
  237. {
  238. #if defined(_MSC_VER)
  239. HCRYPTPROV hProv(0);
  240. if (!CryptAcquireContext(&hProv, "RVC", MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_MACHINE_KEYSET | CRYPT_DELETEKEYSET)) {
  241. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("delete keyset fail: %d", GetLastError());
  242. return Error_Unexpect;
  243. } else {
  244. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("delete keyset succ");
  245. return Error_Succeed;
  246. }
  247. #else
  248. return Error_NotImpl;
  249. #endif //_MSC_VER
  250. }
  251. ErrorCodeEnum GUITask::GetFrameworkInfo(CSimpleStringA &strInfo)
  252. {
  253. CSystemStaticInfo info;
  254. memset(&info, 0, sizeof(info));
  255. auto rc = m_pEntity->GetFunction()->GetSystemStaticInfo(info);
  256. if (rc == Error_Succeed) {
  257. strInfo = CSimpleStringA::Format("[%s] [%s]", (const char*) info.strTerminalID, (const char*)info.InstallVersion.ToString());
  258. }
  259. return rc;
  260. }
  261. ErrorCodeEnum GUITask::AsyncStartEntity(const char *entity_name, const char *cmdline, void *pData)
  262. {
  263. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  264. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  265. if (pFuncPrivilege != NULL) {
  266. CSmartPointer<IAsynWaitSp> spWait;
  267. ErrorCodeEnum Error = pFuncPrivilege->StartEntity(entity_name, cmdline, spWait);
  268. if (Error == Error_Succeed) {
  269. callback_entry *entry = new callback_entry();
  270. entry->pRawData = pData;
  271. entry->EntityName = entity_name;
  272. entry->ErrorResult = Error_Unexpect;
  273. entry->op = OP_START_ENTITY;
  274. spWait->SetCallback(this, entry);
  275. }
  276. return Error;
  277. } else {
  278. return Error_NoPrivilege;
  279. }
  280. }
  281. ErrorCodeEnum GUITask::AsyncStopEntity(const char *entity_name, void *pData)
  282. {
  283. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  284. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  285. if (pFuncPrivilege != NULL) {
  286. CSmartPointer<IAsynWaitSp> spWait;
  287. ErrorCodeEnum Error = pFuncPrivilege->StopEntity(entity_name, spWait);
  288. if (Error == Error_Succeed) {
  289. callback_entry *entry = new callback_entry();
  290. entry->pRawData = pData;
  291. entry->EntityName = entity_name;
  292. entry->ErrorResult = Error_Unexpect;
  293. entry->op = OP_STOP_ENTITY;
  294. spWait->SetCallback(this, entry);
  295. }
  296. return Error;
  297. } else {
  298. return Error_NoPrivilege;
  299. }
  300. }
  301. ErrorCodeEnum GUITask::AsyncPauseEntity(const char *entity_name, void *pData)
  302. {
  303. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  304. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  305. if (pFuncPrivilege != NULL) {
  306. CSmartPointer<IAsynWaitSp> spWait;
  307. ErrorCodeEnum Error = pFuncPrivilege->PauseEntity(entity_name, spWait);
  308. if (Error == Error_Succeed) {
  309. callback_entry *entry = new callback_entry();
  310. entry->pRawData = pData;
  311. entry->EntityName = entity_name;
  312. entry->ErrorResult = Error_Unexpect;
  313. entry->op = OP_PAUSE_ENTITY;
  314. spWait->SetCallback(this, entry);
  315. }
  316. return Error;
  317. } else {
  318. return Error_NoPrivilege;
  319. }
  320. }
  321. ErrorCodeEnum GUITask::AsyncContinueEntity(const char *entity_name, void *pData)
  322. {
  323. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  324. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  325. if (pFuncPrivilege != NULL) {
  326. CSmartPointer<IAsynWaitSp> spWait;
  327. ErrorCodeEnum Error = pFuncPrivilege->ContinueEntity(entity_name, spWait);
  328. if (Error == Error_Succeed) {
  329. callback_entry *entry = new callback_entry();
  330. entry->pRawData = pData;
  331. entry->EntityName = entity_name;
  332. entry->ErrorResult = Error_Unexpect;
  333. entry->op = OP_CONTINUE_ENTITY;
  334. spWait->SetCallback(this, entry);
  335. }
  336. return Error;
  337. } else {
  338. return Error_NoPrivilege;
  339. }
  340. }
  341. ErrorCodeEnum GUITask::AsyncTerminateEntity(const char *entity_name, void *pData)
  342. {
  343. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  344. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  345. if (pFuncPrivilege != NULL) {
  346. CSmartPointer<IAsynWaitSp> spWait;
  347. ErrorCodeEnum Error = pFuncPrivilege->TerminateEntity(entity_name, spWait);
  348. if (Error == Error_Succeed) {
  349. callback_entry *entry = new callback_entry();
  350. entry->pRawData = pData;
  351. entry->EntityName = entity_name;
  352. entry->ErrorResult = Error_Unexpect;
  353. entry->op = OP_TERMINATE_ENTITY;
  354. spWait->SetCallback(this, entry);
  355. }
  356. return Error;
  357. } else {
  358. return Error_NoPrivilege;
  359. }
  360. }
  361. UINT CalcKeyCountUnderSection(const char* pszFile, const char* pszSection)
  362. {
  363. UINT result(0);
  364. #if defined(_MSC_VER)
  365. DWORD dwInitialCapacity = 16;
  366. DWORD dwSize;
  367. char* p = NULL;
  368. const int tries = 70;
  369. ErrorCodeEnum Error = Error_Succeed;
  370. int i;
  371. for (i = 0; i < tries; ++i) {
  372. p = (char*)realloc(p, dwInitialCapacity);
  373. dwSize = ::GetPrivateProfileStringA(pszSection, NULL, NULL, p, dwInitialCapacity, pszFile);
  374. if (dwSize == dwInitialCapacity - 2) { // buffer is too small
  375. dwInitialCapacity = dwInitialCapacity * 2;
  376. } else {
  377. break;
  378. }
  379. }
  380. if (i < tries) {
  381. int cnt = 0;
  382. char* t = p;
  383. size_t n;
  384. while ((n = strlen(t)) > 0) {
  385. cnt++;
  386. t += n + 1;
  387. }
  388. result = cnt;
  389. }
  390. free(p);
  391. #endif //_MSC_VER
  392. return result;
  393. }
  394. UINT GUITask::GetWillWorkEntityCountFromHealthmanager()
  395. {
  396. UINT count(0);
  397. CSystemStaticInfo sysInfo;
  398. CSimpleStringA cfgPath = "", strCoreBoot("CoreBoot"), strSafeLoad("SafeLoad"), strOp("Operating");
  399. m_pEntity->GetFunction()->GetPath("cfg", cfgPath);
  400. m_pEntity->GetFunction()->GetSystemStaticInfo(sysInfo);
  401. strCoreBoot = strCoreBoot + "." + sysInfo.strMachineType;
  402. strSafeLoad = strSafeLoad + "." + sysInfo.strMachineType;
  403. strOp = strOp + "." + sysInfo.strMachineType;
  404. cfgPath = cfgPath + "\\HealthManager.ini";
  405. count += CalcKeyCountUnderSection(cfgPath, strCoreBoot);
  406. count += CalcKeyCountUnderSection(cfgPath, strSafeLoad);
  407. count += CalcKeyCountUnderSection(cfgPath, strOp);
  408. return count;
  409. }
  410. ErrorCodeEnum GUITask::GetAllEntity(CAutoArray<EntityEntry> &Entities)
  411. {
  412. CSmartPointer<IEntityFunction> spFunc = m_pEntity->GetFunction();
  413. CAutoArray<CSimpleStringA> strEntityNames;
  414. CAutoArray<WORD> wDevelopIDs;
  415. ErrorCodeEnum Error = spFunc->GetAllRegistedEntity(strEntityNames, wDevelopIDs);
  416. if (Error == Error_Succeed) {
  417. Entities.Init(strEntityNames.GetCount());
  418. for (int i = 0; i < strEntityNames.GetCount(); ++i) {
  419. Error = GetEntity(strEntityNames[i], Entities[i]);
  420. }
  421. }
  422. return Error;
  423. }
  424. ErrorCodeEnum GUITask::GetEntity(const char *entity_name, EntityEntry &e)
  425. {
  426. CSmartPointer<IEntityFunction> spFunc = m_pEntity->GetFunction();
  427. LOG_ASSERT(spFunc != NULL);
  428. CEntityStaticInfo StaticInfo;
  429. CEntityRunInfo RunInfo;
  430. ErrorCodeEnum Error = spFunc->GetEntityStaticInfo(entity_name, StaticInfo);
  431. if (Error == Error_Succeed) {
  432. Error = spFunc->GetEntityRunInfo(entity_name, RunInfo);
  433. if (Error == Error_Succeed) {
  434. e.Name = entity_name;
  435. e.Id = RunInfo.dwEntityInstanceID;
  436. e.ModuleName = _GetFileName(StaticInfo.strSpFileName);
  437. e.State = RunInfo.eState;
  438. e.Type = StaticInfo.bStartedByShell ? 0 : 1;
  439. e.Pid = (int)RunInfo.dwProcessID;
  440. e.DevelopID = (int)StaticInfo.wEntityDevelopID;
  441. e.DebugLevel = RunInfo.eDebugLevel;
  442. }
  443. }
  444. return Error;
  445. }
  446. ErrorCodeEnum GUITask::GetCustomizeStartMenuList(CAutoArray<StartMenuEntry> &StartItems)
  447. {
  448. int cnt = 0;
  449. StartItems.Clear();
  450. return Error_Deprecated;
  451. }
  452. void GUITask::OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp)
  453. {
  454. #if defined(_MSC_VER)
  455. if (m_hWndMainFrame) {
  456. CSmartPointer<ICallbackListener> spCallback;
  457. CSmartPointer<IReleasable> pData;
  458. pAsynWaitSp->GetCallback(spCallback, pData);
  459. LOG_ASSERT(pData.GetRawPointer() != NULL);
  460. callback_entry* entry = static_cast<callback_entry*>((IReleasable*)pData.GetRawPointer());
  461. entry->ErrorResult = pAsynWaitSp->AsyncGetAnswer();
  462. callback_entry* new_entry = new callback_entry();
  463. new_entry->EntityName = entry->EntityName;
  464. new_entry->ErrorResult = entry->ErrorResult;
  465. new_entry->op = entry->op;
  466. new_entry->state = entry->state;
  467. PostMessage(m_hWndMainFrame, WM_GUICONSOLE, 0, (LPARAM)new_entry);
  468. }
  469. #endif //_MSC_VER
  470. }
  471. ErrorCodeEnum GUITask::OutputMsg(const char *pMsg)
  472. {
  473. #if defined(_MSC_VER)
  474. if (m_hWndMainFrame) {
  475. PostMessage(m_hWndMainFrame, WM_SHOW_MSG, 0, (LPARAM)strdup(pMsg));
  476. return Error_Succeed;
  477. } else
  478. return Error_NotExist;
  479. #else
  480. return Error_NotSupport;
  481. #endif //_MSC_VER
  482. }
  483. void GUITask::OnEntityStateHook(const char *pszEntityName,const char *pszTriggerEntity,EntityStateEnum eState,EntityStateEnum eLastState)
  484. {
  485. #if defined(_MSC_VER)
  486. if (m_hWndMainFrame) {
  487. callback_entry* entry = new callback_entry();
  488. entry->EntityName = pszEntityName;
  489. entry->ErrorResult = Error_Succeed;
  490. entry->op = OP_FIRE_ENTITY_STATE;
  491. entry->state = eState;
  492. DWORD dwProcessID = 0;
  493. //if (entry->state != EntityState_Close) // 关闭状态进程号清0置后
  494. {
  495. CEntityRunInfo Info;
  496. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  497. pFunc->GetEntityRunInfo(entry->EntityName, Info);
  498. dwProcessID = Info.dwProcessID;
  499. }
  500. PostMessage(m_hWndMainFrame, WM_GUICONSOLE, dwProcessID, (LPARAM)entry);
  501. }
  502. SYSTEMTIME st;
  503. GetLocalTime(&st);
  504. CSimpleStringA msg;
  505. if(eState == EntityState_Starting)
  506. msg = CSimpleString::Format("[%04d-%02d-%02d %02d:%02d:%02d] 正在启动实体%s...", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, pszEntityName);
  507. if(eState == EntityState_Idle)
  508. {
  509. msg = CSimpleString::Format("[%04d-%02d-%02d %02d:%02d:%02d] %s 实体启动成功", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, pszEntityName);
  510. m_idleNum++;
  511. }
  512. if(eLastState == EntityState_Idle && eState != EntityState_Idle )
  513. {
  514. msg = CSimpleString::Format("[%04d-%02d-%02d %02d:%02d:%02d] %s实体异常,重新启动...", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, pszEntityName);
  515. m_idleNum--;
  516. }
  517. PostMessage(m_hWndStartPage, WM_NUMCHANGE, 0, 0);
  518. PostMessage(m_hWndStartPage, WM_SHOW_MSG, (WPARAM)strdup(msg), (LPARAM)RGB(171, 171, 171));
  519. #endif //_MSC_VER
  520. }
  521. void GUITask::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  522. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  523. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo)
  524. {
  525. // 忽略GPIO事件
  526. if (dwUserCode == 0x2090000A || dwUserCode == 0x20900009)
  527. return;
  528. else if (dwUserCode == EVENT_MOD_CENTERSETTING_UPDATE_CENTER)
  529. {
  530. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("检测到集中配置更新了");
  531. auto generateCenterSettingPath = []() ->std::string {
  532. char pathbuf[1024] = "";
  533. int pathlen = ::GetModuleFileNameA(NULL, pathbuf, 1024);//获得GuiConsole路径
  534. // 替换掉单杠
  535. int times = 0;
  536. while (pathlen > 0)
  537. {
  538. if (pathbuf[pathlen--] == SPLIT_SLASH)
  539. times++;
  540. if (2 == times)
  541. break;
  542. }
  543. pathbuf[++pathlen] = '\0';
  544. std::string dstPath = pathbuf;
  545. #if defined(_MSC_VER)
  546. dstPath.append("\\cfg\\CenterSetting.ini");
  547. #else
  548. dstPath.append("/cfg/CenterSetting.LAN.ini");
  549. #endif //_MSC_VER
  550. return dstPath;
  551. };
  552. //实时更新实体打印的日志等级,这个功能在信创下需要调整,实现方式不一样 gifur@20230816
  553. auto centersettingPath = generateCenterSettingPath();
  554. load_debugLevelInCentersetting(centersettingPath.c_str());
  555. }
  556. SYSTEMTIME st;
  557. GetLocalTime(&st);
  558. CSimpleString timeStr = CSimpleString::Format("[%04d-%02d-%02d %02d:%02d:%02d]", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
  559. if (pszMessage!=NULL && strlen(pszMessage)>2)
  560. {
  561. CSimpleStringA str = pszMessage;
  562. if (str[str.GetLength()-2] == '\r' && str[str.GetLength()-1]=='\n')
  563. str[str.GetLength()-2] = 0;
  564. if (eLogType == Log_Error)
  565. {
  566. str = CSimpleStringA::Format("%s [%s] Error:{%s}(sc:0x%X, uc:0x%X)\r\n", timeStr.GetData(), pszEntityName, (const char*)str, dwSysError, dwUserCode);
  567. #if defined(_MSC_VER)
  568. PostMessage(m_hWndStartPage, WM_SHOW_MSG, (WPARAM)strdup(str), (LPARAM)RGB(255, 132, 32));
  569. #endif //_MSC_VER
  570. }
  571. else if(eLogType == Log_Warning)
  572. {
  573. str = CSimpleStringA::Format("%s [%s] Warn:{%s}(sc:0x%X, uc:0x%X)\r\n", timeStr.GetData(), pszEntityName, (const char*)str, dwSysError, dwUserCode);
  574. if (eLevel == Severity_High || eLevel == Severity_Middle)
  575. {
  576. #if defined(_MSC_VER)
  577. PostMessage(m_hWndStartPage, WM_SHOW_MSG, (WPARAM)strdup(str), (LPARAM)RGB(255, 132, 32));
  578. #endif //_MSC_VER
  579. }
  580. }
  581. else if(eLogType == Log_Event)
  582. str = CSimpleStringA::Format("[%s] Event:{%s}(uc:0x%X)\r\n", pszEntityName, (const char*)str, dwUserCode);
  583. else if (eLogType == Log_Debug)
  584. str = CSimpleStringA::Format("[%s] Debug:{%s}\r\n", pszEntityName, (const char*)str);
  585. else
  586. return;
  587. OutputMsg(str);
  588. }
  589. }
  590. CEntityBase* GUITask::GetEntity()
  591. {
  592. return m_pEntity;
  593. }
  594. ErrorCodeEnum GUITask::ShowMaintainView(bool bShow, bool bHighLevel)
  595. {
  596. #if defined(_MSC_VER)
  597. if (m_hWndMainFrame) {
  598. PostMessage(m_hWndMainFrame, WM_SHOW_MAINTAIN_VIEW, bShow ? 1 : 0, bHighLevel ? 1 : 0);
  599. return Error_Succeed;
  600. } else
  601. return Error_NotExist;
  602. #else
  603. return Error_NotSupport;
  604. #endif //_MSC_VER
  605. }
  606. ErrorCodeEnum GUITask::SetWindowPosition(bool bTop)
  607. {
  608. #if defined(_MSC_VER)
  609. if (m_hWndMainFrame) {
  610. if (bTop) {
  611. ShowWindow(m_hWndMainFrame, SW_NORMAL);
  612. SetWindowPos(m_hWndMainFrame, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  613. SetWindowPos(m_hWndMainFrame, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  614. } else {
  615. SetWindowPos(m_hWndMainFrame, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  616. SetWindowPos(m_hWndMainFrame, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  617. ShowWindow(m_hWndMainFrame, SW_MINIMIZE);
  618. }
  619. return Error_Succeed;
  620. } else
  621. return Error_NotExist;
  622. #else
  623. return Error_NotSupport;
  624. #endif //_MSC_VER
  625. }
  626. ErrorCodeEnum GUITask::ShowBeginInit(bool bShow)
  627. {
  628. #if defined(_MSC_VER)
  629. if (m_hWndMainFrame) {
  630. PostMessage(m_hWndMainFrame, WM_SHOW_BEGININIT_VIEW, bShow ? 1 : 0, -1);
  631. return Error_Succeed;
  632. } else
  633. return Error_NotExist;
  634. #else
  635. return Error_NotSupport;
  636. #endif //_MSC_VER
  637. }
  638. ErrorCodeEnum GUITask::EnableMobileDialMenu(bool bEnable)
  639. {
  640. #if defined(_MSC_VER)
  641. if (m_hWndMainFrame) {
  642. PostMessage(m_hWndMainFrame, WM_SHOW_MOBILEDIAL_VIEW, bEnable ? 1 : 0, -1);
  643. return Error_Succeed;
  644. } else {
  645. return Error_NotExist;
  646. }
  647. #else
  648. return Error_NotSupport;
  649. #endif //_MSC_VER
  650. }
  651. void GUITask::CloseSoftKeyboard()
  652. {
  653. #if defined(_MSC_VER)
  654. HANDLE hProcessHandle;
  655. ULONG nProcessID;
  656. HWND kbWindow;
  657. kbWindow = ::FindWindow(NULL, _T("屏幕键盘"));
  658. if (NULL != kbWindow) {
  659. ::GetWindowThreadProcessId(kbWindow, &nProcessID);
  660. hProcessHandle = ::OpenProcess(PROCESS_TERMINATE, FALSE, nProcessID);
  661. ::TerminateProcess(hProcessHandle, 4);
  662. }
  663. #endif //_MSC_VER
  664. }
  665. ErrorCodeEnum GUITask::ShowBlueScreen()
  666. {
  667. auto pEntityFunc = m_pEntity->GetFunction();
  668. auto pPrevFunc = pEntityFunc->GetPrivilegeFunction();
  669. const char *pMsg = "System Failure!System Failure!System Failure!System Failure!System Failure!System Failure!System Failure!System Failure!\r\n系统启动失败,请联系总行开发人员解决!";
  670. pPrevFunc->DisplayBlueScreen(pMsg);
  671. return Error_Succeed;
  672. }
  673. ErrorCodeEnum GUITask::ShowFatalError()
  674. {
  675. auto pEntityFunc = m_pEntity->GetFunction();
  676. const char *pMsg = "开放系统管理员初级培训及认证报名通知.开放系统管理员初级培训及认证报名通知.开放系统管理员初级培训及认证报名通知.开放系统管理员初级培训及认证报名通知.开放系统管理员初级培训及认证报名通知.";
  677. pEntityFunc->ShowFatalError(pMsg);
  678. return Error_Succeed;
  679. }
  680. ErrorCodeEnum GUITask::HideBlueScreen()
  681. {
  682. auto pEntityFunc = m_pEntity->GetFunction();
  683. auto pPrevFunc = pEntityFunc->GetPrivilegeFunction();
  684. return pPrevFunc->UndisplayBlueScreen();
  685. }
  686. ErrorCodeEnum GUITask::ShowOutputConsole()
  687. {
  688. auto pFunc = m_pEntity->GetFunction()->GetPrivilegeFunction();
  689. return pFunc->ShowOuputConsole();
  690. }
  691. ErrorCodeEnum GUITask::CloseOutputConsole()
  692. {
  693. auto pFunc = m_pEntity->GetFunction()->GetPrivilegeFunction();
  694. return pFunc->CloseOuputConsole();
  695. }
  696. void GUITask::OnSysVarEvent(const char *pszKey,
  697. const char *pszValue, const char *pszOldValue, const char *pszEntityName)
  698. {
  699. if ((_strnicmp(pszKey, "UIState", strlen("UIState")) == 0))
  700. {
  701. if (_strnicmp(pszValue, "M", strlen("M")) == 0)
  702. {
  703. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("close start page");
  704. #if defined(_MSC_VER)
  705. if (m_hWndStartPage) {
  706. PostMessageA(m_hWndStartPage, WM_CLOSE, -1, -1);
  707. }
  708. #endif //_MSC_VER
  709. m_pEntity->GetFunction()->UnregistSysVarEvent("UIState");
  710. }
  711. }
  712. if ((_strnicmp(pszKey, "TerminalStage", strlen("TerminalStage")) == 0))
  713. {
  714. if (_strnicmp(pszValue, "N", strlen("N")) == 0)
  715. {
  716. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("close start page");
  717. #if defined(_MSC_VER)
  718. if (m_hWndStartPage) {
  719. PostMessageA(m_hWndStartPage, WM_CLOSE, -1, -1);
  720. }
  721. #endif //_MSC_VER
  722. m_pEntity->GetFunction()->UnregistSysVarEvent("TerminalStage");
  723. }
  724. }
  725. }
  726. ErrorCodeEnum GUITask::HideGuiConsole()
  727. {
  728. #if defined(_MSC_VER)
  729. ShowWindow(m_hWndMainFrame, SW_HIDE);
  730. #endif //_MSC_VER
  731. return Error_Succeed;
  732. }