|
void | open () |
|
int | add (const std::string &path, unsigned long mask) |
|
void | remove (int wd) |
|
InotifyEventList | wait (int sec) |
|
int | get_fd () const |
|
bool | select (int sec=-1, int usec=-1) |
|
bool | select2 (int sec=-1, int usec=-1) |
|
bool | close () |
|
Definition at line 49 of file Inotify.h.
◆ Inotify()
◆ ~Inotify()
◆ add()
int add |
( |
const std::string & |
path, |
|
|
unsigned long |
mask |
|
) |
| |
Definition at line 33 of file Inotify.cc.
34{
35 int wd = inotify_add_watch(m_fd, path.c_str(), mask);
36 if (wd < 0) {
38 }
39 return wd;
40}
◆ close()
Definition at line 90 of file FileDescriptor.cc.
91{
92 if (m_fd > 0) {
93 if (::close(m_fd) != 0) {
94 return false;
95 }
96 }
97 m_fd = -1;
98 return true;
99}
◆ get_fd()
◆ open()
Definition at line 26 of file Inotify.cc.
27{
28 if ((m_fd = ::inotify_init()) < 0) {
29 throw (
IOException(
"Failed to initialize inotify."));
30 }
31}
◆ remove()
Definition at line 42 of file Inotify.cc.
43{
44 if (::inotify_rm_watch(m_fd, wd) < 0) {
46 }
47}
◆ select()
bool select |
( |
int |
sec = -1 , |
|
|
int |
usec = -1 |
|
) |
| |
|
inherited |
Definition at line 38 of file FileDescriptor.cc.
39{
40 if (m_fd <= 0) {
41 return false;
42 }
43 fd_set fds;
44 FD_ZERO(&fds);
45 FD_SET(m_fd, &fds);
46 int ret;
47 if (sec >= 0 && usec >= 0) {
48 timeval t = {sec, usec};
49 ret = ::select(FD_SETSIZE, &fds, NULL, NULL, &t);
50 } else {
51 ret = ::select(FD_SETSIZE, &fds, NULL, NULL, NULL);
52 }
53 if (ret < 0) {
54 perror("select");
56 }
57 if (FD_ISSET(m_fd, &fds)) {
58 return true;
59 } else {
60 return false;
61 }
62}
◆ select2()
bool select2 |
( |
int |
sec = -1 , |
|
|
int |
usec = -1 |
|
) |
| |
|
inherited |
Definition at line 64 of file FileDescriptor.cc.
65{
66 if (m_fd <= 0) {
67 return false;
68 }
69 fd_set fds;
70 FD_ZERO(&fds);
71 FD_SET(m_fd, &fds);
72 int ret;
73 if (sec >= 0 && usec >= 0) {
74 timeval t = {sec, usec};
75 ret = ::select(FD_SETSIZE, NULL, &fds, NULL, &t);
76 } else {
77 ret = ::select(FD_SETSIZE, NULL, &fds, NULL, NULL);
78 }
79 if (ret < 0) {
80 perror("select");
82 }
83 if (FD_ISSET(m_fd, &fds)) {
84 return true;
85 } else {
86 return false;
87 }
88}
◆ wait()
InotifyEventList wait |
( |
int |
sec | ) |
|
Definition at line 49 of file Inotify.cc.
50{
51 InotifyEventList ievent_v;
52
53 if (select(sec, 0)) {
54 char buf[16384];
55 int r = read(m_fd, buf, 16384);
56 if (r <= 0) return ievent_v;
57 int index = 0;
58 while (index < r) {
59 inotify_event* ev = (inotify_event*)&buf[index];
60 int event_size = sizeof(inotify_event) + ev->len;
61 index += event_size;
62 ievent_v.push_back(
InotifyEvent(ev->wd, ev->mask, ev->name));
63 }
64 }
65
66
67
68 return ievent_v;
69}
◆ FILE_ACCESS
const unsigned long FILE_ACCESS |
|
static |
◆ FILE_ATTRIB
const unsigned long FILE_ATTRIB |
|
static |
◆ FILE_CLOSE_NOWRITE
const unsigned long FILE_CLOSE_NOWRITE |
|
static |
◆ FILE_CLOSE_WRITE
const unsigned long FILE_CLOSE_WRITE |
|
static |
◆ FILE_CREATE
const unsigned long FILE_CREATE |
|
static |
◆ FILE_DELETE
const unsigned long FILE_DELETE |
|
static |
◆ FILE_MODIFY
const unsigned long FILE_MODIFY |
|
static |
◆ FILE_OPEN
const unsigned long FILE_OPEN |
|
static |
◆ m_fd
The documentation for this class was generated from the following files: