123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- #pragma once
- #include "modVer.h"
- #include "SpTest.h"
- #include "ResourceWatcherFSM.h"
- #include "UOSTools.hpp"
- class ResourceWatcherEntity;
- #define ENT_TIMERID_CHECK_SOGOU_INPUT_INSTALLED_STATE 1
- #define ENT_TIMERINTERVAL_CHECK_SOGOU_INPUT_INSTALLED_STATE 60 * 1000
- #define ENT_TIMERID_CHECK_SOGOU_INPUT_PROCESS_STATUS_CHANGE 3
- #define ENT_TIMERINTERVAL_CHECK_SOGOU_INPUT_PROCESS_STATUS_CHANGE 30 * 1000
- class ResourceWatcherServiceSession : public ResourceWatcherService_ServerSessionBase
- {
- public:
- ResourceWatcherServiceSession(ResourceWatcherEntity* pEntity) : m_pEntity(pEntity) {}
- virtual ~ResourceWatcherServiceSession() {}
- virtual void Handle_Fetch(SpReqAnsContext<ResourceWatcherService_Fetch_Req,
- ResourceWatcherService_Fetch_Ans>::Pointer ctx);
- virtual void Handle_GetDevInfo(SpReqAnsContext<ResourceWatcherService_GetDevInfo_Req,
- ResourceWatcherService_GetDevInfo_Ans>::Pointer ctx);
-
- virtual void Handle_GetCardSwiper(SpReqAnsContext<ResourceWatcherService_GetCardSwiper_Req, ResourceWatcherService_GetCardSwiper_Ans>::Pointer ctx);
- virtual void Handle_GetCpuType(SpReqAnsContext<ResourceWatcherService_GetCpuType_Req, ResourceWatcherService_GetCpuType_Ans>::Pointer ctx);
- virtual void Handle_OperateFile(SpReqAnsContext<ResourceWatcherService_OperateFile_Req, ResourceWatcherService_OperateFile_Ans>::Pointer ctx);
- virtual void Handle_ExtractEventLog(SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req, ResourceWatcherService_ExtractEventLog_Ans>::Pointer ctx);
- virtual void Handle_UpdateDNS(SpReqAnsContext<ResourceWatcherService_UpdateDNS_Req, ResourceWatcherService_UpdateDNS_Ans>::Pointer ctx);
- virtual void Handle_GetNetworkInfo(SpReqAnsContext<ResourceWatcherService_GetNetworkInfo_Req, ResourceWatcherService_GetNetworkInfo_Ans>::Pointer ctx);
- virtual void Handle_GetThirdPartyInstallState(SpReqAnsContext<ResourceWatcherService_GetThirdPartyInstallState_Req, ResourceWatcherService_GetThirdPartyInstallState_Ans>::Pointer ctx);
- virtual void Handle_InstallThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_InstallThirdPartyProgram_Req, ResourceWatcherService_InstallThirdPartyProgram_Ans>::Pointer ctx);
- private:
- ResourceWatcherEntity* m_pEntity;
- };
- class ResourceWatcherEntity : public CEntityBase, public IBroadcastListener, public ITimerListener
- {
- public:
- ResourceWatcherEntity():m_bInitMode(FALSE) {}
- virtual ~ResourceWatcherEntity() {}
- virtual const char* GetEntityName() const { return "ResourceWatcher"; }
- const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
- ON_ENTITYT_TEST()
- virtual CServerSessionBase* OnNewSession(const char* , const char * )
- {
- LOG_FUNCTION();
- return new ResourceWatcherServiceSession(this);
- }
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,
- CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- ErrorCodeEnum errorCode = Error_Succeed;
- CSimpleStringA strtermState;
- GetFunction()->GetSysVar("TerminalStage", strtermState);
- if (strtermState.IsStartWith("Z=")) {
- Dbg("aaa in config mode");
- m_bInitMode = TRUE;
- }
- errorCode = m_fsm.Init(this);
- if (errorCode == Error_Succeed) {
- CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
- CSystemStaticInfo staticInfo;
- spEntityFunction->GetSystemStaticInfo(staticInfo);
- if (!staticInfo.strMachineType.IsNullOrEmpty() && !staticInfo.strMachineType.Compare("RVC.Pad", true)) {
- errorCode = spEntityFunction->SubscribeBroadcast("CardSwiper", NULL, this, m_uiCardSwiperStatusListener);
- if (errorCode != Error_Succeed) {
- LOG_TRACE("Subscribe CardSwiper evt failed 0x%x", errorCode);
- pTransactionContext->SendAnswer(errorCode);
- return;
- }
- Dbg("SubScribe CardSwiper status broadcast suc.");
- }
- }
-
- pTransactionContext->SendAnswer(errorCode);
- }
- void OnStarted()
- {
- m_fsm.AfterInit();
- ///**TODO(Gifur@10/21/2021): ´Ë½Ó¿ÚÓÐÎÊÌ⣬´ý²é£¡£¡£¡ */
- //m_bInitMode = m_fsm.IsInitMode();
- //Dbg("%s: %u", __FUNCTION__, m_bInitMode);
- if (!m_bInitMode) {
- CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
- spEntityFunction->SetTimer(ENT_TIMERID_CHECK_SOGOU_INPUT_INSTALLED_STATE,
- this, ENT_TIMERINTERVAL_CHECK_SOGOU_INPUT_INSTALLED_STATE);
- }
- }
- /*ignore*/
- virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- UOS::MonitorInfo info;
- info.name = "VGA-0";
- info.nResolutionX = 1280;
- info.nResolutionY = 1024;
- info.isPrimary = true;
- ConfigMonitorSetting(info);
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- /*ignore*/
- virtual void OnPreContinue(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- UOS::MonitorInfo info;
- info.name = "HDMI-A-0";
- info.nResolutionX = 1024;
- info.nResolutionY = 768;
- info.isPrimary = false;
- info.other = "VGA-0";
- info.posDirecttion = 2;
- ConfigMonitorSetting(info);
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- /*invoke fsm.onExit(), invoked when entity will be closed*/
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,
- CSmartPointer<ITransactionContext>pTransactionContext)
- {
- ErrorCodeEnum errorCode = m_fsm.OnExit();
- pTransactionContext->SendAnswer(errorCode);
- }
- virtual void OnSelfTest(EntityTestEnum eTestType,
- CSmartPointer<ITransactionContext>pTransactionContext)
- {
- m_fsm.SelfTest(eTestType, pTransactionContext);
- }
- virtual bool IsService() const
- {
- return true;
- }
- virtual bool IsMultiThread() const
- {
- return false;
- }
- void Fetch(SpReqAnsContext<ResourceWatcherService_Fetch_Req,
- ResourceWatcherService_Fetch_Ans>::Pointer ctx)
- {
- FetchEvent* evt = new FetchEvent();
- evt->ctx = ctx;
- m_fsm.PostEventFIFO(evt);
- }
- void GetDevInfo(SpReqAnsContext<ResourceWatcherService_GetDevInfo_Req,
- ResourceWatcherService_GetDevInfo_Ans>::Pointer ctx)
- {
- ctx->Answer(Error_NotImpl);
- }
- void GetCSwiperStatus(SpReqAnsContext<ResourceWatcherService_GetCardSwiper_Req,
- ResourceWatcherService_GetCardSwiper_Ans>::Pointer ctx)
- {
- ctx->Ans.status = m_fsm.GetCardSwiperVal();
- ctx->Answer(Error_Succeed);
- }
- void GetCPUType(SpReqAnsContext<ResourceWatcherService_GetCpuType_Req,
- ResourceWatcherService_GetCpuType_Ans>::Pointer ctx)
- {
- m_fsm.GetCpuType(ctx);
- }
- void OperateFile(
- SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
- ResourceWatcherService_OperateFile_Ans>::Pointer ctx)
- {
- OperateFileEvent* evt = new OperateFileEvent();
- evt->m_ctx = ctx;
- m_fsm.PostEventFIFO(evt);
- }
- void RetrieveEventLog(SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req,
- ResourceWatcherService_ExtractEventLog_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- #if defined(RVC_OS_WIN)
- m_fsm.PostEventFIFO(new GetEventLogEvent(ctx));
- #else
- ctx->Answer(Error_NotSupport);
- #endif //RVC_OS_WIN
- }
- void UpdateDNS(SpReqAnsContext<ResourceWatcherService_UpdateDNS_Req, ResourceWatcherService_UpdateDNS_Ans>::Pointer ctx);
-
- void GetNetworkInfo(SpReqAnsContext<ResourceWatcherService_GetNetworkInfo_Req, ResourceWatcherService_GetNetworkInfo_Ans>::Pointer ctx);
- void GetThirdPartyInstallState(SpReqAnsContext<ResourceWatcherService_GetThirdPartyInstallState_Req, ResourceWatcherService_GetThirdPartyInstallState_Ans>::Pointer ctx);
- void InstallThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_InstallThirdPartyProgram_Req, ResourceWatcherService_InstallThirdPartyProgram_Ans>::Pointer ctx);
- #if defined(_MSC_VER)
- SP_BEGIN_MSG_DISPATCH_MAP(ResourceWatcherEntity)
- SP_BEGIN_ENTITY_MSG("CardSwiper")
- SP_MSG_HANDLE_NS(CardSwiper, ConnectStatus, OnCardSwiperConnectStatus)
- SP_END_ENTITY_MSG()
- SP_END_MSG_DISPATCH_MAP()
- #else
- virtual void OnBroadcastEvent(CUUID SubID, const char* pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, CAutoBuffer Buffer)
- {
- }
- #endif //_MSC_VER
- private:
- void OnCardSwiperConnectStatus(const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, CardSwiper::ConnectStatus &evt)
- {
- Dbg("OnCardSwiperConnectStatus %d", evt.status);
- QueryCardSwiper cardswiperStatus;
- cardswiperStatus.status = evt.status;
- m_fsm.m_cardswiperStatus = evt.status;
- SpSendBroadcast(GetFunction(), SP_MSG_OF(QueryCardSwiper), SP_MSG_SIG_OF(QueryCardSwiper),
- cardswiperStatus);
- }
- ErrorCodeEnum DoCheckInstallStateJob();
- void DoCheckSogouProcessStatus();
- void OnTimeout(DWORD dwTimerID)
- {
- if(dwTimerID == ENT_TIMERID_CHECK_SOGOU_INPUT_INSTALLED_STATE) {
- CSimpleStringA strState;
- auto err = GetFunction()->GetSysVar("UIState",strState);
- /** 让进入首页之后才获取输入法信息 [Gifur@20211212]*/
- if(/*TRUE || */err == Error_Succeed && strState == "M") {
- Dbg("to check Sogou input install state...");
- if(Error_Succeed == DoCheckInstallStateJob()) {
- GetFunction()->KillTimer(ENT_TIMERID_CHECK_SOGOU_INPUT_INSTALLED_STATE);
- GetFunction()->SetTimer(ENT_TIMERID_CHECK_SOGOU_INPUT_PROCESS_STATUS_CHANGE,
- this, ENT_TIMERINTERVAL_CHECK_SOGOU_INPUT_PROCESS_STATUS_CHANGE);
- }
- } else {
- Dbg("Get UIState result: %s, %s", SpStrError(err), strState.GetData());
- }
- } else if (dwTimerID == ENT_TIMERID_CHECK_SOGOU_INPUT_PROCESS_STATUS_CHANGE) {
- DoCheckSogouProcessStatus();
- }
- else {
- Dbg("Unkonwn timer id: %u", dwTimerID);
- }
- }
- ErrorCodeEnum ConfigMonitorSetting(const UOS::MonitorInfo& config);
- private:
- ResourceWatcherFSM m_fsm;
- CUUID m_uiCardSwiperStatusListener;
- BOOL m_bInitMode;
- };
|