1 #include "daq/slc/system/Inotify.h"
3 #include <daq/slc/base/IOException.h>
5 #include <sys/inotify.h>
10 const unsigned long Inotify::FILE_CREATE(IN_CREATE);
11 const unsigned long Inotify::FILE_OPEN(IN_OPEN);
12 const unsigned long Inotify::FILE_CLOSE_WRITE(IN_CLOSE_WRITE);
13 const unsigned long Inotify::FILE_CLOSE_NOWRITE(IN_CLOSE_NOWRITE);
14 const unsigned long Inotify::FILE_DELETE(IN_DELETE);
15 const unsigned long Inotify::FILE_MODIFY(IN_MODIFY);
16 const unsigned long Inotify::FILE_ACCESS(IN_ACCESS);
17 const unsigned long Inotify::FILE_ATTRIB(IN_ATTRIB);
21 if ((m_fd = ::inotify_init()) < 0) {
22 throw (
IOException(
"Failed to initialize inotify."));
26 int Inotify::add(
const std::string& path,
unsigned long mask)
28 int wd = inotify_add_watch(m_fd, path.c_str(), mask);
35 void Inotify::remove(
int wd)
37 if (::inotify_rm_watch(m_fd, wd) < 0) {
42 InotifyEventList Inotify::wait(
int sec)
44 InotifyEventList ievent_v;
48 int r = read(m_fd, buf, 16384);
49 if (r <= 0)
return ievent_v;
52 inotify_event* ev = (inotify_event*)&buf[index];
53 int event_size =
sizeof(inotify_event) + ev->len;
55 ievent_v.push_back(
InotifyEvent(ev->wd, ev->mask, ev->name));