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