00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028 #ifndef OW32_DirectoryWatch_h
00029 #define OW32_DirectoryWatch_h
00030
00031 #include <OW32/IoCompletion.h>
00032 #include <OW32/RefCounted.h>
00033 #include <OW32/auto_array_ptr.h>
00034 #include <OW32/SyncObjects.h>
00035
00036 #include <stl/ci_string.h>
00037
00038 namespace OW32
00039 {
00040
00041 class CIoCompletionThreadPool;
00042 class CDirectoryWatchCallback;
00043
00054 class CDirectoryWatch :
00055 public CIoCompletion,
00056 public CRefCounted
00057 {
00058 public:
00059 IMPLEMENT_IO_COMPLETION(CDirectoryWatch);
00060
00069 CDirectoryWatch(
00070 CDirectoryWatchCallback *callback,
00071 CIoCompletionThreadPool &ioCompletionPool,
00072 const ci_wstring &directoryName,
00073 DWORD changesMask = FILE_NOTIFY_CHANGE_LAST_WRITE|FILE_NOTIFY_CHANGE_FILE_NAME
00074 );
00075
00079 virtual ~CDirectoryWatch();
00080
00084 const ci_wstring &getDirectory() const { return m_directory; }
00085
00089 void cancel();
00090
00091 private:
00092
00093 CDirectoryWatch(const CDirectoryWatch &other);
00094 CDirectoryWatch &operator= (const CDirectoryWatch &other);
00095
00099 void OnWatchCompletion(BOOL bRet, DWORD dwBytes, LPOVERLAPPED lpOS);
00100
00104 void processNotifications();
00105
00107 CDirectoryWatchCallback *m_callback;
00108
00110 ci_wstring m_directory;
00111
00113 DWORD m_changesMask;
00114
00116 OVERLAPPEDPLUS m_os;
00117
00119 auto_array_ptr<BYTE> m_notifyBuffer;
00120
00122 DWORD m_notifyBufferCount;
00123
00125 CCriticalSection m_directoryLock;
00126
00128 XHANDLE m_hDirectory;
00129 };
00130
00131 #ifdef _MSC_VER
00132 #pragma warning(default: 4251)
00133 #endif
00134
00136 typedef CAutoRefCountedPtr<CDirectoryWatch> CDirectoryWatchPtr;
00137
00138 }
00139
00140 #endif // OW32_DirectoryWatch_h