17 #ifndef FILEWATCHTHREAD_H_ 18 #define FILEWATCHTHREAD_H_ 21 #include <sys/inotify.h> 50 #define BUF_SIZE MAX_EVENTS*(sizeof(struct inotify_event) + NAME_MAX + 1) 56 while (
int numRead = read(fd, eventBuf,
BUF_SIZE)) {
57 if (numRead == 0 | numRead == -1){
58 printf(
"FileWatchThreaded::threadMain : read() from inotify fd returned %d !\n",numRead);
62 for (
char *
p = (
char*)eventBuf; p < eventBuf + numRead; p += sizeof(struct inotify_event) + reinterpret_cast<struct inotify_event *>(
p)->len) {
63 if (reinterpret_cast<struct inotify_event *>(
p)->mask & IN_MODIFY)
64 modified(reinterpret_cast<struct inotify_event *>(
p)->name);
65 if (reinterpret_cast<struct inotify_event *>(
p)->mask & IN_CLOSE_WRITE)
66 closeWrite(reinterpret_cast<struct inotify_event *>(
p)->name);
105 virtual int add(std::string path){
106 int ret = inotify_add_watch(fd, path.c_str(), IN_ALL_EVENTS);
108 return Debug().
evaluateError(fd,
" FileWatchThreaded : When calling inotify_add_watch.");
120 FILE *fid=fopen(path.c_str(),
"a");
132 #endif // FILEWATCHTHREAD_H_
virtual int addFile(std::string path)
FileWatchThreaded()
Constructor.
int fd
The inotify file descriptor.
virtual int evaluateError(int errorNum)
char eventBuf [BUF_SIZE] __attribute__((aligned(__alignof__(struct inotify_event))))
The buffered events.
virtual void closeWrite(char *name)
virtual ~FileWatchThreaded()
Destructor.
virtual void modified(char *name)
virtual int add(std::string path)
std::map< std::string, int > pathFds
This will contain a map between watch file descriptors and file/dir names.
virtual void * threadMain(void)