]> git.tdb.fi Git - libs/core.git/blobdiff - source/fs/unix/filemonitor_platform.h
Add a class for monitoring changes in files
[libs/core.git] / source / fs / unix / filemonitor_platform.h
diff --git a/source/fs/unix/filemonitor_platform.h b/source/fs/unix/filemonitor_platform.h
new file mode 100644 (file)
index 0000000..31b728f
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef MSP_FS_FILEMONITOR_PLATFORM_H_
+#define MSP_FS_FILEMONITOR_PLATFORM_H_
+
+namespace Msp {
+namespace FS {
+
+class INotify: public IO::EventObject
+{
+private:
+       IO::Handle fd;
+
+public:
+       INotify();
+       ~INotify();
+
+       int add_watch(const FS::Path &, int);
+       void remove_watch(int);
+
+       virtual void set_block(bool) { }
+       virtual void set_inherit(bool) { }
+
+protected:
+       virtual unsigned do_write(const char *, unsigned);
+       virtual unsigned do_read(char *, unsigned);
+
+public:
+       virtual const IO::Handle &get_handle(IO::Mode) { return fd; }
+       virtual const IO::Handle &get_event_handle() { return fd; }
+};
+
+
+struct FileMonitor::Private
+{
+       FileMonitor &monitor;
+       INotify inotify;
+
+       Private(FileMonitor &);
+
+       void events_available();
+};
+
+} // namespace FS
+} // namespace Msp
+
+#endif