diff options
| author | Li Jin <dragon-fly@qq.com> | 2025-04-09 17:40:13 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2025-04-09 17:40:13 +0800 |
| commit | 9750786a5c03b5ce3ea22b240d1b3cd34990856b (patch) | |
| tree | e495e43245e1bacc86d33142af202613a82a40c1 /src/3rdParty/efsw/FileWatcherInotify.hpp | |
| parent | 571fb952b99e580a0381f539885f8f175e2ec3b0 (diff) | |
| download | yuescript-9750786a5c03b5ce3ea22b240d1b3cd34990856b.tar.gz yuescript-9750786a5c03b5ce3ea22b240d1b3cd34990856b.tar.bz2 yuescript-9750786a5c03b5ce3ea22b240d1b3cd34990856b.zip | |
Updated efsw. Fixed issue #204.
Diffstat (limited to 'src/3rdParty/efsw/FileWatcherInotify.hpp')
| -rw-r--r--[-rwxr-xr-x] | src/3rdParty/efsw/FileWatcherInotify.hpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/3rdParty/efsw/FileWatcherInotify.hpp b/src/3rdParty/efsw/FileWatcherInotify.hpp index dc922ac..26d2c0b 100755..100644 --- a/src/3rdParty/efsw/FileWatcherInotify.hpp +++ b/src/3rdParty/efsw/FileWatcherInotify.hpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | #include <efsw/WatcherInotify.hpp> | 8 | #include <efsw/WatcherInotify.hpp> |
| 9 | #include <map> | 9 | #include <map> |
| 10 | #include <unordered_map> | ||
| 10 | #include <vector> | 11 | #include <vector> |
| 11 | 12 | ||
| 12 | namespace efsw { | 13 | namespace efsw { |
| @@ -24,23 +25,24 @@ class FileWatcherInotify : public FileWatcherImpl { | |||
| 24 | 25 | ||
| 25 | /// Add a directory watch | 26 | /// Add a directory watch |
| 26 | /// On error returns WatchID with Error type. | 27 | /// On error returns WatchID with Error type. |
| 27 | WatchID addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive ); | 28 | WatchID addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive, |
| 29 | const std::vector<WatcherOption>& options ) override; | ||
| 28 | 30 | ||
| 29 | /// Remove a directory watch. This is a brute force lazy search O(nlogn). | 31 | /// Remove a directory watch. This is a brute force lazy search O(nlogn). |
| 30 | void removeWatch( const std::string& directory ); | 32 | void removeWatch( const std::string& directory ) override; |
| 31 | 33 | ||
| 32 | /// Remove a directory watch. This is a map lookup O(logn). | 34 | /// Remove a directory watch. This is a map lookup O(logn). |
| 33 | void removeWatch( WatchID watchid ); | 35 | void removeWatch( WatchID watchid ) override; |
| 34 | 36 | ||
| 35 | /// Updates the watcher. Must be called often. | 37 | /// Updates the watcher. Must be called often. |
| 36 | void watch(); | 38 | void watch() override; |
| 37 | 39 | ||
| 38 | /// Handles the action | 40 | /// Handles the action |
| 39 | void handleAction( Watcher* watch, const std::string& filename, unsigned long action, | 41 | void handleAction( Watcher* watch, const std::string& filename, unsigned long action, |
| 40 | std::string oldFilename = "" ); | 42 | std::string oldFilename = "" ) override; |
| 41 | 43 | ||
| 42 | /// @return Returns a list of the directories that are being watched | 44 | /// @return Returns a list of the directories that are being watched |
| 43 | std::list<std::string> directories(); | 45 | std::vector<std::string> directories() override; |
| 44 | 46 | ||
| 45 | protected: | 47 | protected: |
| 46 | /// Map of WatchID to WatchStruct pointers | 48 | /// Map of WatchID to WatchStruct pointers |
| @@ -49,6 +51,8 @@ class FileWatcherInotify : public FileWatcherImpl { | |||
| 49 | /// User added watches | 51 | /// User added watches |
| 50 | WatchMap mRealWatches; | 52 | WatchMap mRealWatches; |
| 51 | 53 | ||
| 54 | std::unordered_map<std::string, WatchID> mWatchesRef; | ||
| 55 | |||
| 52 | /// inotify file descriptor | 56 | /// inotify file descriptor |
| 53 | int mFD; | 57 | int mFD; |
| 54 | 58 | ||
| @@ -57,12 +61,14 @@ class FileWatcherInotify : public FileWatcherImpl { | |||
| 57 | Mutex mWatchesLock; | 61 | Mutex mWatchesLock; |
| 58 | Mutex mRealWatchesLock; | 62 | Mutex mRealWatchesLock; |
| 59 | Mutex mInitLock; | 63 | Mutex mInitLock; |
| 64 | bool mIsTakingAction; | ||
| 60 | std::vector<std::pair<WatcherInotify*, std::string>> mMovedOutsideWatches; | 65 | std::vector<std::pair<WatcherInotify*, std::string>> mMovedOutsideWatches; |
| 61 | 66 | ||
| 62 | WatchID addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive, | 67 | WatchID addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive, |
| 63 | WatcherInotify* parent = NULL ); | 68 | bool syntheticEvents, WatcherInotify* parent = NULL, |
| 69 | bool fromInternalEvent = false ); | ||
| 64 | 70 | ||
| 65 | bool pathInWatches( const std::string& path ); | 71 | bool pathInWatches( const std::string& path ) override; |
| 66 | 72 | ||
| 67 | private: | 73 | private: |
| 68 | void run(); | 74 | void run(); |
