Rev 3 | Rev 13 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3 | Rev 11 | ||
---|---|---|---|
Line 26... | Line 26... | ||
26 | #include "inotify-cxx.h"
|
26 | #include "inotify-cxx.h"
|
27 | 27 | ||
28 | #define DUMP_SEP \
|
28 | #define DUMP_SEP \
|
29 | ({ \
|
29 | ({ \
|
30 | if (!rStr.empty()) { \
|
30 | if (!rStr.empty()) { \
|
31 | rStr.append(" "); \
|
31 | rStr.append(","); \
|
32 | } \
|
32 | } \
|
33 | })
|
33 | })
|
34 | 34 | ||
- | 35 | uint32_t InotifyEvent::GetMaskByName(const std::string& rName) |
|
- | 36 | {
|
|
- | 37 | if (rName == "IN_ACCESS") |
|
- | 38 | return IN_ACCESS; |
|
- | 39 | else if (rName == "IN_MODIFY") |
|
- | 40 | return IN_MODIFY; |
|
- | 41 | else if (rName == "IN_ATTRIB") |
|
- | 42 | return IN_ATTRIB; |
|
- | 43 | else if (rName == "IN_CLOSE_WRITE") |
|
- | 44 | return IN_CLOSE_WRITE; |
|
- | 45 | else if (rName == "IN_CLOSE_NOWRITE") |
|
- | 46 | return IN_CLOSE_NOWRITE; |
|
- | 47 | else if (rName == "IN_MOVED_FROM") |
|
- | 48 | return IN_MOVED_FROM; |
|
- | 49 | else if (rName == "IN_MOVED_TO") |
|
- | 50 | return IN_MOVED_TO; |
|
- | 51 | else if (rName == "IN_CREATE") |
|
- | 52 | return IN_CREATE; |
|
- | 53 | else if (rName == "IN_DELETE") |
|
- | 54 | return IN_DELETE; |
|
- | 55 | else if (rName == "IN_DELETE_SELF") |
|
- | 56 | return IN_DELETE_SELF; |
|
- | 57 | else if (rName == "IN_UNMOUNT") |
|
- | 58 | return IN_UNMOUNT; |
|
- | 59 | else if (rName == "IN_Q_OVERFLOW") |
|
- | 60 | return IN_Q_OVERFLOW; |
|
- | 61 | else if (rName == "IN_IGNORED") |
|
- | 62 | return IN_IGNORED; |
|
- | 63 | else if (rName == "IN_CLOSE") |
|
- | 64 | return IN_CLOSE; |
|
- | 65 | else if (rName == "IN_MOVE") |
|
- | 66 | return IN_MOVE; |
|
- | 67 | else if (rName == "IN_ISDIR") |
|
- | 68 | return IN_ISDIR; |
|
- | 69 | else if (rName == "IN_ONESHOT") |
|
- | 70 | return IN_ONESHOT; |
|
- | 71 | else if (rName == "IN_ALL_EVENTS") |
|
- | 72 | return IN_ALL_EVENTS; |
|
- | 73 | ||
- | 74 | return (uint32_t) 0; |
|
- | 75 | }
|
|
35 | 76 | ||
36 | void InotifyEvent::DumpTypes(std::string& rStr) const |
77 | void InotifyEvent::DumpTypes(uint32_t uValue, std::string& rStr) |
37 | {
|
78 | {
|
38 | rStr = ""; |
79 | rStr = ""; |
39 | 80 | ||
40 | if (IsType(IN_ACCESS)) { |
81 | if (IsType(uValue, IN_ALL_EVENTS)) { |
41 | rStr.append("IN_ACCESS"); |
82 | rStr.append("IN_ALL_EVENTS"); |
42 | }
|
- | |
43 | if (IsType(IN_MODIFY)) { |
- | |
44 | DUMP_SEP;
|
- | |
45 | rStr.append("IN_MODIFY"); |
- | |
46 | }
|
- | |
47 | if (IsType(IN_ATTRIB)) { |
- | |
48 | DUMP_SEP;
|
- | |
49 | rStr.append("IN_ATTRIB"); |
- | |
50 | }
|
83 | }
|
- | 84 | else { |
|
- | 85 | if (IsType(uValue, IN_ACCESS)) { |
|
- | 86 | DUMP_SEP;
|
|
- | 87 | rStr.append("IN_ACCESS"); |
|
- | 88 | }
|
|
- | 89 | if (IsType(uValue, IN_MODIFY)) { |
|
- | 90 | DUMP_SEP;
|
|
- | 91 | rStr.append("IN_MODIFY"); |
|
- | 92 | }
|
|
- | 93 | if (IsType(uValue, IN_ATTRIB)) { |
|
- | 94 | DUMP_SEP;
|
|
- | 95 | rStr.append("IN_ATTRIB"); |
|
- | 96 | }
|
|
51 | if (IsType(IN_CLOSE_WRITE)) { |
97 | if (IsType(uValue, IN_CREATE)) { |
- | 98 | DUMP_SEP;
|
|
- | 99 | rStr.append("IN_CREATE"); |
|
- | 100 | }
|
|
- | 101 | if (IsType(uValue, IN_DELETE)) { |
|
- | 102 | DUMP_SEP;
|
|
- | 103 | rStr.append("IN_DELETE"); |
|
- | 104 | }
|
|
- | 105 | if (IsType(uValue, IN_DELETE_SELF)) { |
|
- | 106 | DUMP_SEP;
|
|
- | 107 | rStr.append("IN_DELETE_SELF"); |
|
- | 108 | }
|
|
- | 109 | if (IsType(uValue, IN_OPEN)) { |
|
- | 110 | DUMP_SEP;
|
|
- | 111 | rStr.append("IN_OPEN"); |
|
- | 112 | }
|
|
- | 113 | if (IsType(uValue, IN_CLOSE)) { |
|
52 | DUMP_SEP;
|
114 | DUMP_SEP;
|
53 | rStr.append("IN_CLOSE_WRITE"); |
115 | rStr.append("IN_CLOSE"); |
54 | }
|
116 | }
|
- | 117 | else { |
|
- | 118 | if (IsType(uValue, IN_CLOSE_WRITE)) { |
|
- | 119 | DUMP_SEP;
|
|
- | 120 | rStr.append("IN_CLOSE_WRITE"); |
|
- | 121 | }
|
|
55 | if (IsType(IN_CLOSE_NOWRITE)) { |
122 | if (IsType(uValue, IN_CLOSE_NOWRITE)) { |
56 | DUMP_SEP;
|
123 | DUMP_SEP;
|
57 | rStr.append("IN_CLOSE_NOWRITE"); |
124 | rStr.append("IN_CLOSE_NOWRITE"); |
- | 125 | }
|
|
58 | }
|
126 | }
|
59 | if (IsType(IN_OPEN)) { |
127 | if (IsType(uValue, IN_MOVE)) { |
60 | DUMP_SEP;
|
128 | DUMP_SEP;
|
61 | rStr.append("IN_OPEN"); |
129 | rStr.append("IN_MOVE"); |
62 | }
|
130 | }
|
- | 131 | else { |
|
63 | if (IsType(IN_MOVED_FROM)) { |
132 | if (IsType(uValue, IN_MOVED_FROM)) { |
64 | DUMP_SEP;
|
133 | DUMP_SEP;
|
65 | rStr.append("IN_MOVED_FROM"); |
134 | rStr.append("IN_MOVED_FROM"); |
- | 135 | }
|
|
- | 136 | if (IsType(uValue, IN_MOVED_TO)) { |
|
- | 137 | DUMP_SEP;
|
|
- | 138 | rStr.append("IN_MOVED_TO"); |
|
- | 139 | }
|
|
- | 140 | }
|
|
66 | }
|
141 | }
|
67 | if (IsType(IN_MOVED_TO)) { |
- | |
68 | DUMP_SEP;
|
- | |
69 | rStr.append("IN_MOVED_TO"); |
- | |
70 | }
|
- | |
71 | if (IsType(IN_CREATE)) { |
- | |
72 | DUMP_SEP;
|
- | |
73 | rStr.append("IN_CREATE"); |
- | |
74 | }
|
- | |
75 | if (IsType(IN_DELETE)) { |
- | |
76 | DUMP_SEP;
|
- | |
77 | rStr.append("IN_DELETE"); |
- | |
78 | }
|
- | |
79 | if (IsType(IN_DELETE_SELF)) { |
- | |
80 | DUMP_SEP;
|
- | |
81 | rStr.append("IN_DELETE_SELF"); |
- | |
82 | }
|
- | |
83 | if (IsType(IN_UNMOUNT)) { |
142 | if (IsType(uValue, IN_UNMOUNT)) { |
84 | DUMP_SEP;
|
143 | DUMP_SEP;
|
85 | rStr.append("IN_UNMOUNT"); |
144 | rStr.append("IN_UNMOUNT"); |
86 | }
|
145 | }
|
87 | if (IsType(IN_Q_OVERFLOW)) { |
146 | if (IsType(uValue, IN_Q_OVERFLOW)) { |
88 | DUMP_SEP;
|
147 | DUMP_SEP;
|
89 | rStr.append("IN_Q_OVERFLOW"); |
148 | rStr.append("IN_Q_OVERFLOW"); |
90 | }
|
149 | }
|
91 | if (IsType(IN_IGNORED)) { |
150 | if (IsType(uValue, IN_IGNORED)) { |
92 | DUMP_SEP;
|
151 | DUMP_SEP;
|
93 | rStr.append("IN_IGNORED"); |
152 | rStr.append("IN_IGNORED"); |
94 | }
|
153 | }
|
95 | if (IsType(IN_CLOSE)) { |
- | |
96 | DUMP_SEP;
|
- | |
97 | rStr.append("IN_CLOSE"); |
- | |
98 | }
|
- | |
99 | if (IsType(IN_MOVE)) { |
- | |
100 | DUMP_SEP;
|
- | |
101 | rStr.append("IN_MOVE"); |
- | |
102 | }
|
- | |
103 | if (IsType(IN_ISDIR)) { |
154 | if (IsType(uValue, IN_ISDIR)) { |
104 | DUMP_SEP;
|
155 | DUMP_SEP;
|
105 | rStr.append("IN_ISDIR"); |
156 | rStr.append("IN_ISDIR"); |
106 | }
|
157 | }
|
107 | if (IsType(IN_ONESHOT)) { |
158 | if (IsType(uValue, IN_ONESHOT)) { |
108 | DUMP_SEP;
|
159 | DUMP_SEP;
|
109 | rStr.append("IN_ONESHOT"); |
160 | rStr.append("IN_ONESHOT"); |
110 | }
|
161 | }
|
111 | }
|
162 | }
|
112 | 163 | ||
- | 164 | void InotifyEvent::DumpTypes(std::string& rStr) const |
|
- | 165 | {
|
|
- | 166 | DumpTypes((uint32_t) m_evt.mask, rStr); |
|
- | 167 | }
|
|
- | 168 | ||
113 | 169 | ||
114 | Inotify::Inotify() |
170 | Inotify::Inotify() |
115 | {
|
171 | {
|
116 | m_fd = inotify_init(); |
172 | m_fd = inotify_init(); |
117 | }
|
173 | }
|
Line 136... | Line 192... | ||
136 | return false; |
192 | return false; |
137 | 193 | ||
138 | pWatch->m_wd = inotify_add_watch(m_fd, pWatch->GetPath().c_str(), pWatch->GetMask()); |
194 | pWatch->m_wd = inotify_add_watch(m_fd, pWatch->GetPath().c_str(), pWatch->GetMask()); |
139 | if (pWatch->m_wd != -1) { |
195 | if (pWatch->m_wd != -1) { |
140 | m_watches.insert(IN_WATCH_MAP::value_type(pWatch->m_wd, pWatch)); |
196 | m_watches.insert(IN_WATCH_MAP::value_type(pWatch->m_wd, pWatch)); |
- | 197 | pWatch->m_pInotify = this; |
|
141 | return true; |
198 | return true; |
142 | }
|
199 | }
|
143 | 200 | ||
144 | return false; |
201 | return false; |
145 | }
|
202 | }
|
Line 150... | Line 207... | ||
150 | return; |
207 | return; |
151 | 208 | ||
152 | if (inotify_rm_watch(m_fd, pWatch->GetMask()) != -1) { |
209 | if (inotify_rm_watch(m_fd, pWatch->GetMask()) != -1) { |
153 | m_watches.erase(pWatch->m_wd); |
210 | m_watches.erase(pWatch->m_wd); |
154 | pWatch->m_wd = -1; |
211 | pWatch->m_wd = -1; |
- | 212 | pWatch->m_pInotify = NULL; |
|
155 | }
|
213 | }
|
156 | }
|
214 | }
|
157 | 215 | ||
158 | void Inotify::RemoveAll() |
216 | void Inotify::RemoveAll() |
159 | {
|
217 | {
|
160 | IN_WATCH_MAP::iterator it = m_watches.begin(); |
218 | IN_WATCH_MAP::iterator it = m_watches.begin(); |
161 | while (it != m_watches.end()) { |
219 | while (it != m_watches.end()) { |
- | 220 | InotifyWatch* pW = (*it).second; |
|
162 | inotify_rm_watch(m_fd, (*it).second->GetMask()); |
221 | inotify_rm_watch(m_fd, pW->GetMask()); |
- | 222 | pW->m_wd = -1; |
|
- | 223 | pW->m_pInotify = NULL; |
|
163 | it++; |
224 | it++; |
164 | }
|
225 | }
|
165 | 226 | ||
166 | m_watches.clear(); |
227 | m_watches.clear(); |
167 | }
|
228 | }
|
Line 178... | Line 239... | ||
178 | return false; |
239 | return false; |
179 | }
|
240 | }
|
180 | 241 | ||
181 | ssize_t i = 0; |
242 | ssize_t i = 0; |
182 | while (i < len) { |
243 | while (i < len) { |
- | 244 | InotifyWatch* pW = FindWatch(((struct inotify_event *) &m_buf[i])->wd); |
|
183 | InotifyEvent evt((struct inotify_event *) &m_buf[i]); |
245 | InotifyEvent evt((struct inotify_event *) &m_buf[i], pW); |
184 | m_events.push_back(evt); |
246 | m_events.push_back(evt); |
185 | i += INOTIFY_EVENT_SIZE + (int) evt.GetLength(); |
247 | i += INOTIFY_EVENT_SIZE + (int) evt.GetLength(); |
186 | }
|
248 | }
|
187 | 249 | ||
188 | return true; |
250 | return true; |