mod_ResourceWatcher.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. #pragma once
  2. #include "modVer.h"
  3. #include "SpTest.h"
  4. #include "ResourceWatcherFSM.h"
  5. #include "UOSTools.hpp"
  6. class ResourceWatcherEntity;
  7. #define ENT_TIMERID_CHECK_SOGOU_INPUT_INSTALLED_STATE 1
  8. #define ENT_TIMERINTERVAL_CHECK_SOGOU_INPUT_INSTALLED_STATE 60 * 1000
  9. #define ENT_TIMERID_CHECK_SOGOU_INPUT_PROCESS_STATUS_CHANGE 3
  10. #define ENT_TIMERINTERVAL_CHECK_SOGOU_INPUT_PROCESS_STATUS_CHANGE 30 * 1000
  11. class ResourceWatcherServiceSession : public ResourceWatcherService_ServerSessionBase
  12. {
  13. public:
  14. ResourceWatcherServiceSession(ResourceWatcherEntity* pEntity) : m_pEntity(pEntity) {}
  15. virtual ~ResourceWatcherServiceSession() {}
  16. virtual void Handle_Fetch(SpReqAnsContext<ResourceWatcherService_Fetch_Req,
  17. ResourceWatcherService_Fetch_Ans>::Pointer ctx);
  18. virtual void Handle_GetDevInfo(SpReqAnsContext<ResourceWatcherService_GetDevInfo_Req,
  19. ResourceWatcherService_GetDevInfo_Ans>::Pointer ctx);
  20. virtual void Handle_GetCardSwiper(SpReqAnsContext<ResourceWatcherService_GetCardSwiper_Req, ResourceWatcherService_GetCardSwiper_Ans>::Pointer ctx);
  21. virtual void Handle_GetCpuType(SpReqAnsContext<ResourceWatcherService_GetCpuType_Req, ResourceWatcherService_GetCpuType_Ans>::Pointer ctx);
  22. virtual void Handle_OperateFile(SpReqAnsContext<ResourceWatcherService_OperateFile_Req, ResourceWatcherService_OperateFile_Ans>::Pointer ctx);
  23. virtual void Handle_ExtractEventLog(SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req, ResourceWatcherService_ExtractEventLog_Ans>::Pointer ctx);
  24. virtual void Handle_UpdateDNS(SpReqAnsContext<ResourceWatcherService_UpdateDNS_Req, ResourceWatcherService_UpdateDNS_Ans>::Pointer ctx);
  25. virtual void Handle_GetNetworkInfo(SpReqAnsContext<ResourceWatcherService_GetNetworkInfo_Req, ResourceWatcherService_GetNetworkInfo_Ans>::Pointer ctx);
  26. virtual void Handle_GetThirdPartyInstallState(SpReqAnsContext<ResourceWatcherService_GetThirdPartyInstallState_Req, ResourceWatcherService_GetThirdPartyInstallState_Ans>::Pointer ctx);
  27. virtual void Handle_InstallThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_InstallThirdPartyProgram_Req, ResourceWatcherService_InstallThirdPartyProgram_Ans>::Pointer ctx);
  28. virtual void Handle_BizLinkDetect(SpReqAnsContext<ResourceWatcherService_BizLinkDetect_Req, ResourceWatcherService_BizLinkDetect_Ans>::Pointer ctx);
  29. virtual void Handle_CheckNetType(SpReqAnsContext<ResourceWatcherService_CheckNetType_Req, ResourceWatcherService_CheckNetType_Ans>::Pointer ctx);
  30. virtual void Handle_GetBizLinks(SpReqAnsContext<ResourceWatcherService_GetBizLinks_Req, ResourceWatcherService_GetBizLinks_Ans>::Pointer ctx);
  31. virtual void Handle_GetTerminalVersionList(SpReqAnsContext<ResourceWatcherService_GetTerminalVersionList_Req, ResourceWatcherService_GetTerminalVersionList_Ans>::Pointer ctx);
  32. virtual void Handle_ManipulateVersion(SpReqAnsContext<ResourceWatcherService_ManipulateVersion_Req, ResourceWatcherService_ManipulateVersion_Ans>::Pointer ctx);
  33. private:
  34. ResourceWatcherEntity* m_pEntity;
  35. };
  36. class ResourceWatcherEntity : public CEntityBase, public IBroadcastListener, public ITimerListener
  37. {
  38. public:
  39. ResourceWatcherEntity():m_bInitMode(FALSE) {}
  40. virtual ~ResourceWatcherEntity() {}
  41. virtual const char* GetEntityName() const { return "ResourceWatcher"; }
  42. const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
  43. ON_ENTITYT_TEST()
  44. virtual CServerSessionBase* OnNewSession(const char* , const char * )
  45. {
  46. LOG_FUNCTION();
  47. return new ResourceWatcherServiceSession(this);
  48. }
  49. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,
  50. CSmartPointer<ITransactionContext> pTransactionContext)
  51. {
  52. LOG_FUNCTION();
  53. ErrorCodeEnum errorCode = Error_Succeed;
  54. CSimpleStringA strtermState;
  55. GetFunction()->GetSysVar("TerminalStage", strtermState);
  56. if (strtermState.IsStartWith("Z=")) {
  57. Dbg("aaa in config mode");
  58. m_bInitMode = TRUE;
  59. }
  60. errorCode = m_fsm.Init(this);
  61. if (errorCode == Error_Succeed) {
  62. CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
  63. CSystemStaticInfo staticInfo;
  64. spEntityFunction->GetSystemStaticInfo(staticInfo);
  65. if (!staticInfo.strMachineType.IsNullOrEmpty() && !staticInfo.strMachineType.Compare("RVC.Pad", true)) {
  66. errorCode = spEntityFunction->SubscribeBroadcast("CardSwiper", NULL, this, m_uiCardSwiperStatusListener);
  67. if (errorCode != Error_Succeed) {
  68. LOG_TRACE("Subscribe CardSwiper evt failed 0x%x", errorCode);
  69. pTransactionContext->SendAnswer(errorCode);
  70. return;
  71. }
  72. Dbg("SubScribe CardSwiper status broadcast suc.");
  73. }
  74. }
  75. pTransactionContext->SendAnswer(errorCode);
  76. }
  77. void OnStarted()
  78. {
  79. m_fsm.AfterInit();
  80. ///**TODO(Gifur@10/21/2021): ´Ë½Ó¿ÚÓÐÎÊÌ⣬´ý²é£¡£¡£¡ */
  81. //m_bInitMode = m_fsm.IsInitMode();
  82. //Dbg("%s: %u", __FUNCTION__, m_bInitMode);
  83. if (!m_bInitMode) {
  84. CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
  85. spEntityFunction->SetTimer(ENT_TIMERID_CHECK_SOGOU_INPUT_INSTALLED_STATE,
  86. this, ENT_TIMERINTERVAL_CHECK_SOGOU_INPUT_INSTALLED_STATE);
  87. }
  88. }
  89. /*ignore*/
  90. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  91. {
  92. UOS::MonitorInfo info;
  93. info.name = "VGA-0";
  94. info.nResolutionX = 1280;
  95. info.nResolutionY = 1024;
  96. info.isPrimary = true;
  97. ConfigMonitorSetting(info);
  98. pTransactionContext->SendAnswer(Error_Succeed);
  99. }
  100. /*ignore*/
  101. virtual void OnPreContinue(CSmartPointer<ITransactionContext> pTransactionContext)
  102. {
  103. UOS::MonitorInfo info;
  104. info.name = "HDMI-A-0";
  105. info.nResolutionX = 1024;
  106. info.nResolutionY = 768;
  107. info.isPrimary = false;
  108. info.other = "VGA-0";
  109. info.posDirecttion = 2;
  110. ConfigMonitorSetting(info);
  111. pTransactionContext->SendAnswer(Error_Succeed);
  112. }
  113. /*invoke fsm.onExit(), invoked when entity will be closed*/
  114. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,
  115. CSmartPointer<ITransactionContext>pTransactionContext)
  116. {
  117. ErrorCodeEnum errorCode = m_fsm.OnExit();
  118. pTransactionContext->SendAnswer(errorCode);
  119. }
  120. virtual void OnSelfTest(EntityTestEnum eTestType,
  121. CSmartPointer<ITransactionContext>pTransactionContext)
  122. {
  123. m_fsm.SelfTest(eTestType, pTransactionContext);
  124. }
  125. virtual bool IsService() const
  126. {
  127. return true;
  128. }
  129. virtual bool IsMultiThread() const
  130. {
  131. return false;
  132. }
  133. void Fetch(SpReqAnsContext<ResourceWatcherService_Fetch_Req,
  134. ResourceWatcherService_Fetch_Ans>::Pointer ctx)
  135. {
  136. FetchEvent* evt = new FetchEvent();
  137. evt->ctx = ctx;
  138. m_fsm.PostEventFIFO(evt);
  139. }
  140. void GetDevInfo(SpReqAnsContext<ResourceWatcherService_GetDevInfo_Req,
  141. ResourceWatcherService_GetDevInfo_Ans>::Pointer ctx)
  142. {
  143. ctx->Answer(Error_NotImpl);
  144. }
  145. void GetCSwiperStatus(SpReqAnsContext<ResourceWatcherService_GetCardSwiper_Req,
  146. ResourceWatcherService_GetCardSwiper_Ans>::Pointer ctx)
  147. {
  148. ctx->Ans.status = m_fsm.GetCardSwiperVal();
  149. ctx->Answer(Error_Succeed);
  150. }
  151. void GetCPUType(SpReqAnsContext<ResourceWatcherService_GetCpuType_Req,
  152. ResourceWatcherService_GetCpuType_Ans>::Pointer ctx)
  153. {
  154. m_fsm.GetCpuType(ctx);
  155. }
  156. void BizLinkDetect(SpReqAnsContext<ResourceWatcherService_BizLinkDetect_Req,
  157. ResourceWatcherService_BizLinkDetect_Ans>::Pointer ctx)
  158. {
  159. m_fsm.BizLinkDetect(ctx);
  160. }
  161. void CheckNetType(SpReqAnsContext<ResourceWatcherService_CheckNetType_Req,
  162. ResourceWatcherService_CheckNetType_Ans>::Pointer ctx)
  163. {
  164. m_fsm.CheckNetType(ctx);
  165. }
  166. void GetBizLinks(SpReqAnsContext<ResourceWatcherService_GetBizLinks_Req,
  167. ResourceWatcherService_GetBizLinks_Ans>::Pointer ctx)
  168. {
  169. m_fsm.GetBizLinks(ctx);
  170. }
  171. void GetTerminalVersionList(SpReqAnsContext<ResourceWatcherService_GetTerminalVersionList_Req, ResourceWatcherService_GetTerminalVersionList_Ans>::Pointer ctx);
  172. void ManipulateVersion(SpReqAnsContext<ResourceWatcherService_ManipulateVersion_Req, ResourceWatcherService_ManipulateVersion_Ans>::Pointer ctx);
  173. void OperateFile(
  174. SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
  175. ResourceWatcherService_OperateFile_Ans>::Pointer ctx)
  176. {
  177. OperateFileEvent* evt = new OperateFileEvent();
  178. evt->m_ctx = ctx;
  179. m_fsm.PostEventFIFO(evt);
  180. }
  181. void RetrieveEventLog(SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req,
  182. ResourceWatcherService_ExtractEventLog_Ans>::Pointer ctx)
  183. {
  184. LOG_FUNCTION();
  185. #if defined(RVC_OS_WIN)
  186. m_fsm.PostEventFIFO(new GetEventLogEvent(ctx));
  187. #else
  188. ctx->Answer(Error_NotSupport);
  189. #endif //RVC_OS_WIN
  190. }
  191. void UpdateDNS(SpReqAnsContext<ResourceWatcherService_UpdateDNS_Req, ResourceWatcherService_UpdateDNS_Ans>::Pointer ctx);
  192. void GetNetworkInfo(SpReqAnsContext<ResourceWatcherService_GetNetworkInfo_Req, ResourceWatcherService_GetNetworkInfo_Ans>::Pointer ctx);
  193. void GetThirdPartyInstallState(SpReqAnsContext<ResourceWatcherService_GetThirdPartyInstallState_Req, ResourceWatcherService_GetThirdPartyInstallState_Ans>::Pointer ctx);
  194. void InstallThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_InstallThirdPartyProgram_Req, ResourceWatcherService_InstallThirdPartyProgram_Ans>::Pointer ctx);
  195. #if defined(_MSC_VER)
  196. SP_BEGIN_MSG_DISPATCH_MAP(ResourceWatcherEntity)
  197. SP_BEGIN_ENTITY_MSG("CardSwiper")
  198. SP_MSG_HANDLE_NS(CardSwiper, ConnectStatus, OnCardSwiperConnectStatus)
  199. SP_END_ENTITY_MSG()
  200. SP_END_MSG_DISPATCH_MAP()
  201. #else
  202. virtual void OnBroadcastEvent(CUUID SubID, const char* pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, CAutoBuffer Buffer)
  203. {
  204. }
  205. #endif //_MSC_VER
  206. private:
  207. void OnCardSwiperConnectStatus(const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, CardSwiper::ConnectStatus &evt)
  208. {
  209. Dbg("OnCardSwiperConnectStatus %d", evt.status);
  210. QueryCardSwiper cardswiperStatus;
  211. cardswiperStatus.status = evt.status;
  212. m_fsm.m_cardswiperStatus = evt.status;
  213. SpSendBroadcast(GetFunction(), SP_MSG_OF(QueryCardSwiper), SP_MSG_SIG_OF(QueryCardSwiper),
  214. cardswiperStatus);
  215. }
  216. ErrorCodeEnum DoCheckInstallStateJob();
  217. void DoCheckSogouProcessStatus();
  218. void OnTimeout(DWORD dwTimerID)
  219. {
  220. if(dwTimerID == ENT_TIMERID_CHECK_SOGOU_INPUT_INSTALLED_STATE) {
  221. CSimpleStringA strState;
  222. auto err = GetFunction()->GetSysVar("UIState",strState);
  223. /** 让进入首页之后才获取输入法信息 [Gifur@20211212]*/
  224. if(/*TRUE || */err == Error_Succeed && strState == "M") {
  225. Dbg("to check Sogou input install state...");
  226. if(Error_Succeed == DoCheckInstallStateJob()) {
  227. GetFunction()->KillTimer(ENT_TIMERID_CHECK_SOGOU_INPUT_INSTALLED_STATE);
  228. GetFunction()->SetTimer(ENT_TIMERID_CHECK_SOGOU_INPUT_PROCESS_STATUS_CHANGE,
  229. this, ENT_TIMERINTERVAL_CHECK_SOGOU_INPUT_PROCESS_STATUS_CHANGE);
  230. }
  231. } else {
  232. Dbg("Get UIState result: %s, %s", SpStrError(err), strState.GetData());
  233. }
  234. } else if (dwTimerID == ENT_TIMERID_CHECK_SOGOU_INPUT_PROCESS_STATUS_CHANGE) {
  235. DoCheckSogouProcessStatus();
  236. }
  237. else {
  238. Dbg("Unkonwn timer id: %u", dwTimerID);
  239. }
  240. }
  241. ErrorCodeEnum ConfigMonitorSetting(const UOS::MonitorInfo& config);
  242. std::vector<std::string> GetUserNameList(bool bExcludeRoot = false);
  243. private:
  244. ResourceWatcherFSM m_fsm;
  245. CUUID m_uiCardSwiperStatusListener;
  246. BOOL m_bInitMode;
  247. };