Brenta Engine 1.2
Loading...
Searching...
No Matches
fswatcher.hpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#pragma once
7
8#include <tenno/vector.hpp>
9
10#include <filesystem>
11#include <optional>
12
13namespace brenta
14{
15
16//
17// Filesystem Watcher
18// ------------------
19//
20// Watch for events on files in the filesystem. Make sure you
21// initialize and destroy this object before using it.
22//
23// The API is really simple, you `add(..)` and `rm(..)` the paths
24// you want to monitor, then call `watch()` and wait for events.
25// Watch will return a path where an event occurred. If it does
26// not return anything, then this object was destroyed or an error
27// was encountered while waiting.
28//
30{
31public:
32
33 enum Event
34 {
35 Modify,
36 };
37
38 FilesystemWatcher() = default;
40
41 bool init();
42 void destroy();
43
44 bool add(const std::filesystem::path &path,
45 tenno::vector<Event> events);
46 bool add(const tenno::vector<std::filesystem::path> &paths,
47 tenno::vector<Event> events);
48
49 bool rm(const std::filesystem::path &path);
50 bool rm(const tenno::vector<std::filesystem::path> &path);
51
52 // Blocks and returns the path that received a notification
53 std::optional<std::filesystem::path> watch();
54
55private:
56
57 void* internal = nullptr; // used internally
58
59};
60
61} // namespace brenta