From 94f8330613877b3582d32bd11abd83a97b4399ad Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 15 Nov 2022 17:23:46 +0800 Subject: adding -w option to Yuescript tool. --- src/3rdParty/efsw/FileWatcherGeneric.hpp | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 src/3rdParty/efsw/FileWatcherGeneric.hpp (limited to 'src/3rdParty/efsw/FileWatcherGeneric.hpp') diff --git a/src/3rdParty/efsw/FileWatcherGeneric.hpp b/src/3rdParty/efsw/FileWatcherGeneric.hpp new file mode 100755 index 0000000..4cb0b67 --- /dev/null +++ b/src/3rdParty/efsw/FileWatcherGeneric.hpp @@ -0,0 +1,60 @@ +#ifndef EFSW_FILEWATCHERGENERIC_HPP +#define EFSW_FILEWATCHERGENERIC_HPP + +#include +#include +#include +#include + +namespace efsw { + +/// Implementation for Generic File Watcher. +/// @class FileWatcherGeneric +class FileWatcherGeneric : public FileWatcherImpl { + public: + typedef std::list WatchList; + + FileWatcherGeneric( FileWatcher* parent ); + + virtual ~FileWatcherGeneric(); + + /// Add a directory watch + /// On error returns WatchID with Error type. + WatchID addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive ); + + /// Remove a directory watch. This is a brute force lazy search O(nlogn). + void removeWatch( const std::string& directory ); + + /// Remove a directory watch. This is a map lookup O(logn). + void removeWatch( WatchID watchid ); + + /// Updates the watcher. Must be called often. + void watch(); + + /// Handles the action + void handleAction( Watcher* watch, const std::string& filename, unsigned long action, + std::string oldFilename = "" ); + + /// @return Returns a list of the directories that are being watched + std::list directories(); + + protected: + Thread* mThread; + + /// The last watchid + WatchID mLastWatchID; + + /// Map of WatchID to WatchStruct pointers + WatchList mWatches; + + Mutex mWatchesLock; + + bool pathInWatches( const std::string& path ); + + private: + void run(); +}; + +} // namespace efsw + +#endif -- cgit v1.2.3-55-g6feb