ResourceWatcherFSM.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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 <ws2tcpip.h>
  10. #include <tchar.h>
  11. #include <stdarg.h>
  12. #include <string>
  13. #include <vector>
  14. #include <assert.h>
  15. #include <time.h>
  16. #include <map>
  17. #include <atlbase.h>
  18. #include <conio.h>
  19. #include "mbnapi.h"
  20. #include <comdef.h>
  21. using namespace std;
  22. #pragma comment(lib, "ws2_32.lib")
  23. #pragma comment(lib, "mbnapi_uuid.lib")
  24. #include "../mod_cardswiper/CardSwiper_client_g.h"
  25. #include "../mod_cardswiper/CardSwiper_msg_g.h"
  26. #include "../mod_cardswiper/CardSwiper_def_g.h"
  27. #include "../EventCode.h"
  28. #include "FileSimpleComp.h"
  29. #define DEFAULT_INTERVAL 1000
  30. #define SYSVAR_DISKSTATEUS_FOR_VIDEO "VideoSpaceStatus" //录像磁盘空间状态系统变量
  31. #define VIDEO_SPACE_UNKNOWN "U" // 未知:未初始化或其他原因
  32. #define VIDEO_SPACE_SUFFICIENT "S" // 空间充足
  33. #define VIDEO_SPACE_INSUFF_LITTLE "W" // 低级警告:磁盘空间不足以支持七天以上录像
  34. #define VIDEO_SPACE_INSUFF_LESS "E" // 高级警告:磁盘空间不足以支持三天以上录像
  35. #define VIDEO_SPACE_INSUFF_FATAL "F" // 严重错误:磁盘空间不足以支持一天以上录像
  36. #define OPT_FILE_CMD_SPREAD 0
  37. #define OPT_FILE_CMD_EXECUTE 1
  38. #define OPT_FILE_CMD_DELETE 2
  39. #define OPT_FILE_CMD_CLEAR 3
  40. #define OPT_FILE_CMD_CREATE 4
  41. #define OPT_FILE_CMD_APPEND 5
  42. #define OPT_FILE_CMD_RENAME 6
  43. #define OPT_FILE_RES_SUCCESS 1
  44. #define OPT_FILE_RES_INVALID -1
  45. #define OPT_FILE_RES_FAILED -2
  46. #define SYSVAR_FRAMEWORK_FIRST_BOOT "FirstLaunchSinceSysBoot" //框架开机后首次启动标识
  47. #define SYSVAR_FRAMEWORK_FIRST_BOOT_YES "Y"
  48. #define SYSVAR_FRAMEWORK_FIRST_BOOT_NO "N"
  49. //Black sheet access attribute
  50. #define BS_DENY_READ 0x00000001
  51. #define BS_DENY_MODIFY 0x00000002 //Actually Append action.
  52. #define BS_DENY_EXECUTE 0x00000004
  53. #define BS_DENY_DELETE 0x00000008
  54. #define BS_DENY_CREATE 0x00000010
  55. #define BS_DENY_INHERITED 0x10000000
  56. #define BS_ACCESS_ALL ((DWORD)-1)
  57. #define LIMITED_SYS_COUNT 3
  58. static const char* limited_sys_paths[LIMITED_SYS_COUNT] =
  59. {
  60. "Program Files",
  61. "ProgramData",
  62. "Program Files (x86)"
  63. };
  64. #define LIMITED_SYS_PATH(x) \
  65. limited_sys_paths[x]
  66. class CustomSignalEvents;
  67. enum EvtType {
  68. USER_EVT_FETCH = EVT_USER + 1,
  69. USER_EVT_RUN,
  70. USER_EVT_GET_CARDSWIPER_STATUS,
  71. USER_EVT_GET_CARDSWIPER_STATUS_FINISHED,
  72. USER_EVT_CLEAR_UPLOADEDVIDEOFILES,
  73. USER_EVT_CLEAR_UPLOADEDVIDEOFILES_FINISHED,
  74. USER_EVT_CLEAR_VIDEOFILE_ENHANCE,
  75. USER_EVT_CLEAR_VIDEOFILE_ENHANCE_FINISHED,
  76. USER_EVT_VERSION_CLEAR,
  77. USER_EVT_VERSION_CLEAR_FINISHED,
  78. USER_EVT_FILE_OPERAT,
  79. USER_EVT_FILE_OPERAT_FINISHED,
  80. USER_EVT_GET_EVENTLOG,
  81. USER_EVT_GET_EVENTLOG_FINISHED
  82. };
  83. enum DealFileType {
  84. DFT_CenterSetting,
  85. DFT_Ad0
  86. };
  87. #include "ResourceWatcher_server_g.h"
  88. #include "ResourceWatcher_msg_g.h"
  89. using namespace ResourceWatcher;
  90. using namespace CardSwiper;
  91. #define WIDE_CONDITION
  92. #ifdef WIDE_CONDITION
  93. #include "EventLogW.h"
  94. typedef CEventLogW CEventLog;
  95. typedef EVENTLOGPARAM_W EVENTLOGPARAM;
  96. typedef LPEVENTLOGPARAM_W LPEVENTLOGPARAM;
  97. #else
  98. #include "EventLog.h"
  99. #endif //WIDE_CONDITION
  100. class CardSwiperClient;
  101. struct CInstallInfoEx : public CInstallInfo
  102. {
  103. CInstallInfoEx(const CInstallInfo& info)
  104. :CInstallInfo(info){/* empty */}
  105. bool operator < (const CInstallInfoEx &rhs) const
  106. {
  107. CVersion l_version(this->InstallVersion);
  108. DWORD l_timeTick = (DWORD)this->tmSwithOverDate;
  109. CVersion r_version(rhs.InstallVersion);
  110. DWORD r_timeTick = (DWORD)rhs.tmSwithOverDate;
  111. if(l_version == r_version)
  112. return l_timeTick <= r_timeTick;
  113. return l_version > r_version;
  114. }
  115. };
  116. class FetchEvent: public FSMEvent
  117. {
  118. public:
  119. FetchEvent() : FSMEvent(USER_EVT_FETCH) {}
  120. virtual ~FetchEvent() {}
  121. SpReqAnsContext<ResourceWatcherService_Fetch_Req, ResourceWatcherService_Fetch_Ans>::Pointer ctx;
  122. virtual void OnUnhandled()
  123. {
  124. if(ctx != NULL)
  125. {
  126. ctx->Answer(Error_InvalidState);
  127. }
  128. }
  129. };
  130. struct CPUInforStruct {
  131. bool bInitialed;
  132. int level;
  133. CSimpleStringA csBrand;
  134. };
  135. class ResourceWatcherFSM : public FSMImpl<ResourceWatcherFSM>
  136. {
  137. public:
  138. ResourceWatcherFSM(void);
  139. ~ResourceWatcherFSM(void);
  140. enum {s0, s1, s2, s3};
  141. BEGIN_FSM_STATE(ResourceWatcherFSM)
  142. FSM_STATE_ENTRY(s0, "Idle", s0_on_entry, s0_on_exit, s0_on_event)
  143. FSM_STATE_ENTRY(s1, "Running", s1_on_entry, s1_on_exit, s1_on_event)
  144. FSM_STATE_ENTRY(s2, "Failed", s2_on_entry, s2_on_exit, s2_on_event)
  145. FSM_STATE_ENTRY(s3, "Listerning", s3_on_entry, s3_on_exit, s3_on_event)
  146. END_FSM_STATE()
  147. BEGIN_FSM_RULE(ResourceWatcherFSM, s0)
  148. FSM_RULE_ENTRY(s0, s1, USER_EVT_RUN, 0)
  149. FSM_RULE_ENTRY(s1, s3, USER_EVT_VERSION_CLEAR_FINISHED, 0)
  150. END_FSM_RULE()
  151. virtual ErrorCodeEnum OnInit();
  152. virtual ErrorCodeEnum OnExit();
  153. virtual void s0_on_entry();
  154. virtual void s0_on_exit();
  155. virtual unsigned int s0_on_event(FSMEvent* e);
  156. virtual void s1_on_entry();
  157. virtual void s1_on_exit();
  158. virtual unsigned int s1_on_event(FSMEvent* e);
  159. virtual void s2_on_entry();
  160. virtual void s2_on_exit();
  161. virtual unsigned int s2_on_event(FSMEvent* e);
  162. virtual void s3_on_entry();
  163. virtual void s3_on_exit();
  164. virtual unsigned int s3_on_event(FSMEvent* e);
  165. void SelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext);
  166. int GetCardSwiperVal()
  167. {
  168. return m_cardswiperStatus;
  169. }
  170. private:
  171. BOOL m_IsPadDevice;
  172. //Cardswiper Component
  173. BOOL m_bGetStatusRotate;
  174. //Video Component
  175. CSimpleStringA m_csUploadVideoPath;
  176. CSimpleStringA m_csDelFileSuffix;
  177. int m_nDayOfBackward;
  178. int m_failDelCnt;
  179. bool m_bReadyFlag;
  180. FILETIME m_ftRemoveTime;
  181. //Video Component2
  182. priority_queue<TmpFileInfo*, vector<TmpFileInfo*>, Comparetor> m_VideoFiles;
  183. ULARGE_INTEGER uiAllVideoFileSizeCal;
  184. char szMaxSizeFilePath[MAX_PATH];
  185. ULARGE_INTEGER uiMaxFileSize;
  186. ULARGE_INTEGER mUiCalibration;
  187. ULARGE_INTEGER mUiRequireBytes;
  188. //日期,数量
  189. map<UINT, UINT> VideoDailyRecord;
  190. typedef map<UINT, UINT>::const_iterator const_map_cu_iter;
  191. DiskInfo diskInfo;
  192. bool m_bVideoClearReady;
  193. int m_nMinSavedDay;
  194. //CPU Component
  195. int m_highPart, m_lowPart;
  196. CSystemStaticInfo m_RvcSysinfo;
  197. typedef std::string bs_key;
  198. typedef unsigned long bs_value;
  199. typedef map<bs_key, bs_value> BlackSheet;
  200. typedef BlackSheet::const_iterator const_bs_iter;
  201. typedef BlackSheet::iterator bs_iter;
  202. typedef std::pair<bs_key, bs_value> BlackSheetPair;
  203. BlackSheet m_blacksheet;
  204. CSimpleStringA m_strTerminalNo;
  205. FILETIME m_ftAd0RemoveTime;
  206. public:
  207. int GetCardSwiperStatus();
  208. int m_cardswiperStatus;
  209. //Start Video Component [Josephus in 9:12:26 2016/4/14]
  210. int ClearVideoFiles(int& newDeletedFilesNum, int initFlag = 1);
  211. void CalculateBackTime(PFILETIME ftResultTime, int days);
  212. BOOL CalCulateUploadFileAddition(ULARGE_INTEGER& uiBytesCal);
  213. /*
  214. *-1, First file time is earlier than second file time.
  215. * 0, First file time is equal to second file time
  216. * 1, First file time is later than second file time.
  217. */
  218. LONG CompareVideoFileTime(PFILETIME ftCurTime, PFILETIME fileTime)
  219. {
  220. return CompareFileTime(ftCurTime, fileTime);
  221. }
  222. void GetTimeString(LPTSTR lpszString, DWORD dwSize, FILETIME *ftWrite);
  223. int ProcessVideoFile(LPCTSTR dirName, int& deletedFileCnt, int& deleteFailedCnt, const int nFlag);
  224. ErrorCodeEnum ExpandDir(LPCTSTR macorStr, CSimpleStringA &outDir);
  225. // End Video Component
  226. // Start CPU Componet --Josephus at 9:05:24 2016121
  227. void InitialCPUMarkInfor();
  228. int SelectMarkLevel(int nValue)
  229. {
  230. //if(m_highPart == m_lowPart && m_lowPart + m_highPart == 0)
  231. // InitialCPUMarkInfor();
  232. if(m_highPart == m_lowPart && m_highPart == 0)
  233. return 0;
  234. if(m_lowPart == 0)
  235. {//no low config
  236. if(nValue >= m_highPart)
  237. return 1;
  238. else
  239. return 2;
  240. }
  241. else if(m_highPart == 0)
  242. {
  243. if(nValue > m_lowPart)
  244. return 2;
  245. else
  246. return 3;
  247. }
  248. else if(m_lowPart >= m_highPart)
  249. {//low standard.
  250. if(nValue > m_lowPart)
  251. return 2;
  252. else
  253. return 3;
  254. }
  255. if(nValue <= m_lowPart)
  256. return 3;
  257. if(nValue < m_highPart)
  258. return 2;
  259. return 1;
  260. //if(m_highPart < m_lowPart)
  261. // return 0;
  262. //if(nValue >= m_highPart)
  263. // return 1;
  264. //if(nValue <= m_lowPart)
  265. // return 3;
  266. //return 2;
  267. }
  268. BOOL GetCPUBrand(CSimpleStringA& csCpuBrand);
  269. ErrorCodeEnum GetCpuType(
  270. SpReqAnsContext<ResourceWatcherService_GetCpuType_Req,
  271. ResourceWatcherService_GetCpuType_Ans>::Pointer ctx);
  272. //End CPU Component
  273. // Start CenterSetting Clear Job --Josephus at 15:57:58 20161210
  274. BOOL ExecuteClearTask();
  275. int ClearSpecifieFile(DealFileType fileType, LPCTSTR dirName, int& deletedFileCnt, int& deleteFailedCnt);
  276. int DoSomethingWith(DealFileType fileType, LPCTSTR szFilePath, LPCTSTR szFileName);
  277. // End CenterSetting clear Job
  278. // Start Video Component2 --Josephus at 16:19:56 201755
  279. void ClearVideoQueue()
  280. {
  281. while(!m_VideoFiles.empty())
  282. {
  283. TmpFileInfo* pNodeInfo = m_VideoFiles.top();
  284. m_VideoFiles.pop();
  285. if(pNodeInfo != NULL)
  286. {
  287. delete pNodeInfo;
  288. }
  289. }
  290. memset(szMaxSizeFilePath, 0, sizeof(szMaxSizeFilePath));
  291. uiAllVideoFileSizeCal.QuadPart = 0ui64;
  292. uiMaxFileSize.QuadPart = 0ui64;
  293. mUiRequireBytes.QuadPart = 0ui64;
  294. VideoDailyRecord.clear();
  295. }
  296. void CalCulateFileInfo(LPCTSTR lpFilePath, PWIN32_FIND_DATA pWfdata);
  297. // Has been purified --Josephus at 10:42:55 201759
  298. void PrintResult()
  299. {
  300. char szResult[DEFAULT_OUTPUT_FORMAT_SIZE];
  301. ByteSprintf(szResult, (double)uiMaxFileSize.QuadPart);
  302. Dbg("Max Video file: %s size: %s", szMaxSizeFilePath, szResult);
  303. ByteSprintf(szResult, (double)uiAllVideoFileSizeCal.QuadPart);
  304. Dbg("uiAllVideoFileSizeCal.QuadPart : %I64u Bytes", uiAllVideoFileSizeCal.QuadPart);
  305. Dbg("Totally(size()#%d) directory size: %s", m_VideoFiles.size(), szResult);
  306. }
  307. void ClearMoreVideoFiles();
  308. bool IsNeedToFirstClear();
  309. void SetSysValAndBroadcast(DWORD dwVal, LPCTSTR lpszMessage);
  310. // End --Josephus at 16:20:02 201755
  311. BOOL DeleteVersionPackage();
  312. BOOL CombineVersionPath(CVersion version);
  313. int ProcessFileDelete(LPCTSTR lpszPath, int& nDelSucCnt, int& nDelFailedCnt);
  314. int ProcessFileSpaceCalculation(LPCTSTR lpszPath, PULARGE_INTEGER puliSpaceBytes);
  315. FILE_LAYOUT_ENTRY m_FileEntry;
  316. DWORD InitialVolumes();
  317. BOOL InitialFileEntity(LPCTSTR lpszPath, DWORD& dwFileCnt, const DWORD dwFilterAttributes = 0UL);
  318. //DWORD GetSubFileInfors(PFILE_LAYOUT_ENTRY entry, DWORD& dwDirCount, DWORD& dwFileCount);
  319. DWORD ProcessFileOperation(const SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
  320. ResourceWatcherService_OperateFile_Ans>::Pointer& ctx);
  321. DWORD ExecuteFile(LPCTSTR lpszFilePath, LPCTSTR lpParam);
  322. BOOL ConveyFileEntityToContext(const SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
  323. ResourceWatcherService_OperateFile_Ans>::Pointer& ctx, BOOL bRefleshHeader = FALSE
  324. , DWORD dwFilterAttributes = 0);
  325. int MonitorRSAMachineKeysDir();
  326. /*
  327. option: 0::scan, 2::delete
  328. */
  329. int FilterFilePathAhead(LPCTSTR lpszPath, const int option);
  330. void InitBlackSheet();
  331. BOOL InBlackSheet(LPCTSTR lpszPath, const int option);
  332. BOOL ClearDirRecursiveEx(LPCSTR lpDirPat);
  333. // Add -Josephus@2017713 16:04:18
  334. DWORD CalSpecifiedSecondsFrom1970(const WORD wDuration,
  335. DWORD* dwStartTime
  336. ,DWORD* dwEndTime
  337. ,const PULONGLONG pStartTime
  338. ,const PULONGLONG pEndTime);
  339. DWORD CombineTheEvtxFileName(LPCTSTR lpszTerminalNo, CHAR szEvtxFileName[]);
  340. DWORD GetEventLog(SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req,
  341. ResourceWatcherService_ExtractEventLog_Ans>::Pointer ctx);
  342. BOOL RetrieveSpecificedEventLogs(const LPEVENTLOGPARAM pEvtLogFilter,
  343. LPCTSTR lpszEvtFileName, DWORD& dwEntries);
  344. // Add Ad0 folder job [4/2/2018 10:53 @Gifur]
  345. BOOL ClearAd0Folder();
  346. BOOL IsTodayDone(int nRecordTime);
  347. BOOL GetSystemBootTime(CSmallDateTime& systemBootTime);
  348. HRESULT SetDefaultAudioPlaybackDevice(LPCWSTR devID);
  349. BOOL SetDefaultAudioDevice();
  350. };
  351. class RunEvent : public FSMEvent
  352. {
  353. public:
  354. RunEvent() : FSMEvent(USER_EVT_RUN) {}
  355. virtual ~RunEvent() {}
  356. };
  357. class OperateFileEvent : public FSMEvent
  358. {
  359. public:
  360. OperateFileEvent()
  361. : FSMEvent(USER_EVT_FILE_OPERAT)
  362. , m_ctx(NULL){}
  363. ~OperateFileEvent(){}
  364. SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
  365. ResourceWatcherService_OperateFile_Ans>::Pointer m_ctx;
  366. virtual void OnUnhandled()
  367. {
  368. if (m_ctx != NULL)
  369. {
  370. Dbg("Operate file event unhandled");
  371. m_ctx->Ans.result = OPT_FILE_RES_FAILED;
  372. m_ctx->Answer(Error_Succeed);
  373. }
  374. }
  375. };
  376. class GetEventLogEvent : public FSMEvent
  377. {
  378. public:
  379. GetEventLogEvent(SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req,
  380. ResourceWatcherService_ExtractEventLog_Ans>::Pointer ctx)
  381. : FSMEvent(USER_EVT_GET_EVENTLOG)
  382. , m_ctx(ctx){}
  383. ~GetEventLogEvent(){}
  384. SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req,
  385. ResourceWatcherService_ExtractEventLog_Ans>::Pointer m_ctx;
  386. virtual void OnUnhandled()
  387. {
  388. if (m_ctx != NULL)
  389. {
  390. Dbg("get event log event unhandled");
  391. }
  392. }
  393. };
  394. struct GetCardSwiperTask : public ITaskSp
  395. {
  396. ResourceWatcherFSM* m_pFSM;
  397. GetCardSwiperTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  398. void Process()
  399. {
  400. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_GET_CARDSWIPER_STATUS_FINISHED);
  401. fsmEvent->param1 = m_pFSM->GetCardSwiperStatus();
  402. m_pFSM->PostEventFIFO(fsmEvent);
  403. }
  404. };
  405. struct ClearVideoFilesTask : public ITaskSp
  406. {
  407. ResourceWatcherFSM* m_pFSM;
  408. ClearVideoFilesTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM), m_nInitFlag(1) {}
  409. int m_nInitFlag;
  410. void SetFlag(int nFlag) { m_nInitFlag = nFlag; }
  411. void Process()
  412. {
  413. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_CLEAR_UPLOADEDVIDEOFILES_FINISHED);
  414. fsmEvent->param2 = m_pFSM->ClearVideoFiles(fsmEvent->param1, m_nInitFlag);
  415. m_pFSM->PostEventFIFO(fsmEvent);
  416. }
  417. };
  418. struct ClearVideoFilesEnhanceTask : public ITaskSp
  419. {
  420. ResourceWatcherFSM* m_pFSM;
  421. ClearVideoFilesEnhanceTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  422. void Process()
  423. {
  424. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_CLEAR_VIDEOFILE_ENHANCE_FINISHED);
  425. m_pFSM->ClearMoreVideoFiles();
  426. m_pFSM->PostEventFIFO(fsmEvent);
  427. }
  428. };
  429. struct ClearCenterSettingFilesTask : public ITaskSp
  430. {
  431. ResourceWatcherFSM* m_pFSM;
  432. ClearCenterSettingFilesTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  433. void Process()
  434. {
  435. m_pFSM->ExecuteClearTask();
  436. }
  437. };
  438. struct ClearVersionTask : public ITaskSp
  439. {
  440. ResourceWatcherFSM* m_pFSM;
  441. ClearVersionTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  442. void Process()
  443. {
  444. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_VERSION_CLEAR_FINISHED);
  445. m_pFSM->DeleteVersionPackage();
  446. m_pFSM->PostEventFIFO(fsmEvent);
  447. }
  448. };
  449. struct ClearAd0Task : public ITaskSp
  450. {
  451. ResourceWatcherFSM* m_pFSM;
  452. ClearAd0Task(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM), m_nInitFlag(1) {}
  453. int m_nInitFlag;
  454. void SetFlag(int nFlag) { m_nInitFlag = nFlag; }
  455. void Process()
  456. {
  457. m_pFSM->ClearAd0Folder();
  458. }
  459. };
  460. struct RSAMachineKeyLostMonitorTask : public ITaskSp
  461. {
  462. ResourceWatcherFSM* m_pFSM;
  463. RSAMachineKeyLostMonitorTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  464. void Process()
  465. {
  466. int nRes = m_pFSM->MonitorRSAMachineKeysDir();
  467. if(nRes < 0)
  468. {
  469. LogError(Severity_Middle, Error_Unexpect, LOG_ERR_RSAKEY_MINOTOR_FAILED
  470. ,CSimpleStringA::Format("MonitorRSAMachineKeysDir failed returned: %d", nRes));
  471. }
  472. }
  473. };
  474. struct OperateFileTask : public ITaskSp
  475. {
  476. ResourceWatcherFSM* m_pFSM;
  477. OperateFileTask(ResourceWatcherFSM* pFSM,
  478. SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
  479. ResourceWatcherService_OperateFile_Ans>::Pointer ctx)
  480. : m_pFSM(pFSM)
  481. , m_ctx(ctx)
  482. {}
  483. SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
  484. ResourceWatcherService_OperateFile_Ans>::Pointer m_ctx;
  485. void Process()
  486. {
  487. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_FILE_OPERAT_FINISHED);
  488. m_pFSM->ProcessFileOperation(m_ctx);
  489. m_pFSM->PostEventFIFO(fsmEvent);
  490. }
  491. };
  492. struct GetEventLogTask : public ITaskSp
  493. {
  494. ResourceWatcherFSM* m_pFSM;
  495. GetEventLogTask(ResourceWatcherFSM* pFSM,
  496. SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req,
  497. ResourceWatcherService_ExtractEventLog_Ans>::Pointer ctx)
  498. : m_pFSM(pFSM)
  499. , m_ctx(ctx)
  500. {}
  501. SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req,
  502. ResourceWatcherService_ExtractEventLog_Ans>::Pointer m_ctx;
  503. void Process()
  504. {
  505. LOG_FUNCTION();
  506. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_GET_EVENTLOG_FINISHED);
  507. m_pFSM->GetEventLog(m_ctx);
  508. fsmEvent->param1 = fsmEvent->param2 = 0;
  509. m_pFSM->PostEventFIFO(fsmEvent);
  510. }
  511. };
  512. class CardSwiperClient : public CardSwiperService_ClientBase
  513. {
  514. public:
  515. CardSwiperClient(CEntityBase* base): CardSwiperService_ClientBase(base)
  516. {
  517. }
  518. };