8#include "daq/slc/system/Inotify.h"
10#include <daq/slc/base/IOException.h>
12#include <sys/inotify.h>
17const unsigned long Inotify::FILE_CREATE(IN_CREATE);
18const unsigned long Inotify::FILE_OPEN(IN_OPEN);
19const unsigned long Inotify::FILE_CLOSE_WRITE(IN_CLOSE_WRITE);
20const unsigned long Inotify::FILE_CLOSE_NOWRITE(IN_CLOSE_NOWRITE);
21const unsigned long Inotify::FILE_DELETE(IN_DELETE);
22const unsigned long Inotify::FILE_MODIFY(IN_MODIFY);
23const unsigned long Inotify::FILE_ACCESS(IN_ACCESS);
24const unsigned long Inotify::FILE_ATTRIB(IN_ATTRIB);
28 if ((m_fd = ::inotify_init()) < 0) {
29 throw (
IOException(
"Failed to initialize inotify."));
33int Inotify::add(
const std::string& path,
unsigned long mask)
35 int wd = inotify_add_watch(m_fd, path.c_str(), mask);
42void Inotify::remove(
int wd)
44 if (::inotify_rm_watch(m_fd, wd) < 0) {
49InotifyEventList Inotify::wait(
int sec)
51 InotifyEventList ievent_v;
55 int r = read(m_fd, buf, 16384);
56 if (r <= 0)
return ievent_v;
59 inotify_event* ev = (inotify_event*)&buf[index];
60 int event_size =
sizeof(inotify_event) + ev->len;
62 ievent_v.push_back(
InotifyEvent(ev->wd, ev->mask, ev->name));
Abstract base class for different kinds of events.