diff options
Diffstat (limited to 'src/3rdParty/efsw/FileWatcherKqueue.hpp')
-rwxr-xr-x | src/3rdParty/efsw/FileWatcherKqueue.hpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/3rdParty/efsw/FileWatcherKqueue.hpp b/src/3rdParty/efsw/FileWatcherKqueue.hpp new file mode 100755 index 0000000..1bf3755 --- /dev/null +++ b/src/3rdParty/efsw/FileWatcherKqueue.hpp | |||
@@ -0,0 +1,80 @@ | |||
1 | #ifndef EFSW_FILEWATCHEROSX_HPP | ||
2 | #define EFSW_FILEWATCHEROSX_HPP | ||
3 | |||
4 | #include <efsw/FileWatcherImpl.hpp> | ||
5 | |||
6 | #if EFSW_PLATFORM == EFSW_PLATFORM_KQUEUE || EFSW_PLATFORM == EFSW_PLATFORM_FSEVENTS | ||
7 | |||
8 | #include <efsw/WatcherKqueue.hpp> | ||
9 | |||
10 | namespace efsw { | ||
11 | |||
12 | /// Implementation for OSX based on kqueue. | ||
13 | /// @class FileWatcherKqueue | ||
14 | class FileWatcherKqueue : public FileWatcherImpl { | ||
15 | friend class WatcherKqueue; | ||
16 | |||
17 | public: | ||
18 | FileWatcherKqueue( FileWatcher* parent ); | ||
19 | |||
20 | virtual ~FileWatcherKqueue(); | ||
21 | |||
22 | /// Add a directory watch | ||
23 | /// On error returns WatchID with Error type. | ||
24 | WatchID addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive ); | ||
25 | |||
26 | /// Remove a directory watch. This is a brute force lazy search O(nlogn). | ||
27 | void removeWatch( const std::string& directory ); | ||
28 | |||
29 | /// Remove a directory watch. This is a map lookup O(logn). | ||
30 | void removeWatch( WatchID watchid ); | ||
31 | |||
32 | /// Updates the watcher. Must be called often. | ||
33 | void watch(); | ||
34 | |||
35 | /// Handles the action | ||
36 | void handleAction( Watcher* watch, const std::string& filename, unsigned long action, | ||
37 | std::string oldFilename = "" ); | ||
38 | |||
39 | /// @return Returns a list of the directories that are being watched | ||
40 | std::list<std::string> directories(); | ||
41 | |||
42 | protected: | ||
43 | /// Map of WatchID to WatchStruct pointers | ||
44 | WatchMap mWatches; | ||
45 | |||
46 | /// time out data | ||
47 | struct timespec mTimeOut; | ||
48 | |||
49 | /// WatchID allocator | ||
50 | int mLastWatchID; | ||
51 | |||
52 | Thread* mThread; | ||
53 | |||
54 | Mutex mWatchesLock; | ||
55 | |||
56 | std::list<WatchID> mRemoveList; | ||
57 | |||
58 | long mFileDescriptorCount; | ||
59 | |||
60 | bool mAddingWatcher; | ||
61 | |||
62 | bool isAddingWatcher() const; | ||
63 | |||
64 | bool pathInWatches( const std::string& path ); | ||
65 | |||
66 | void addFD(); | ||
67 | |||
68 | void removeFD(); | ||
69 | |||
70 | bool availablesFD(); | ||
71 | |||
72 | private: | ||
73 | void run(); | ||
74 | }; | ||
75 | |||
76 | } // namespace efsw | ||
77 | |||
78 | #endif | ||
79 | |||
80 | #endif | ||