/* * Copyright (c) 2020, Itamar S. * Copyright (c) 2021, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace Core { struct FileWatcherEvent { enum class Type { Modified, ChildAdded, ChildRemoved, }; Type type; String child_path; }; class BlockingFileWatcher { AK_MAKE_NONCOPYABLE(BlockingFileWatcher); public: explicit BlockingFileWatcher(const String& path); ~BlockingFileWatcher(); Optional wait_for_event(); private: String m_path; int m_watcher_fd { -1 }; }; class FileWatcher : public RefCounted { AK_MAKE_NONCOPYABLE(FileWatcher); public: static Result, String> watch(const String& path); ~FileWatcher(); Function on_change; private: FileWatcher(NonnullRefPtr, const String& path); NonnullRefPtr m_notifier; String m_path; }; }