Watcher.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Watcher.h: interface for the CWatcher class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_WATCHER_H__59FB1B23_A774_4A4A_8D09_534FC5CFD9E1__INCLUDED_)
  5. #define AFX_WATCHER_H__59FB1B23_A774_4A4A_8D09_534FC5CFD9E1__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. #define WTH_BUF_LEN (MAX_PATH * 2)
  10. class CWatcher
  11. {
  12. public:
  13. enum enmACTION
  14. {
  15. actCreate = FILE_ACTION_ADDED,
  16. actRemote = FILE_ACTION_REMOVED,
  17. actRenameNew = FILE_ACTION_RENAMED_NEW_NAME,
  18. actRenameOld = FILE_ACTION_RENAMED_OLD_NAME,
  19. actChange = FILE_ACTION_MODIFIED
  20. };
  21. public:
  22. CWatcher();
  23. virtual ~CWatcher();
  24. public:
  25. VOID Destroy();
  26. BOOL Create(CString csStrPath);
  27. protected:
  28. virtual VOID OnWatch(DWORD dwAction, CString csStrName1, CString csStrName2);
  29. private:
  30. BOOL Watch();
  31. static DWORD WINAPI WatchThreadProc(LPVOID lpvPara);
  32. VOID CloseAllHandle();
  33. CString WideCharToCString(LPCWSTR lpszWideChar, UINT nLength);
  34. private:
  35. char m_szBuffer[WTH_BUF_LEN]; // 缓冲区
  36. OVERLAPPED m_stOverlapped; // 重叠结构
  37. HANDLE m_hThread; // 线程句柄
  38. HANDLE m_hIOCPNew; // 新的完成端口句柄
  39. HANDLE m_hIOCPApp; // 使用的完成端口句柄
  40. HANDLE m_hPath; // 目录句柄
  41. };
  42. #endif // !defined(AFX_WATCHER_H__59FB1B23_A774_4A4A_8D09_534FC5CFD9E1__INCLUDED_)