00001 00029 #ifndef _FW_FILEWATCHER_H_ 00030 #define _FW_FILEWATCHER_H_ 00031 00032 #include "FileWatcherWin32Header.h" 00033 #include <string> 00034 #include <stdexcept> 00035 00036 namespace FW 00037 { 00039 typedef std::string String; 00041 typedef unsigned long WatchID; 00042 00043 // forward declarations 00044 class FileWatcherImpl; 00045 class FileWatchListener; 00046 00049 class Exception : public std::runtime_error 00050 { 00051 public: 00052 Exception(const String& message) 00053 : std::runtime_error(message) 00054 {} 00055 }; 00056 00059 class FileNotFoundException : public Exception 00060 { 00061 public: 00062 FileNotFoundException() 00063 : Exception("File not found") 00064 {} 00065 00066 FileNotFoundException(const String& filename, 00067 const String message = "") 00068 : Exception(message + "File not found (" + filename + ")") 00069 {} 00070 }; 00071 00075 namespace Actions 00076 { 00077 enum Action 00078 { 00080 Add = 1, 00082 Delete = 2, 00084 Modified = 4 00085 }; 00086 }; 00087 typedef Actions::Action Action; 00088 00092 class FileWatcher_EXPORT FileWatcher 00093 { 00094 public: 00097 FileWatcher(); 00098 00101 virtual ~FileWatcher(); 00102 00106 WatchID addWatch(const String& directory, 00107 FileWatchListener* watcher, 00108 bool recursive = false); 00109 00111 void removeWatch(const String& directory); 00112 00114 void removeWatch(WatchID watchid); 00115 00117 void update(); 00118 00119 private: 00121 FileWatcherImpl* mImpl; 00122 00123 };//end FileWatcher 00124 00125 00128 class FileWatchListener 00129 { 00130 public: 00131 FileWatchListener() {} 00132 virtual ~FileWatchListener() {} 00133 00139 virtual void handleFileAction(WatchID watchid, 00140 const String& dir, 00141 const String& filename, 00142 Action action) = 0; 00143 00144 };//class FileWatchListener 00145 00146 };//namespace FW 00147 00148 #endif//_FW_FILEWATCHER_H_
1.6.1