#ifndef EFSW_FILEWATCHERLINUX_HPP #define EFSW_FILEWATCHERLINUX_HPP #include #if EFSW_PLATFORM == EFSW_PLATFORM_INOTIFY #include #include #include #include namespace efsw { /// Implementation for Linux based on inotify. /// @class FileWatcherInotify class FileWatcherInotify : public FileWatcherImpl { public: /// type for a map from WatchID to WatchStruct pointer typedef std::map WatchMap; FileWatcherInotify( FileWatcher* parent ); virtual ~FileWatcherInotify(); /// Add a directory watch /// On error returns WatchID with Error type. WatchID addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive, const std::vector& options ) override; /// Remove a directory watch. This is a brute force lazy search O(nlogn). void removeWatch( const std::string& directory ) override; /// Remove a directory watch. This is a map lookup O(logn). void removeWatch( WatchID watchid ) override; /// Updates the watcher. Must be called often. void watch() override; /// Handles the action void handleAction( Watcher* watch, const std::string& filename, unsigned long action, std::string oldFilename = "" ) override; /// @return Returns a list of the directories that are being watched std::vector directories() override; protected: /// Map of WatchID to WatchStruct pointers WatchMap mWatches; /// User added watches WatchMap mRealWatches; std::unordered_map mWatchesRef; /// inotify file descriptor int mFD; Thread* mThread; Mutex mWatchesLock; Mutex mRealWatchesLock; Mutex mInitLock; bool mIsTakingAction; std::vector> mMovedOutsideWatches; WatchID addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive, bool syntheticEvents, WatcherInotify* parent = NULL, bool fromInternalEvent = false ); bool pathInWatches( const std::string& path ) override; private: void run(); void removeWatchLocked( WatchID watchid ); void checkForNewWatcher( Watcher* watch, std::string fpath ); Watcher* watcherContainsDirectory( std::string dir ); }; } // namespace efsw #endif #endif