ResourceWatcherFSM.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  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_VERSION_CLEAR_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. private:
  211. void readVideoStoreData();
  212. private:
  213. BOOL m_IsPadDevice;
  214. //Cardswiper Component
  215. BOOL m_bGetStatusRotate;
  216. //Video Component
  217. CSimpleStringA m_uploadedVideoDirPath;
  218. CSimpleStringA m_csDelFileSuffix;
  219. int m_nDayOfBackward;
  220. int m_failDelCnt;
  221. bool m_bReadyFlag;
  222. //Video Component2
  223. priority_queue<TmpFileInfo*, vector<TmpFileInfo*>, Comparetor> m_VideoFiles;
  224. //日期,数量
  225. map<UINT, UINT> VideoDailyRecord;
  226. char szMaxSizeFilePath[MAX_PATH];
  227. #if defined(_MSC_VER)
  228. FILETIME m_ftRemoveTime;
  229. ULARGE_INTEGER mAllVideoFileSizeCal;
  230. ULARGE_INTEGER mMaxFileSize;
  231. ULARGE_INTEGER mUiCalibration;
  232. ULARGE_INTEGER mUiRequireBytes;
  233. FILETIME mftAd0RemoveTime;
  234. #else
  235. unsigned long long mAllVideoFileSizeCal;
  236. unsigned long long mMaxFileSize;
  237. unsigned long long mUiCalibration;
  238. unsigned long long mUiRequireBytes;
  239. time_t mftAd0RemoveTime;
  240. #endif //_MSC_VER
  241. typedef map<UINT, UINT>::const_iterator const_map_cu_iter;
  242. DiskInfo diskInfo;
  243. bool m_bVideoClearReady;
  244. int m_nMinSavedDay;
  245. //CPU Component
  246. int m_highPart;
  247. int m_lowPart;
  248. typedef std::string bs_key;
  249. typedef DWORD bs_value;
  250. typedef map<bs_key, bs_value> BLACK_LIST;
  251. typedef BLACK_LIST::const_iterator const_bs_iter;
  252. typedef BLACK_LIST::iterator bs_iter;
  253. typedef std::pair<bs_key, bs_value> BlackSheetPair;
  254. std::map<std::string, DWORD> m_forbidDirList;
  255. CSimpleStringA m_strTerminalNo;
  256. CSimpleStringA m_strDefaultDns;
  257. CSimpleStringA m_strBackupDns;
  258. int m_nEnableSetDns;
  259. FILE_LAYOUT_ENTRY m_FileEntry;
  260. BOOL m_bFirstRunAfterBoot;
  261. BOOL m_bIsConfigMode;
  262. public:
  263. int GetCardSwiperStatus();
  264. int m_cardswiperStatus;
  265. //Start Video Component [Josephus in 9:12:26 2016/4/14]
  266. int CleanVideoFiles(int& newDeletedFilesNum, int initFlag = 1);
  267. #if defined(_MSC_VER)
  268. void CalculateBackTime(PFILETIME ftResultTime, int days);
  269. BOOL CalculateWillUploadDirSize(ULARGE_INTEGER& uiBytesCal);
  270. /*
  271. *-1, First file time is earlier than second file time.
  272. * 0, First file time is equal to second file time
  273. * 1, First file time is later than second file time.
  274. */
  275. LONG CompareVideoFileTime(PFILETIME ftCurTime, PFILETIME fileTime)
  276. {
  277. return CompareFileTime(ftCurTime, fileTime);
  278. }
  279. void SyncUpdateVideoCreateDaily(const FILETIME* ft, int minusOrAdd)
  280. {
  281. SYSTEMTIME stUTC, stLocal;
  282. FileTimeToSystemTime(ft, &stUTC);
  283. SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
  284. UINT uDate = stLocal.wYear * 10000 + stLocal.wMonth * 100 + stLocal.wDay;
  285. VideoDailyRecord[uDate] += minusOrAdd;
  286. }
  287. // Start CPU Componet --Josephus at 9:05:24 2016121
  288. void InitialCPUMarkInfor();
  289. int SelectMarkLevel(int nValue)
  290. {
  291. if (m_highPart == m_lowPart && m_highPart == 0)
  292. return 0;
  293. if (m_lowPart == 0) {//no low config
  294. if (nValue >= m_highPart)
  295. return 1;
  296. else
  297. return 2;
  298. } else if (m_highPart == 0) {
  299. if (nValue > m_lowPart)
  300. return 2;
  301. else
  302. return 3;
  303. } else if (m_lowPart >= m_highPart) {//low standard.
  304. if (nValue > m_lowPart)
  305. return 2;
  306. else
  307. return 3;
  308. }
  309. if (nValue <= m_lowPart)
  310. return 3;
  311. if (nValue < m_highPart)
  312. return 2;
  313. return 1;
  314. }
  315. BOOL GetCPUBrand(CSimpleStringA& csCpuBrand);
  316. void RecordVideoFileInfomation(LPCTSTR lpFilePath, PWIN32_FIND_DATA pWfdata);
  317. int CalculateAllVideoSize(LPCTSTR lpszPath, PULARGE_INTEGER puliSpaceBytes);
  318. // Add -Josephus@2017713 16:04:18
  319. DWORD CalSpecifiedSecondsFrom1970(const WORD wDuration,
  320. DWORD* dwStartTime
  321. , DWORD* dwEndTime
  322. , const PULONGLONG pStartTime
  323. , const PULONGLONG pEndTime);
  324. DWORD CombineTheEvtxFileName(LPCTSTR lpszTerminalNo, CHAR szEvtxFileName[]);
  325. DWORD GetEventLog(SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req,
  326. ResourceWatcherService_ExtractEventLog_Ans>::Pointer ctx);
  327. BOOL RetrieveSpecificedEventLogs(const LPEVENTLOGPARAM pEvtLogFilter,
  328. LPCTSTR lpszEvtFileName, DWORD& dwEntries);
  329. HRESULT SetDefaultAudioPlaybackDevice(LPCWSTR devID);
  330. BOOL SetDefaultAudioDevice();
  331. #else
  332. LONG CompareVideoFileTime(const time_t* ftCurTime, const time_t* fileTime)
  333. {
  334. if (*ftCurTime == *fileTime) return 0;
  335. if (*ftCurTime < *fileTime) return -1;
  336. return 1;
  337. }
  338. void CalculateBackTime(time_t* ftResultTime, int days);
  339. BOOL CalculateWillUploadDirSize(unsigned long long& uiBytesCal);
  340. void SyncUpdateVideoCreateDaily(const time_t* ft, int minusOrAdd)
  341. {
  342. tm* backtime = localtime(ft);
  343. const UINT uDate = (1900 + backtime->tm_year) * 10000 + (1 + backtime->tm_mon) * 100 + backtime->tm_mday;
  344. VideoDailyRecord[uDate] += minusOrAdd;
  345. }
  346. void RecordVideoFileInfomation(LPCTSTR lpFilePath, struct stat* pWfdata);
  347. int CalculateAllVideoSize(LPCTSTR lpszPath, unsigned long long* puliSpaceBytes);
  348. #endif //_MSC_VER
  349. void AppendVideoSizeTogether();
  350. void CalculateFreeDiskNeeded();
  351. void RecordFreeDiskNeededToRunCfg();
  352. void GetFreeDiskNeededFromRunCfg();
  353. int RemoveExpireVideoFileAndRecord(LPCTSTR dirName, int& deletedFileCnt, int& deleteFailedCnt, const int nFlag);
  354. // End Video Component
  355. ErrorCodeEnum GetCpuType(
  356. SpReqAnsContext<ResourceWatcherService_GetCpuType_Req,
  357. ResourceWatcherService_GetCpuType_Ans>::Pointer ctx);
  358. // Start CenterSetting Clear Job --Josephus at 15:57:58 20161210
  359. BOOL RemoveDuplicateCenterSettingFiles();
  360. int ClearSpecifieFile(DealFileType fileType, LPCTSTR dirName, int& deletedFileCnt, int& deleteFailedCnt);
  361. int RemoveSpecifiedFile(DealFileType fileType, LPCTSTR szFilePath, LPCTSTR szFileName);
  362. // End CenterSetting clear Job
  363. // Start Video Component2 --Josephus at 16:19:56 201755
  364. void ClearVideoQueue();
  365. // Has been purified --Josephus at 10:42:55 201759
  366. void PrintVideEmurateResult();
  367. void CleanMoreVideoFiles();
  368. bool IsNeedToFirstClear();
  369. void SetSysValAndBroadcast(DWORD dwVal, LPCTSTR lpszMessage);
  370. // End --Josephus at 16:20:02 201755
  371. BOOL DeleteVersionPackage();
  372. BOOL DeleteSpecificeVersionDir(CVersion version);
  373. int ProcessFileDelete(LPCTSTR lpszPath, int& nDelSucCnt, int& nDelFailedCnt);
  374. DWORD InitialVolumes();
  375. BOOL InitialDirectoryEntity(LPCTSTR lpszPath, DWORD& dwFileCnt, const DWORD dwFilterAttributes = 0UL);
  376. DWORD ProcessFileOperation(const SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
  377. ResourceWatcherService_OperateFile_Ans>::Pointer& ctx);
  378. DWORD ExecuteFile(LPCTSTR lpszFilePath, LPCTSTR lpParam);
  379. BOOL ConveyFileEntityToContext(const SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
  380. ResourceWatcherService_OperateFile_Ans>::Pointer& ctx, BOOL bRefleshHeader = FALSE
  381. , DWORD dwFilterAttributes = 0);
  382. /*
  383. option: 0::scan, 2::delete
  384. */
  385. int FilterFilePathAhead(LPCTSTR lpszPath, const int option);
  386. void InitBlackList();
  387. BOOL InBlackListOrNot(LPCTSTR lpszPath, const int option);
  388. // Add Ad0 folder job [4/2/2018 10:53 @Gifur]
  389. BOOL ClearAd0Folder();
  390. BOOL IsTodayDone(int nRecordTime);
  391. BOOL GetSystemBootTime(CSmallDateTime& systemBootTime);
  392. BOOL DetectIsFirstRunAtBoot();
  393. /** 返回操作系统当前的版本,比如1032,1010,1031*/
  394. UINT GetSystemDisplayVersion(CSimpleStringA& strVersion);
  395. void UploadSysVersionInfo(UINT& ver);
  396. string CPUProcessStatus();
  397. string MemoryProcessStatus();
  398. void HardwareInfoTimer(void* pData);
  399. void LinkDetect(int detectType, const char* url, bool& status, uint &delay);
  400. //void MainLinkDetectTimer(void* pData);
  401. void GetMainLinkStatus();
  402. ErrorCodeEnum BizLinkDetect(
  403. SpReqAnsContext<ResourceWatcherService_BizLinkDetect_Req,
  404. ResourceWatcherService_BizLinkDetect_Ans>::Pointer ctx);
  405. ErrorCodeEnum CheckNetType(
  406. SpReqAnsContext<ResourceWatcherService_CheckNetType_Req,
  407. ResourceWatcherService_CheckNetType_Ans>::Pointer ctx);
  408. ErrorCodeEnum GetBizLinks(
  409. SpReqAnsContext<ResourceWatcherService_GetBizLinks_Req,
  410. ResourceWatcherService_GetBizLinks_Ans>::Pointer ctx);
  411. BOOL ReadCPUInfo(CPUInfo* cpu);
  412. void GetSystemCPUStatus();
  413. void GetSystemMemoryStatus();
  414. void GetSystemDiskStatus();
  415. void GetOperationDiskStatus();
  416. void GetDiskStatusFrom(LPCTSTR path);
  417. void ConfirmWindowEffectHasBeenOpen();
  418. void switchWindowsEffect(const char* cfgFilePath, bool enable);
  419. BOOL SetLocalDNSWithResolv(LPCTSTR dns1, LPCTSTR dns2);
  420. BOOL SetLocalDNSWithNetworkManager(LPCTSTR dns1, LPCTSTR dns2);
  421. BOOL SetLocalDNSWithInterfaces(LPCTSTR dns1, LPCTSTR dns2);
  422. void ConfirmDNSConfigHasSet();
  423. BOOL readDNSConfigFile(CSimpleStringA& result);
  424. /** 1032操作系统版本出现剪贴板和操作中心,需要将剪贴板关掉避免手势唤起
  425. * 统信的人告知可以通过删除剪贴板程序实现……JUST DO IT!
  426. */
  427. void ConfirmDDEClipboardDisable();
  428. void RecoverDDEClipboardEnable();
  429. /** 自己摸索,统信说需要操作系统定制方能解决 [Gifur@202198]*/
  430. void ConfirmNotificationCenterDisable();
  431. };
  432. class RunEvent : public FSMEvent
  433. {
  434. public:
  435. RunEvent() : FSMEvent(USER_EVT_RUN) {}
  436. virtual ~RunEvent() {}
  437. };
  438. class OperateFileEvent : public FSMEvent
  439. {
  440. public:
  441. OperateFileEvent()
  442. : FSMEvent(USER_EVT_FILE_OPERAT)
  443. , m_ctx(NULL)
  444. {
  445. }
  446. ~OperateFileEvent() {}
  447. SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
  448. ResourceWatcherService_OperateFile_Ans>::Pointer m_ctx;
  449. virtual void OnUnhandled()
  450. {
  451. if (m_ctx != NULL) {
  452. Dbg("Operate file event unhandled");
  453. m_ctx->Ans.result = OPT_FILE_RES_FAILED;
  454. m_ctx->Answer(Error_Succeed);
  455. }
  456. }
  457. };
  458. class GetEventLogEvent : public FSMEvent
  459. {
  460. public:
  461. GetEventLogEvent(SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req,
  462. ResourceWatcherService_ExtractEventLog_Ans>::Pointer ctx)
  463. : FSMEvent(USER_EVT_GET_EVENTLOG)
  464. , m_ctx(ctx)
  465. {
  466. }
  467. ~GetEventLogEvent() {}
  468. SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req,
  469. ResourceWatcherService_ExtractEventLog_Ans>::Pointer m_ctx;
  470. virtual void OnUnhandled()
  471. {
  472. if (m_ctx != NULL) {
  473. Dbg("get event log event unhandled");
  474. }
  475. }
  476. };
  477. struct GetCardSwiperTask : public ITaskSp
  478. {
  479. ResourceWatcherFSM* m_pFSM;
  480. GetCardSwiperTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  481. void Process()
  482. {
  483. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_GET_CARDSWIPER_STATUS_FINISHED);
  484. fsmEvent->param1 = m_pFSM->GetCardSwiperStatus();
  485. m_pFSM->PostEventFIFO(fsmEvent);
  486. }
  487. };
  488. struct ClearVideoFilesTask : public ITaskSp
  489. {
  490. ResourceWatcherFSM* m_pFSM;
  491. ClearVideoFilesTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM), m_nInitFlag(1) {}
  492. int m_nInitFlag;
  493. void SetFlag(int nFlag) { m_nInitFlag = nFlag; }
  494. void Process()
  495. {
  496. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_CLEAR_UPLOADEDVIDEOFILES_FINISHED);
  497. int value(0);
  498. fsmEvent->param2 = m_pFSM->CleanVideoFiles(value, m_nInitFlag);
  499. fsmEvent->param1 = value;
  500. m_pFSM->PostEventFIFO(fsmEvent);
  501. }
  502. };
  503. struct ClearVideoFilesEnhanceTask : public ITaskSp
  504. {
  505. ResourceWatcherFSM* m_pFSM;
  506. ClearVideoFilesEnhanceTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  507. void Process()
  508. {
  509. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_CLEAR_VIDEOFILE_ENHANCE_FINISHED);
  510. m_pFSM->CleanMoreVideoFiles();
  511. m_pFSM->PostEventFIFO(fsmEvent);
  512. }
  513. };
  514. struct ClearCenterSettingFilesTask : public ITaskSp
  515. {
  516. ResourceWatcherFSM* m_pFSM;
  517. ClearCenterSettingFilesTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  518. void Process()
  519. {
  520. m_pFSM->RemoveDuplicateCenterSettingFiles();
  521. }
  522. };
  523. struct ClearVersionTask : public ITaskSp
  524. {
  525. ResourceWatcherFSM* m_pFSM;
  526. ClearVersionTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  527. void Process()
  528. {
  529. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_VERSION_CLEAR_FINISHED);
  530. m_pFSM->DeleteVersionPackage();
  531. m_pFSM->PostEventFIFO(fsmEvent);
  532. }
  533. };
  534. struct ClearAd0Task : public ITaskSp
  535. {
  536. ResourceWatcherFSM* m_pFSM;
  537. ClearAd0Task(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM), m_nInitFlag(1) {}
  538. int m_nInitFlag;
  539. void SetFlag(int nFlag) { m_nInitFlag = nFlag; }
  540. void Process()
  541. {
  542. m_pFSM->ClearAd0Folder();
  543. }
  544. };
  545. struct RunTask : public ITaskSp
  546. {
  547. ResourceWatcherFSM* m_pFSM;
  548. RunTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM), m_nInitFlag(1) {}
  549. int m_nInitFlag;
  550. void SetFlag(int nFlag) { m_nInitFlag = nFlag; }
  551. void Process()
  552. {
  553. m_pFSM->ClearAd0Folder();
  554. m_pFSM->RemoveDuplicateCenterSettingFiles();
  555. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_CLEAR_UPLOADEDVIDEOFILES_FINISHED);
  556. int value(0);
  557. fsmEvent->param2 = m_pFSM->CleanVideoFiles(value, m_nInitFlag);
  558. fsmEvent->param1 = value;
  559. m_pFSM->PostEventFIFO(fsmEvent);
  560. }
  561. };
  562. struct OperateFileTask : public ITaskSp
  563. {
  564. ResourceWatcherFSM* m_pFSM;
  565. OperateFileTask(ResourceWatcherFSM* pFSM,
  566. SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
  567. ResourceWatcherService_OperateFile_Ans>::Pointer ctx)
  568. : m_pFSM(pFSM)
  569. , m_ctx(ctx)
  570. {
  571. }
  572. SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
  573. ResourceWatcherService_OperateFile_Ans>::Pointer m_ctx;
  574. void Process()
  575. {
  576. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_FILE_OPERAT_FINISHED);
  577. m_pFSM->ProcessFileOperation(m_ctx);
  578. m_pFSM->PostEventFIFO(fsmEvent);
  579. }
  580. };
  581. #if defined(RVC_OS_WIN)
  582. struct GetEventLogTask : public ITaskSp
  583. {
  584. ResourceWatcherFSM* m_pFSM;
  585. GetEventLogTask(ResourceWatcherFSM* pFSM,
  586. SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req,
  587. ResourceWatcherService_ExtractEventLog_Ans>::Pointer ctx)
  588. : m_pFSM(pFSM)
  589. , m_ctx(ctx)
  590. {
  591. }
  592. SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req,
  593. ResourceWatcherService_ExtractEventLog_Ans>::Pointer m_ctx;
  594. void Process()
  595. {
  596. LOG_FUNCTION();
  597. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_GET_EVENTLOG_FINISHED);
  598. m_pFSM->GetEventLog(m_ctx);
  599. fsmEvent->param1 = fsmEvent->param2 = 0;
  600. m_pFSM->PostEventFIFO(fsmEvent);
  601. }
  602. };
  603. #endif //RVC_OS_WIN
  604. class CardSwiperClient : public CardSwiperService_ClientBase
  605. {
  606. public:
  607. CardSwiperClient(CEntityBase* base) : CardSwiperService_ClientBase(base)
  608. {
  609. }
  610. };