1 #ifndef INOTIFYWATCHTOWERDRIVER_H 2 #define INOTIFYWATCHTOWERDRIVER_H 3 4 #include <memory> 5 #include <mutex> 6 #include <vector> 7 8 class ObservedFile; 9 class ObservedFileList; 10 11 class INotifyWatchTowerDriver { 12 public: 13 class FileId { 14 public: 15 friend class INotifyWatchTowerDriver; 16 17 FileId() { wd_ = -1; } 18 bool operator==( const FileId& other ) const 19 { return wd_ == other.wd_; } 20 private: 21 FileId( int wd ) { wd_ = wd; } 22 int wd_; 23 }; 24 class DirId { 25 public: 26 friend class INotifyWatchTowerDriver; 27 28 DirId() { wd_ = -1; } 29 bool operator==( const DirId& other ) const 30 { return wd_ == other.wd_; } 31 private: 32 DirId( int wd ) { wd_ = wd; } 33 int wd_; 34 }; 35 class SymlinkId { 36 public: 37 friend class INotifyWatchTowerDriver; 38 39 SymlinkId() { wd_ = -1; } 40 bool operator==( const SymlinkId& other ) const 41 { return wd_ == other.wd_; } 42 private: 43 SymlinkId( int wd ) { wd_ = wd; } 44 int wd_; 45 }; 46 47 INotifyWatchTowerDriver(); 48 49 FileId addFile( const std::string& file_name ); 50 SymlinkId addSymlink( const std::string& file_name ); 51 DirId addDir( const std::string& file_name ); 52 53 void removeFile( const FileId& file_id ); 54 void removeSymlink( const SymlinkId& symlink_id ); 55 56 std::vector<ObservedFile*> waitAndProcessEvents( 57 ObservedFileList* list, 58 std::mutex* list_mutex ); 59 60 private: 61 // Only written at initialisation so no protection needed. 62 const int inotify_fd_; 63 64 // Private member functions 65 size_t processINotifyEvent( const struct inotify_event* event, 66 ObservedFileList* list, 67 std::mutex* list_mutex, 68 std::vector<ObservedFile*>* files_to_notify ); 69 }; 70 71 #endif 72