ResourceWatcherFSM.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. #pragma once
  2. #include "stdafx.h"
  3. #include "SpFSM.h"
  4. #define JUS_A_TEST 0
  5. #include "FileInfo.h"
  6. #include <iostream>
  7. #include <iomanip>
  8. #include <fstream>
  9. #include <stdarg.h>
  10. #include <string>
  11. #include <vector>
  12. #include <assert.h>
  13. #include <time.h>
  14. #include <map>
  15. #if defined(RVC_OS_WIN)
  16. #include <ws2tcpip.h>
  17. #include <tchar.h>
  18. #include <atlbase.h>
  19. #include <conio.h>
  20. #include "mbnapi.h"
  21. #include <comdef.h>
  22. #else
  23. #include <sys/sysinfo.h>
  24. #include <time.h>
  25. #include <sys/types.h>
  26. #include <dirent.h>
  27. #include <sys/stat.h>
  28. #endif //RVC_OS_WIN
  29. using namespace std;
  30. #include "CardSwiper_client_g.h"
  31. #include "CardSwiper_msg_g.h"
  32. #include "CardSwiper_def_g.h"
  33. #include "EventCode.h"
  34. #include "FileSimpleComp.h"
  35. #include "CommEntityUtil.hpp"
  36. #define DEFAULT_INTERVAL 1000
  37. #define SYSVAR_DISKSTATEUS_FOR_VIDEO "VideoSpaceStatus" //录像磁盘空间状态系统变量
  38. #define VIDEO_SPACE_UNKNOWN "U" // 未知:未初始化或其他原因
  39. #define VIDEO_SPACE_SUFFICIENT "S" // 空间充足,3,0
  40. #define VIDEO_SPACE_INSUFF_LITTLE "W" // 低级警告:磁盘空间不足以支持七天以上录像,2
  41. #define VIDEO_SPACE_INSUFF_LESS "E" // 高级警告:磁盘空间不足以支持三天以上录像,1
  42. #define VIDEO_SPACE_INSUFF_FATAL "F" // 严重错误:磁盘空间不足以支持一天以上录像, 4
  43. #define OPT_FILE_CMD_SPREAD 0
  44. #define OPT_FILE_CMD_EXECUTE 1
  45. #define OPT_FILE_CMD_DELETE 2
  46. #define OPT_FILE_CMD_CLEAR 3
  47. #define OPT_FILE_CMD_CREATE 4
  48. #define OPT_FILE_CMD_APPEND 5
  49. #define OPT_FILE_CMD_RENAME 6
  50. #define OPT_FILE_RES_SUCCESS 1
  51. #define OPT_FILE_RES_INVALID -1
  52. #define OPT_FILE_RES_FAILED -2
  53. #define OPT_FILE_RES_NOT_SUPPORT -3
  54. #define SYSVAR_FRAMEWORK_FIRST_BOOT "FirstLaunchSinceSysBoot" //框架开机后首次启动标识
  55. #define SYSVAR_FRAMEWORK_FIRST_BOOT_YES "Y"
  56. #define SYSVAR_FRAMEWORK_FIRST_BOOT_NO "N"
  57. //Black sheet access attribute
  58. #define BS_DENY_READ 0x00000001
  59. #define BS_DENY_MODIFY 0x00000002 //Actually Append action.
  60. #define BS_DENY_EXECUTE 0x00000004
  61. #define BS_DENY_DELETE 0x00000008
  62. #define BS_DENY_CREATE 0x00000010
  63. #define BS_DENY_INHERITED 0x10000000
  64. #define BS_ACCESS_ALL ((DWORD)-1)
  65. #define LIMITED_SYS_COUNT 3
  66. static const char* limited_sys_paths[LIMITED_SYS_COUNT] =
  67. {
  68. "Program Files",
  69. "ProgramData",
  70. "Program Files (x86)"
  71. };
  72. #define LIMITED_SYS_PATH(x) \
  73. limited_sys_paths[x]
  74. class CustomSignalEvents;
  75. enum EvtType
  76. {
  77. USER_EVT_FETCH = EVT_USER + 1,
  78. USER_EVT_RUN,
  79. USER_EVT_GET_CARDSWIPER_STATUS,
  80. USER_EVT_GET_CARDSWIPER_STATUS_FINISHED,
  81. USER_EVT_CLEAR_UPLOADEDVIDEOFILES,
  82. USER_EVT_CLEAR_UPLOADEDVIDEOFILES_FINISHED,
  83. USER_EVT_CLEAR_VIDEOFILE_ENHANCE,
  84. USER_EVT_CLEAR_VIDEOFILE_ENHANCE_FINISHED,
  85. USER_EVT_VERSION_CLEAR,
  86. USER_EVT_VERSION_CLEAR_FINISHED,
  87. USER_EVT_FILE_OPERAT,
  88. USER_EVT_FILE_OPERAT_FINISHED,
  89. USER_EVT_GET_EVENTLOG,
  90. USER_EVT_GET_EVENTLOG_FINISHED
  91. };
  92. enum DealFileType
  93. {
  94. DFT_CenterSetting,
  95. DFT_Ad0
  96. };
  97. #include "ResourceWatcher_server_g.h"
  98. #include "ResourceWatcher_msg_g.h"
  99. using namespace ResourceWatcher;
  100. using namespace CardSwiper;
  101. #if defined(_MSC_VER)
  102. #define WIDE_CONDITION
  103. #ifdef WIDE_CONDITION
  104. #include "EventLogW.h"
  105. typedef CEventLogW CEventLog;
  106. typedef EVENTLOGPARAM_W EVENTLOGPARAM;
  107. typedef LPEVENTLOGPARAM_W LPEVENTLOGPARAM;
  108. #else
  109. #include "EventLog.h"
  110. #endif //WIDE_CONDITION
  111. #endif //RVC_OS_WIN
  112. class CardSwiperClient;
  113. struct CInstallInfoEx : public CInstallInfo
  114. {
  115. CInstallInfoEx(const CInstallInfo& info)
  116. :CInstallInfo(info)
  117. {/* empty */
  118. }
  119. bool operator < (const CInstallInfoEx& rhs) const
  120. {
  121. CVersion l_version(this->InstallVersion);
  122. DWORD l_timeTick = (DWORD)this->tmSwithOverDate;
  123. CVersion r_version(rhs.InstallVersion);
  124. DWORD r_timeTick = (DWORD)rhs.tmSwithOverDate;
  125. if (l_version == r_version)
  126. return l_timeTick <= r_timeTick;
  127. return l_version > r_version;
  128. }
  129. };
  130. class FetchEvent : public FSMEvent
  131. {
  132. public:
  133. FetchEvent() : FSMEvent(USER_EVT_FETCH) {}
  134. virtual ~FetchEvent() {}
  135. SpReqAnsContext<ResourceWatcherService_Fetch_Req, ResourceWatcherService_Fetch_Ans>::Pointer ctx;
  136. virtual void OnUnhandled()
  137. {
  138. if (ctx != NULL) {
  139. ctx->Answer(Error_InvalidState);
  140. }
  141. }
  142. };
  143. //chenjilin hardware change
  144. typedef struct CPUInfoStruct
  145. { // 记录 /proc/stat 中的CPU信息
  146. char name[20];
  147. unsigned int user;
  148. unsigned int nice;
  149. unsigned int system;
  150. unsigned int idle;
  151. unsigned int lowait;
  152. unsigned int irq;
  153. unsigned int softirq;
  154. }CPUInfo;
  155. typedef struct MemInfoStruct // 记录 /proc/meminfo 中的内存信息
  156. {
  157. char infoName1[20];
  158. unsigned long memTotal;
  159. char infoName2[20];
  160. unsigned long memFree;
  161. char infoName3[20];
  162. unsigned long memAvail;
  163. }MemInfo;
  164. //change end
  165. class ResourceWatcherFSM : public FSMImpl<ResourceWatcherFSM>
  166. {
  167. public:
  168. ResourceWatcherFSM(void);
  169. ~ResourceWatcherFSM(void);
  170. enum { s0, s1, s2, s3 };
  171. BEGIN_FSM_STATE(ResourceWatcherFSM)
  172. FSM_STATE_ENTRY(s0, "Idle", s0_on_entry, s0_on_exit, s0_on_event)
  173. FSM_STATE_ENTRY(s1, "Running", s1_on_entry, s1_on_exit, s1_on_event)
  174. FSM_STATE_ENTRY(s2, "Failed", s2_on_entry, s2_on_exit, s2_on_event)
  175. FSM_STATE_ENTRY(s3, "Listerning", s3_on_entry, s3_on_exit, s3_on_event)
  176. END_FSM_STATE()
  177. BEGIN_FSM_RULE(ResourceWatcherFSM, s0)
  178. FSM_RULE_ENTRY(s0, s1, USER_EVT_RUN, 0)
  179. FSM_RULE_ENTRY(s1, s3, USER_EVT_CLEAR_VIDEOFILE_ENHANCE_FINISHED, 0)
  180. END_FSM_RULE()
  181. virtual ErrorCodeEnum OnInit();
  182. virtual ErrorCodeEnum OnExit();
  183. void AfterInit();
  184. virtual void s0_on_entry();
  185. virtual void s0_on_exit();
  186. virtual unsigned int s0_on_event(FSMEvent* e);
  187. virtual void s1_on_entry();
  188. virtual void s1_on_exit();
  189. virtual unsigned int s1_on_event(FSMEvent* e);
  190. virtual void s2_on_entry();
  191. virtual void s2_on_exit();
  192. virtual unsigned int s2_on_event(FSMEvent* e);
  193. virtual void s3_on_entry();
  194. virtual void s3_on_exit();
  195. virtual unsigned int s3_on_event(FSMEvent* e);
  196. void SelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext);
  197. int GetCardSwiperVal() const
  198. {
  199. return m_cardswiperStatus;
  200. }
  201. BOOL IsFirstRunAfterBoot() const
  202. {
  203. return m_bFirstRunAfterBoot;
  204. }
  205. BOOL IsInitMode() const
  206. {
  207. Dbg("%s: %u", __FUNCTION__, m_bIsConfigMode);
  208. return m_bIsConfigMode;
  209. }
  210. void UploadMonitorSettings();
  211. private:
  212. void readVideoStoreData();
  213. private:
  214. BOOL m_IsPadDevice;
  215. //Cardswiper Component
  216. BOOL m_bGetStatusRotate;
  217. //Video Component
  218. CSimpleStringA m_uploadedVideoDirPath;
  219. CSimpleStringA m_csDelFileSuffix;
  220. int m_nDayOfBackward;
  221. int m_failDelCnt;
  222. bool m_bReadyFlag;
  223. //Video Component2
  224. priority_queue<TmpFileInfo*, vector<TmpFileInfo*>, Comparetor> m_VideoFiles;
  225. //日期,数量
  226. map<UINT, UINT> VideoDailyRecord;
  227. char szMaxSizeFilePath[MAX_PATH];
  228. #if defined(_MSC_VER)
  229. FILETIME m_ftRemoveTime;
  230. ULARGE_INTEGER mAllVideoFileSizeCal;
  231. ULARGE_INTEGER mMaxFileSize;
  232. ULARGE_INTEGER mUiCalibration;
  233. ULARGE_INTEGER mUiRequireBytes;
  234. FILETIME mftAd0RemoveTime;
  235. #else
  236. unsigned long long mAllVideoFileSizeCal;
  237. unsigned long long mMaxFileSize;
  238. unsigned long long mUiCalibration;
  239. unsigned long long mUiRequireBytes;
  240. time_t mftAd0RemoveTime;
  241. #endif //_MSC_VER
  242. typedef map<UINT, UINT>::const_iterator const_map_cu_iter;
  243. DiskInfo diskInfo;
  244. bool m_bVideoClearReady;
  245. int m_nMinSavedDay;
  246. //CPU Component
  247. int m_highPart;
  248. int m_lowPart;
  249. typedef std::string bs_key;
  250. typedef DWORD bs_value;
  251. typedef map<bs_key, bs_value> BLACK_LIST;
  252. typedef BLACK_LIST::const_iterator const_bs_iter;
  253. typedef BLACK_LIST::iterator bs_iter;
  254. typedef std::pair<bs_key, bs_value> BlackSheetPair;
  255. std::map<std::string, DWORD> m_forbidDirList;
  256. CSimpleStringA m_strTerminalNo;
  257. CSimpleStringA m_strDefaultDns;
  258. CSimpleStringA m_strBackupDns;
  259. int m_nEnableSetDns;
  260. FILE_LAYOUT_ENTRY m_FileEntry;
  261. BOOL m_bFirstRunAfterBoot;
  262. BOOL m_bIsConfigMode;
  263. public:
  264. int GetCardSwiperStatus();
  265. int m_cardswiperStatus;
  266. //Start Video Component [Josephus in 9:12:26 2016/4/14]
  267. int CleanVideoFiles(int& newDeletedFilesNum, int initFlag = 1);
  268. #if defined(_MSC_VER)
  269. void CalculateBackTime(PFILETIME ftResultTime, int days);
  270. BOOL CalculateWillUploadDirSize(ULARGE_INTEGER& uiBytesCal);
  271. /*
  272. *-1, First file time is earlier than second file time.
  273. * 0, First file time is equal to second file time
  274. * 1, First file time is later than second file time.
  275. */
  276. LONG CompareVideoFileTime(PFILETIME ftCurTime, PFILETIME fileTime)
  277. {
  278. return CompareFileTime(ftCurTime, fileTime);
  279. }
  280. void SyncUpdateVideoCreateDaily(const FILETIME* ft, int minusOrAdd)
  281. {
  282. SYSTEMTIME stUTC, stLocal;
  283. FileTimeToSystemTime(ft, &stUTC);
  284. SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
  285. UINT uDate = stLocal.wYear * 10000 + stLocal.wMonth * 100 + stLocal.wDay;
  286. VideoDailyRecord[uDate] += minusOrAdd;
  287. }
  288. // Start CPU Componet --Josephus at 9:05:24 2016121
  289. void InitialCPUMarkInfor();
  290. int SelectMarkLevel(int nValue)
  291. {
  292. if (m_highPart == m_lowPart && m_highPart == 0)
  293. return 0;
  294. if (m_lowPart == 0) {//no low config
  295. if (nValue >= m_highPart)
  296. return 1;
  297. else
  298. return 2;
  299. } else if (m_highPart == 0) {
  300. if (nValue > m_lowPart)
  301. return 2;
  302. else
  303. return 3;
  304. } else if (m_lowPart >= m_highPart) {//low standard.
  305. if (nValue > m_lowPart)
  306. return 2;
  307. else
  308. return 3;
  309. }
  310. if (nValue <= m_lowPart)
  311. return 3;
  312. if (nValue < m_highPart)
  313. return 2;
  314. return 1;
  315. }
  316. BOOL GetCPUBrand(CSimpleStringA& csCpuBrand);
  317. void RecordVideoFileInfomation(LPCTSTR lpFilePath, PWIN32_FIND_DATA pWfdata);
  318. int CalculateAllVideoSize(LPCTSTR lpszPath, PULARGE_INTEGER puliSpaceBytes);
  319. // Add -Josephus@2017713 16:04:18
  320. DWORD CalSpecifiedSecondsFrom1970(const WORD wDuration,
  321. DWORD* dwStartTime
  322. , DWORD* dwEndTime
  323. , const PULONGLONG pStartTime
  324. , const PULONGLONG pEndTime);
  325. DWORD CombineTheEvtxFileName(LPCTSTR lpszTerminalNo, CHAR szEvtxFileName[]);
  326. DWORD GetEventLog(SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req,
  327. ResourceWatcherService_ExtractEventLog_Ans>::Pointer ctx);
  328. BOOL RetrieveSpecificedEventLogs(const LPEVENTLOGPARAM pEvtLogFilter,
  329. LPCTSTR lpszEvtFileName, DWORD& dwEntries);
  330. HRESULT SetDefaultAudioPlaybackDevice(LPCWSTR devID);
  331. BOOL SetDefaultAudioDevice();
  332. #else
  333. LONG CompareVideoFileTime(const time_t* ftCurTime, const time_t* fileTime)
  334. {
  335. if (*ftCurTime == *fileTime) return 0;
  336. if (*ftCurTime < *fileTime) return -1;
  337. return 1;
  338. }
  339. void CalculateBackTime(time_t* ftResultTime, int days);
  340. BOOL CalculateWillUploadDirSize(unsigned long long& uiBytesCal);
  341. void SyncUpdateVideoCreateDaily(const time_t* ft, int minusOrAdd)
  342. {
  343. tm* backtime = localtime(ft);
  344. const UINT uDate = (1900 + backtime->tm_year) * 10000 + (1 + backtime->tm_mon) * 100 + backtime->tm_mday;
  345. VideoDailyRecord[uDate] += minusOrAdd;
  346. }
  347. void RecordVideoFileInfomation(LPCTSTR lpFilePath, struct stat* pWfdata);
  348. int CalculateAllVideoSize(LPCTSTR lpszPath, unsigned long long* puliSpaceBytes);
  349. #endif //_MSC_VER
  350. void AppendVideoSizeTogether();
  351. void CalculateFreeDiskNeeded();
  352. void RecordFreeDiskNeededToRunCfg();
  353. void GetFreeDiskNeededFromRunCfg();
  354. int RemoveExpireVideoFileAndRecord(LPCTSTR dirName, int& deletedFileCnt, int& deleteFailedCnt, const int nFlag);
  355. // End Video Component
  356. ErrorCodeEnum GetCpuType(
  357. SpReqAnsContext<ResourceWatcherService_GetCpuType_Req,
  358. ResourceWatcherService_GetCpuType_Ans>::Pointer ctx);
  359. // Start CenterSetting Clear Job --Josephus at 15:57:58 20161210
  360. BOOL RemoveDuplicateCenterSettingFiles();
  361. int ClearSpecifieFile(DealFileType fileType, LPCTSTR dirName, int& deletedFileCnt, int& deleteFailedCnt);
  362. int RemoveSpecifiedFile(DealFileType fileType, LPCTSTR szFilePath, LPCTSTR szFileName);
  363. // End CenterSetting clear Job
  364. // Start Video Component2 --Josephus at 16:19:56 201755
  365. void ClearVideoQueue();
  366. // Has been purified --Josephus at 10:42:55 201759
  367. void PrintVideEmurateResult();
  368. void CleanMoreVideoFiles();
  369. bool IsNeedToFirstClear();
  370. void SetSysValAndBroadcast(DWORD dwVal, LPCTSTR lpszMessage);
  371. // End --Josephus at 16:20:02 201755
  372. BOOL DeleteVersionPackage();
  373. BOOL DeleteSpecificeVersionDir(CVersion version);
  374. int ProcessFileDelete(LPCTSTR lpszPath, int& nDelSucCnt, int& nDelFailedCnt);
  375. DWORD InitialVolumes();
  376. BOOL InitialDirectoryEntity(LPCTSTR lpszPath, DWORD& dwFileCnt, const DWORD dwFilterAttributes = 0UL);
  377. DWORD ProcessFileOperation(const SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
  378. ResourceWatcherService_OperateFile_Ans>::Pointer& ctx);
  379. DWORD ExecuteFile(LPCTSTR lpszFilePath, LPCTSTR lpParam);
  380. BOOL ConveyFileEntityToContext(const SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
  381. ResourceWatcherService_OperateFile_Ans>::Pointer& ctx, BOOL bRefleshHeader = FALSE
  382. , DWORD dwFilterAttributes = 0);
  383. /*
  384. option: 0::scan, 2::delete
  385. */
  386. int FilterFilePathAhead(LPCTSTR lpszPath, const int option);
  387. void InitBlackList();
  388. BOOL InBlackListOrNot(LPCTSTR lpszPath, const int option);
  389. // Add Ad0 folder job [4/2/2018 10:53 @Gifur]
  390. BOOL ClearAd0Folder();
  391. BOOL IsTodayDone(int nRecordTime);
  392. BOOL GetSystemBootTime(CSmallDateTime& systemBootTime);
  393. BOOL DetectIsFirstRunAtBoot();
  394. /** 返回操作系统当前的版本,比如1032,1010,1031*/
  395. UINT GetSystemDisplayVersion(CSimpleStringA& strVersion);
  396. void UploadSysVersionInfo(UINT& ver);
  397. string CPUProcessStatus();
  398. string MemoryProcessStatus();
  399. void HardwareInfoTimer(void* pData);
  400. void LinkDetect(int detectType, const char* url, bool& status, uint &delay);
  401. //void MainLinkDetectTimer(void* pData);
  402. void GetMainLinkStatus();
  403. ErrorCodeEnum BizLinkDetect(
  404. SpReqAnsContext<ResourceWatcherService_BizLinkDetect_Req,
  405. ResourceWatcherService_BizLinkDetect_Ans>::Pointer ctx);
  406. ErrorCodeEnum CheckNetType(
  407. SpReqAnsContext<ResourceWatcherService_CheckNetType_Req,
  408. ResourceWatcherService_CheckNetType_Ans>::Pointer ctx);
  409. ErrorCodeEnum GetBizLinks(
  410. SpReqAnsContext<ResourceWatcherService_GetBizLinks_Req,
  411. ResourceWatcherService_GetBizLinks_Ans>::Pointer ctx);
  412. BOOL ReadCPUInfo(CPUInfo* cpu);
  413. void GetSystemCPUStatus();
  414. void GetSystemMemoryStatus();
  415. void GetSystemDiskStatus();
  416. void GetOperationDiskStatus();
  417. void GetDiskStatusFrom(LPCTSTR path);
  418. void ConfirmWindowEffectHasBeenOpen();
  419. void switchWindowsEffect(const char* cfgFilePath, bool enable);
  420. BOOL SetLocalDNSWithResolv(LPCTSTR dns1, LPCTSTR dns2);
  421. BOOL SetLocalDNSWithNetworkManager(LPCTSTR dns1, LPCTSTR dns2);
  422. BOOL SetLocalDNSWithInterfaces(LPCTSTR dns1, LPCTSTR dns2);
  423. void ConfirmDNSConfigHasSet();
  424. BOOL readDNSConfigFile(CSimpleStringA& result);
  425. /** 1032操作系统版本出现剪贴板和操作中心,需要将剪贴板关掉避免手势唤起
  426. * 统信的人告知可以通过删除剪贴板程序实现……JUST DO IT!
  427. */
  428. void ConfirmDDEClipboardDisable();
  429. void RecoverDDEClipboardEnable();
  430. /** 自己摸索,统信说需要操作系统定制方能解决 [Gifur@202198]*/
  431. void ConfirmNotificationCenterDisable();
  432. };
  433. class RunEvent : public FSMEvent
  434. {
  435. public:
  436. RunEvent() : FSMEvent(USER_EVT_RUN) {}
  437. virtual ~RunEvent() {}
  438. };
  439. class OperateFileEvent : public FSMEvent
  440. {
  441. public:
  442. OperateFileEvent()
  443. : FSMEvent(USER_EVT_FILE_OPERAT)
  444. , m_ctx(NULL)
  445. {
  446. }
  447. ~OperateFileEvent() {}
  448. SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
  449. ResourceWatcherService_OperateFile_Ans>::Pointer m_ctx;
  450. virtual void OnUnhandled()
  451. {
  452. if (m_ctx != NULL) {
  453. Dbg("Operate file event unhandled");
  454. m_ctx->Ans.result = OPT_FILE_RES_FAILED;
  455. m_ctx->Answer(Error_Succeed);
  456. }
  457. }
  458. };
  459. class GetEventLogEvent : public FSMEvent
  460. {
  461. public:
  462. GetEventLogEvent(SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req,
  463. ResourceWatcherService_ExtractEventLog_Ans>::Pointer ctx)
  464. : FSMEvent(USER_EVT_GET_EVENTLOG)
  465. , m_ctx(ctx)
  466. {
  467. }
  468. ~GetEventLogEvent() {}
  469. SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req,
  470. ResourceWatcherService_ExtractEventLog_Ans>::Pointer m_ctx;
  471. virtual void OnUnhandled()
  472. {
  473. if (m_ctx != NULL) {
  474. Dbg("get event log event unhandled");
  475. }
  476. }
  477. };
  478. struct GetCardSwiperTask : public ITaskSp
  479. {
  480. ResourceWatcherFSM* m_pFSM;
  481. GetCardSwiperTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  482. void Process()
  483. {
  484. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_GET_CARDSWIPER_STATUS_FINISHED);
  485. fsmEvent->param1 = m_pFSM->GetCardSwiperStatus();
  486. m_pFSM->PostEventFIFO(fsmEvent);
  487. }
  488. };
  489. struct ClearVideoFilesTask : public ITaskSp
  490. {
  491. ResourceWatcherFSM* m_pFSM;
  492. ClearVideoFilesTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM), m_nInitFlag(1) {}
  493. int m_nInitFlag;
  494. void SetFlag(int nFlag) { m_nInitFlag = nFlag; }
  495. void Process()
  496. {
  497. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_CLEAR_UPLOADEDVIDEOFILES_FINISHED);
  498. int value(0);
  499. fsmEvent->param2 = m_pFSM->CleanVideoFiles(value, m_nInitFlag);
  500. fsmEvent->param1 = value;
  501. m_pFSM->PostEventFIFO(fsmEvent);
  502. }
  503. };
  504. struct ClearVideoFilesEnhanceTask : public ITaskSp
  505. {
  506. ResourceWatcherFSM* m_pFSM;
  507. ClearVideoFilesEnhanceTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  508. void Process()
  509. {
  510. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_CLEAR_VIDEOFILE_ENHANCE_FINISHED);
  511. m_pFSM->CleanMoreVideoFiles();
  512. m_pFSM->PostEventFIFO(fsmEvent);
  513. }
  514. };
  515. struct ClearCenterSettingFilesTask : public ITaskSp
  516. {
  517. ResourceWatcherFSM* m_pFSM;
  518. ClearCenterSettingFilesTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  519. void Process()
  520. {
  521. m_pFSM->RemoveDuplicateCenterSettingFiles();
  522. }
  523. };
  524. struct ClearVersionTask : public ITaskSp
  525. {
  526. ResourceWatcherFSM* m_pFSM;
  527. ClearVersionTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  528. void Process()
  529. {
  530. m_pFSM->DeleteVersionPackage();
  531. }
  532. };
  533. struct UploadMonitorInfoTask : public ITaskSp
  534. {
  535. ResourceWatcherFSM* m_pFSM;
  536. UploadMonitorInfoTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  537. void Process()
  538. {
  539. m_pFSM->UploadMonitorSettings();
  540. }
  541. };
  542. struct ClearAd0Task : public ITaskSp
  543. {
  544. ResourceWatcherFSM* m_pFSM;
  545. ClearAd0Task(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM), m_nInitFlag(1) {}
  546. int m_nInitFlag;
  547. void SetFlag(int nFlag) { m_nInitFlag = nFlag; }
  548. void Process()
  549. {
  550. m_pFSM->ClearAd0Folder();
  551. }
  552. };
  553. struct RunTask : public ITaskSp
  554. {
  555. ResourceWatcherFSM* m_pFSM;
  556. RunTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM), m_nInitFlag(1) {}
  557. int m_nInitFlag;
  558. void SetFlag(int nFlag) { m_nInitFlag = nFlag; }
  559. void Process()
  560. {
  561. m_pFSM->ClearAd0Folder();
  562. m_pFSM->RemoveDuplicateCenterSettingFiles();
  563. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_CLEAR_UPLOADEDVIDEOFILES_FINISHED);
  564. int value(0);
  565. fsmEvent->param2 = m_pFSM->CleanVideoFiles(value, m_nInitFlag);
  566. fsmEvent->param1 = value;
  567. m_pFSM->PostEventFIFO(fsmEvent);
  568. }
  569. };
  570. struct OperateFileTask : public ITaskSp
  571. {
  572. ResourceWatcherFSM* m_pFSM;
  573. OperateFileTask(ResourceWatcherFSM* pFSM,
  574. SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
  575. ResourceWatcherService_OperateFile_Ans>::Pointer ctx)
  576. : m_pFSM(pFSM)
  577. , m_ctx(ctx)
  578. {
  579. }
  580. SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
  581. ResourceWatcherService_OperateFile_Ans>::Pointer m_ctx;
  582. void Process()
  583. {
  584. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_FILE_OPERAT_FINISHED);
  585. m_pFSM->ProcessFileOperation(m_ctx);
  586. m_pFSM->PostEventFIFO(fsmEvent);
  587. }
  588. };
  589. #if defined(RVC_OS_WIN)
  590. struct GetEventLogTask : public ITaskSp
  591. {
  592. ResourceWatcherFSM* m_pFSM;
  593. GetEventLogTask(ResourceWatcherFSM* pFSM,
  594. SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req,
  595. ResourceWatcherService_ExtractEventLog_Ans>::Pointer ctx)
  596. : m_pFSM(pFSM)
  597. , m_ctx(ctx)
  598. {
  599. }
  600. SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req,
  601. ResourceWatcherService_ExtractEventLog_Ans>::Pointer m_ctx;
  602. void Process()
  603. {
  604. LOG_FUNCTION();
  605. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_GET_EVENTLOG_FINISHED);
  606. m_pFSM->GetEventLog(m_ctx);
  607. fsmEvent->param1 = fsmEvent->param2 = 0;
  608. m_pFSM->PostEventFIFO(fsmEvent);
  609. }
  610. };
  611. #endif //RVC_OS_WIN
  612. class CardSwiperClient : public CardSwiperService_ClientBase
  613. {
  614. public:
  615. CardSwiperClient(CEntityBase* base) : CardSwiperService_ClientBase(base)
  616. {
  617. }
  618. };