59 lines
1.6 KiB
C++
59 lines
1.6 KiB
C++
#include "INotify.h"
|
|
#include "Log.h"
|
|
|
|
namespace core {
|
|
|
|
INotify::INotify(EPoll &ePoll) : Socket(ePoll, "INotify") {
|
|
setDescriptor(inotify_init());
|
|
}
|
|
|
|
INotify::~INotify() {
|
|
shutdown();
|
|
}
|
|
|
|
int INotify::addWatch(std::string watch) {
|
|
return inotify_add_watch(getDescriptor(), watch.c_str(), IN_ALL_EVENTS);
|
|
}
|
|
|
|
void INotify::removeWatch(int wd) {
|
|
inotify_rm_watch(getDescriptor(), wd);
|
|
}
|
|
|
|
void INotify::onDataReceived(char *buffer, int len) {
|
|
const struct inotify_event *event;
|
|
char *ptr;
|
|
for (ptr = buffer; ptr < buffer + len;
|
|
ptr += sizeof(struct inotify_event) + event->len) {
|
|
event = (const struct inotify_event *) ptr;
|
|
|
|
if(event->mask & IN_ACCESS)
|
|
inAccess(std::string(event->name));
|
|
if(event->mask & IN_ATTRIB)
|
|
inAttrib(std::string(event->name));
|
|
if(event->mask & IN_CLOSE_WRITE)
|
|
inCloseWrite(std::string(event->name));
|
|
if(event->mask & IN_CLOSE_NOWRITE)
|
|
inCloseNoWrite(std::string(event->name));
|
|
if(event->mask & IN_CREATE)
|
|
inCreate(std::string(event->name));
|
|
if(event->mask & IN_DELETE)
|
|
inDelete(std::string(event->name));
|
|
if(event->mask & IN_DELETE_SELF)
|
|
inDeleteSelf(std::string(event->name));
|
|
if(event->mask & IN_MODIFY)
|
|
inModify(std::string(event->name));
|
|
if(event->mask & IN_MOVE_SELF)
|
|
inMoveSelf(std::string(event->name));
|
|
if(event->mask & IN_MOVED_FROM)
|
|
inMovedFrom(std::string(event->name));
|
|
if(event->mask & IN_MOVED_TO)
|
|
inMovedTo(std::string(event->name));
|
|
if(event->mask & IN_OPEN)
|
|
inOpen(std::string(event->name));
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|