From d34d398bc624521d969efab8eb1150c4a6cdeef0 Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 14 Jan 2010 10:59:24 +0000 Subject: Almost finished the inotify wrapper. It still needs more tests. Made MacroList work recursive, added watch through inotify (also recursive). --- server/src/inotify.h | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'server/src/inotify.h') diff --git a/server/src/inotify.h b/server/src/inotify.h index a2503b3..5199055 100644 --- a/server/src/inotify.h +++ b/server/src/inotify.h @@ -35,42 +35,70 @@ #include #include +typedef enum { + WATCH_SINGLE, // Watch only the specified directory. + WATCH_DEEP, // Watch all current subdirs as well + WATCH_DEEP_FOLLOW // Watch all current subdir as well as subdirs + // being created after the watch is initiated +} depth_t; + + class INotify { public: class Event { public: - Event(std::string name, uint32_t mask); + Event(struct inotify_event *event, std::string name); bool isAttributeChangeEvent(); + bool isCreateEvent(); bool isOpenEvent(); bool isCloseEvent(); + bool isCloseWriteEvent(); + bool isCloseNoWriteEvent(); bool isModifyEvent(); + bool isAccessEvent(); bool isDeleteEvent(); + bool isDeleteSelfEvent(); + bool isIgnoredEvent(); + bool isMoveSelfEvent(); + bool isMovedFromEvent(); + bool isMovedToEvent(); std::string name(); + std::string file(); uint32_t mask(); private: std::string _name; + std::string _file; uint32_t _mask; }; INotify(); ~INotify(); - void add(std::string name, uint32_t mask = IN_ALL_EVENTS); + void addFile(std::string name, uint32_t mask = IN_ALL_EVENTS); + void addDirectory(std::string name, + depth_t depth = WATCH_SINGLE, + uint32_t mask = IN_ALL_EVENTS); void remove(std::string name); void remove(int fd); - void addRecursive(std::string name, uint32_t mask = IN_ALL_EVENTS); - bool hasEvents(); Event getNextEvent(); private: + class Watch { + public: + std::string name; + uint32_t mask; + depth_t depth; + }; + void readEvents(); - int fd; - std::map dirmap; + + int ifd; + std::map dirmap; std::list eventlist; }; -- cgit v1.2.3