--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/FileMonitor.h Sat Dec 02 15:02:56 2023 +0100
@@ -0,0 +1,70 @@
+/**
+ * ShaderShark
+ * Copyright © 2023 František Kučera (Frantovo.cz, GlobalCode.info)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <string>
+#include <memory>
+
+class FileMonitor;
+
+class WatchedFile {
+public:
+ class Impl;
+ WatchedFile();
+ virtual ~WatchedFile();
+ std::string getFileName() const;
+ uint32_t getMask() const;
+ FileMonitor getFileMonitor() const;
+private:
+ std::shared_ptr<Impl> impl;
+ friend FileMonitor;
+};
+
+class FileEvent {
+public:
+ std::string fileName;
+ uint32_t mask;
+ // TODO: more information, see: man 7 inotify
+};
+
+class FileMonitor {
+public:
+ class Impl;
+ FileMonitor();
+ virtual ~FileMonitor();
+ /**
+ * @return file descriptor that can be monitored by e.g. epoll
+ */
+ int getFD() const;
+ /**
+ * @param fileName file to be monitored
+ * @param mask IN_CLOSE_WRITE and other IN_*
+ * @return monitoring will continue until any copy of this object exists
+ */
+ WatchedFile watch(const std::string& fileName);
+ WatchedFile watch(const std::string& fileName, uint32_t mask);
+ /**
+ * @param event object to be filled with information
+ * @return true if event was filled, call this method until false returned
+ */
+ bool readEvent(FileEvent& event);
+private:
+ std::shared_ptr<Impl> impl;
+ FileMonitor(std::shared_ptr<Impl> impl);
+ friend WatchedFile;
+};