mod_healthmanager.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. #ifndef __MOD_HEALTHMANAGER_H
  2. #define __MOD_HEALTHMANAGER_H
  3. #include <map>
  4. #include "SpBase.h"
  5. #include "modVer.h"
  6. #include "SpTest.h"
  7. #include "HealthManagerFSM.h"
  8. #include "EventCode.h"
  9. #include "HealthManager_server_g.h"
  10. using namespace HealthManager;
  11. #include "WatchDog_client_g.h"
  12. #include "Ups_client_g.h"
  13. #include "UpsClass.h"
  14. #include "InteractionContext_client_g.h"
  15. #include "UpgradeManager_client_g.h"
  16. #include "CardSwiper_client_g.h"
  17. using namespace std;
  18. using namespace WatchDog;
  19. using namespace Ups;
  20. using namespace InteractionContext;
  21. using namespace UpgradeManager;
  22. using namespace CardSwiper;
  23. #include "GuardianBase.h"
  24. typedef int (*pfShakeHands)(WorkStateEnum &eState);
  25. typedef int (*pfPushUpdateTask)(const char *pszPackName);
  26. typedef bool (*pfIsInstalling)();
  27. typedef int (*pfUpgradeRestart)(const DWORD dwParam1,const DWORD dwParam2);
  28. typedef int (*pfFrameworkQuit)(RebootTriggerEnum eReason);
  29. #define DEPLOYSTATE_NOTINIT 0
  30. #define DEPLOYSTATE_DONE 1
  31. #define DEPLOYSTATE_FAILED 2
  32. enum WatchDogOp
  33. {
  34. WD_OP_START,
  35. WD_OP_STOP,
  36. WD_OP_REFRESH
  37. };
  38. enum ModuleReMode
  39. {
  40. RESTART_MODE_DEFAULT,
  41. RESTART_MODE_LOW,
  42. RESTART_MODE_HIGH,
  43. };
  44. enum DealType
  45. {
  46. Deal_Start = 1,
  47. Deal_Close,
  48. Deal_Pause,
  49. Deal_Continue,
  50. Deal_Kill,
  51. Deal_Test,
  52. Deal_Restart
  53. };
  54. struct ModuleRunInfo
  55. {
  56. DWORD dwStart;
  57. int count;
  58. };
  59. struct RestartModeInfo
  60. {
  61. DWORD dwTimes;
  62. DWORD dwInternal;
  63. };
  64. typedef CAutoArray<CSimpleStringA> NetworkAddressesList;
  65. #define MACSESION 6
  66. #include <winpr/sysinfo.h>
  67. static void GetLocalTimeRVC(SYSTEMTIME& stTime)
  68. {
  69. GetLocalTime(&stTime);
  70. }
  71. class HealthManagerSession : public HealthManagerService_ServerSessionBase
  72. {
  73. public:
  74. HealthManagerSession(CHealthManagerEntity *pEntity):m_pEntity(pEntity){}
  75. virtual ~HealthManagerSession(){}
  76. virtual void Handle_EnterState(SpReqAnsContext<HealthManagerService_EnterState_Req, HealthManagerService_EnterState_Ans>::Pointer ctx);
  77. virtual void Handle_ExitState(SpReqAnsContext<HealthManagerService_ExitState_Req, HealthManagerService_ExitState_Ans>::Pointer ctx);
  78. virtual void Handle_DoEvent(SpReqAnsContext<HealthManagerService_DoEvent_Req, HealthManagerService_DoEvent_Ans>::Pointer ctx);
  79. virtual void Handle_GetEntityCfgInfo(SpReqAnsContext<HealthManagerService_GetEntityCfgInfo_Req, HealthManagerService_GetEntityCfgInfo_Ans>::Pointer ctx);
  80. virtual void Handle_GetNetworkState(SpReqAnsContext<HealthManagerService_GetNetworkState_Req, HealthManagerService_GetNetworkState_Ans>::Pointer ctx);
  81. virtual void Handle_QueryHardwareInfo(SpReqAnsContext<HealthManagerService_QueryHardwareInfo_Req, HealthManagerService_QueryHardwareInfo_Ans>::Pointer ctx);
  82. virtual void Handle_ReadCenterConfigStr(SpReqAnsContext<HealthManagerService_ReadCenterConfigStr_Req, HealthManagerService_ReadCenterConfigStr_Ans>::Pointer ctx);
  83. virtual void Handle_ControlTerminalLife(SpReqAnsContext<HealthManagerService_ControlTerminalLife_Req, HealthManagerService_ControlTerminalLife_Ans>::Pointer ctx);
  84. virtual void Handle_DeployTerminal(SpReqAnsContext<HealthManagerService_DeployTerminal_Req, HealthManagerService_DeployTerminal_Ans>::Pointer ctx);
  85. virtual void Handle_ControlEntityLife(SpReqAnsContext<HealthManagerService_ControlEntityLife_Req, HealthManagerService_ControlEntityLife_Ans>::Pointer ctx);
  86. private:
  87. CHealthManagerEntity *m_pEntity;
  88. };
  89. class CHealthManagerEntity : public CEntityBase, public ILogListener, public ISysVarListener, public IBroadcastListener
  90. {
  91. public:
  92. CHealthManagerEntity() :m_bInit(true), m_pWatchDogClient(NULL), m_bWatchDog(false), m_pUpsClient(NULL)
  93. , m_pSync(NULL), xxx(0), m_MCStart(0), m_bWaitRestartPC(false)
  94. , m_upsStateCount(0), m_bUpsWaitLock(false), m_bScreenLock(false), m_bToRestart(false)
  95. , m_upsNoElectorCount(0), m_bSayIdle(false), m_bGuardianRun(false), m_bHealthInit(false), m_pUpgMgr(NULL)
  96. , m_bVerRollback(false), m_eRebootTrigger(RebootTrigger_Unknown), m_eRebootWay(RebootWay_Unknown)
  97. , m_bGetUpsStateFlag(false), m_menuChoice(""), m_menuPre(""), m_netState("N"), m_bFisrtEnterMainPage(true)
  98. , m_bNeedToRestartPAD(false), m_preDay(99), m_bNeedToRestartIE(false), m_bInMainPage(false), m_maxRunDays(7)
  99. , m_bEnterMainPageEver(false), m_connectStatus(0), m_bAccessSuc(false), m_pfShake(NULL),m_pfUpgradeRestart(NULL){}
  100. virtual ~CHealthManagerEntity() {}
  101. virtual const char *GetEntityName() const { return "HealthManager"; }
  102. const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
  103. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  104. {
  105. ErrorCodeEnum eErrCode(Error_Succeed);
  106. int curStep(0);
  107. bool isNeedConfig = IsNotConfigMode(curStep);
  108. if (isNeedConfig) {
  109. m_fsm.SetConfigMode(true);
  110. } else {
  111. DoRestart();
  112. }
  113. eErrCode = m_fsm.Init(this);
  114. GetFunction()->SubscribeLog(m_uuidUpdate,this,Log_Event,Severity_Middle,Error_IgnoreAll,-1,"UpgradeManager");
  115. GetFunction()->SubscribeLog(m_uuidAccessAuth,this,Log_Event,Severity_Middle,Error_IgnoreAll,-1,"AccessAuthorization");
  116. GetFunction()->SubscribeLog(m_uuidAccessAuth,this,Log_Error,Severity_Middle,Error_IgnoreAll,-1,"AccessAuthorization");
  117. GetFunction()->SubscribeLog(m_uuidInitializer,this,Log_Event,Severity_Middle,Error_IgnoreAll,-1,"Initializer");
  118. GetFunction()->SubscribeLog(m_uuidInitializer,this,Log_Error,Severity_Middle,Error_IgnoreAll,-1,"Initializer");
  119. GetFunction()->SubscribeLog(m_uuidFaceTracking,this,Log_Error,Severity_High,Error_IgnoreAll,-1,"FaceTracking");
  120. GetFunction()->SubscribeLog(m_uuidMediaController,this,Log_Error,Severity_High,Error_IgnoreAll,-1,"MediaController");
  121. GetFunction()->SubscribeLog(m_uuidSelfChecker,this,Log_Event,Severity_Middle,Error_IgnoreAll,-1,"SelfChecker");
  122. GetFunction()->SubscribeLog(m_uuidRemoteController,this,Log_Event,Severity_Middle,Error_IgnoreAll,-1,"RemoteController");
  123. GetFunction()->SubscribeLog(m_uuidGUIConsole,this,Log_Event,Severity_Middle,Error_IgnoreAll,-1,"GUIConsole");
  124. GetFunction()->SubscribeLog(m_uuidHeartBeat,this,Log_Event,Severity_Middle,Error_IgnoreAll,-1,"HeartBeat",false);
  125. GetFunction()->SubscribeLog(m_uuidCenterS, this, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "CenterSetting");
  126. GetFunction()->SubscribeLog(m_uuidPublic, this, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "Chromium");
  127. GetFunction()->RegistSysVarEvent("UIState", this);
  128. //UpgradeManager
  129. #if defined(RVC_OS_WIN)
  130. GetFunction()->SubscribeLog(m_uuidMaintainWatch, this, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "MaintainWatcher");
  131. GetFunction()->SubscribeLog(m_uuidIE, this, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "IEBrowser");
  132. GetFunction()->SubscribeLog(m_uuidCardSwiper, this, Log_Error, Severity_Middle, Error_IgnoreAll, -1, "CardSwiper");
  133. GetFunction()->SubscribeLog(m_uuidPublic, this, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "systemcustomization");
  134. GetFunction()->SubscribeBroadcast("CardSwiper", "", this, m_uuidCardSwiper);
  135. #endif //RVC_OS_WIN
  136. pTransactionContext->SendAnswer(eErrCode) ;
  137. }
  138. void OnStarted() override;
  139. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  140. {
  141. pTransactionContext->SendAnswer(Error_Succeed);
  142. }
  143. void EnterState(SpReqAnsContext<HealthManagerService_EnterState_Req, HealthManagerService_EnterState_Ans>::Pointer ctx)
  144. {
  145. if (ctx->Req.state == "M")
  146. {
  147. FSMEvent *pEvt = new FSMEvent(USER_EVT_MAITAIN);
  148. m_fsm.PostEventFIFO(pEvt);
  149. }
  150. ctx->Answer(Error_Succeed);
  151. }
  152. void ExitState(SpReqAnsContext<HealthManagerService_ExitState_Req, HealthManagerService_ExitState_Ans>::Pointer ctx)
  153. {
  154. if (ctx->Req.state == "M")
  155. {
  156. FSMEvent *pEvt = new FSMEvent(USER_EVT_MAITAIN_FINISHED);
  157. m_fsm.PostEventFIFO(pEvt);
  158. }
  159. ctx->Answer(Error_Succeed);
  160. }
  161. void DoEvent(SpReqAnsContext<HealthManagerService_DoEvent_Req, HealthManagerService_DoEvent_Ans>::Pointer ctx)
  162. {
  163. }
  164. void GetEntityCfgInfo(SpReqAnsContext<HealthManagerService_GetEntityCfgInfo_Req, HealthManagerService_GetEntityCfgInfo_Ans>::Pointer ctx)
  165. {
  166. ctx->Ans.reserved2 = m_fsm.GetEntityCfgInfo(ctx->Req.name,ctx->Ans.loadOpt);
  167. ctx->Answer(Error_Succeed);
  168. }
  169. void GetNetworkState(SpReqAnsContext<HealthManagerService_GetNetworkState_Req, HealthManagerService_GetNetworkState_Ans>::Pointer ctx)
  170. {
  171. ctx->Ans.netDeviceState = m_netState;
  172. ctx->Ans.reserved1 = m_fsm.QueryAccessAuthStatus();
  173. Dbg("current net state %s,auth state:%d", (LPCTSTR)m_netState, ctx->Ans.reserved1);
  174. ctx->Answer(Error_Succeed);
  175. }
  176. virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszParam*/)
  177. {
  178. return new HealthManagerSession(this);
  179. }
  180. virtual bool IsService()const{return true;}
  181. virtual bool IsMultiThread()const{return true;}
  182. bool DoWatchDog(WatchDogOp eOp);
  183. int SystemRestart(bool bPeriod,bool bUpsImmediately,bool bNow=false);
  184. int SystemShutdown(BOOL bReboot=FALSE);
  185. ErrorCodeEnum SystemShutdownThroughUPS(DWORD msPreShutdown = 5, DWORD msPreRestart = 5);
  186. int FrameworkShutdown(bool bRestart=true);
  187. int GetNetDeviceState();
  188. int UpdateSiteChangeFlag();
  189. int UpdateSiteToRuncfg(bool bWriteSite=true,bool bClearSiteFlag = false);
  190. int WriteSiteToRootIni();
  191. void QueryHardwareInfo(SpReqAnsContext<HealthManagerService_QueryHardwareInfo_Req, HealthManagerService_QueryHardwareInfo_Ans>::Pointer ctx);
  192. void ReadCenterConfigStr(SpReqAnsContext<HealthManagerService_ReadCenterConfigStr_Req, HealthManagerService_ReadCenterConfigStr_Ans>::Pointer ctx);
  193. void ControlTerminalLife(SpReqAnsContext<HealthManagerService_ControlTerminalLife_Req, HealthManagerService_ControlTerminalLife_Ans>::Pointer ctx);
  194. void ControlEntityLife(SpReqAnsContext<HealthManagerService_ControlEntityLife_Req, HealthManagerService_ControlEntityLife_Ans>::Pointer ctx);
  195. virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  196. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  197. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage);
  198. virtual void OnSysVarEvent(const char *pszKey,
  199. const char *pszValue, const char *pszOldValue, const char *pszEntityName);
  200. virtual void OnBroadcastEvent(CUUID SubID, const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, CAutoBuffer Buffer);
  201. void DeployTerminal(SpReqAnsContext<HealthManagerService_DeployTerminal_Req, HealthManagerService_DeployTerminal_Ans>::Pointer ctx);
  202. /*!
  203. * @brief 判断是否为未配置模式
  204. * @param[out] 如果为未配置模式,stepMode 等于 0 为从头开始配置,其他为阶段性配置,详情见 DeployStep_* 定义
  205. * @return : true: 为未配置模式,false:正常模式
  206. */
  207. bool IsNotConfigMode(int& stepMode);
  208. private:
  209. CHealthManagerFSM m_fsm;
  210. //the following is useless?just one var is ok? oiltmp
  211. CUUID m_uuidUpdate,m_uuidMediaController,m_uuidFaceTracking,m_uuidAccessAuth,m_uuidInitializer,m_uuidSelfChecker
  212. , m_uuidRemoteController, m_uuidGUIConsole, m_uuidHeartBeat, m_uuidMaintainWatch, m_uuidIE, m_uuidCenterS;
  213. CUUID m_uuidCardSwiper,m_uuidPublic;
  214. int m_devCfgNum,m_connectStatus;
  215. int m_restartHour, m_restartMinute, m_lastHour, m_restartTimes, m_maxRestartTimes, m_preDay, m_dayNum, m_maxRunDays;
  216. bool m_bInit,m_bWatchDog,m_bWaitRestartPC,m_bUpsWaitLock,m_bScreenLock,m_bToRestart,m_testFlag,m_bSayIdle
  217. , m_bGuardianRun, m_bHealthInit, m_bVerRollback, m_bFisrtEnterMainPage, m_bNeedToRestartPAD,m_bNeedToRestartIE
  218. , m_bInMainPage, m_bEnterMainPageEver,m_bAccessSuc;
  219. DWORD m_wDayOfWeek,m_MCStart,m_MCEnd;
  220. int xxx,m_upsStateCount,m_upsNoElectorCount;
  221. RebootTriggerEnum m_eRebootTrigger;
  222. RebootWayEnum m_eRebootWay;
  223. CSimpleStringA m_menuChoice,m_currentVer,m_menuPre,m_netState;
  224. map<CSimpleStringA,ModuleRunInfo> m_modRunInfo;
  225. map<CSimpleStringA,ModuleReMode> m_modCfgInfo;
  226. map<ModuleReMode,RestartModeInfo> m_restartMode;
  227. WatchDogService_ClientBase *m_pWatchDogClient;
  228. UpsService_ClientBase *m_pUpsClient;
  229. SyncService_ClientBase *m_pSync;
  230. UpgradeMgrService_ClientBase *m_pUpgMgr;
  231. pfShakeHands m_pfShake;
  232. pfUpgradeRestart m_pfUpgradeRestart;
  233. bool m_bGetUpsStateFlag;
  234. CSystemStaticInfo m_sysStaticInfo;
  235. /** 启动限制配置读取以及监护模块初始化*/
  236. bool DoRestart();
  237. void OnCheckTimeTimeout();
  238. void OnWatchDogTimeout();
  239. ErrorCodeEnum RestartModule(const char* pEntityName);
  240. void AfterWaitRestartPC();
  241. void UpsSupplyLockScreen();
  242. int ConnectUps();
  243. void SplitModuleNames(CSimpleStringA csLine,ModuleReMode eMode);
  244. bool SaveCurrentVersion();
  245. bool SaveFrameStartTimeForUpgrade();
  246. bool CheckGuardianIsRun(bool bStart=false);
  247. bool StopGuardian();
  248. bool StartGuardian();
  249. bool VersionRollBack(const char *pVerion);
  250. //int QuitFrameworkAndSaveInfo(RebootTriggerEnum eTrigger = RebootTrigger_Unknown,RebootWayEnum eWay = RebootWay_Unknown);
  251. void ReadMachineDataBySyncSerivce();
  252. int RestartIE();
  253. void GetINETMacAddresses(NetworkAddressesList &macList, NetworkAddressesList &ipList);
  254. CSimpleStringA __ReadCenterConfigStr(CSimpleStringA key, CSimpleStringA entityName);
  255. bool IsTestMode();
  256. ErrorCodeEnum GetTmpRootFilePath(CSimpleStringA& rootPath, CSimpleStringA& rootTmpPath);
  257. ErrorCodeEnum GetGuidePageUrlWithStep(int whichStep, CSimpleStringA& strUrl);
  258. ErrorCodeEnum TellChromiumOpenGuidePage(const CSimpleStringA& pageUrl);
  259. ErrorCodeEnum DealSpecifiedEntity(DealType type, LPCTSTR lpcszEntityName, LPCTSTR lpcszCmdline, bool bForce, CSimpleStringA& strErrMsg);
  260. };
  261. #endif // __MOD_HEALTHMANAGER_H