diff options
| author | vaxerski <vaxry@vaxry.net> | 2025-01-19 15:39:19 +0100 |
|---|---|---|
| committer | vaxerski <vaxry@vaxry.net> | 2025-01-19 16:11:12 +0100 |
| commit | 8dd2cd41fb4c5a5eb6886cc190419b36084cabfa (patch) | |
| tree | 713dfeb4f2bf75c2a04ed93166b5f9109dac9a84 /src/config/ConfigWatcher.hpp | |
| parent | 0a0e56d99c3b5f900ec561b3fe9a3c8a64fe1217 (diff) | |
core: move to inotify for monitoring the config files
instead of manually polling every second which is not efficient, use inotify.
an added bonus is that inotify is much much faster
Diffstat (limited to 'src/config/ConfigWatcher.hpp')
| -rw-r--r-- | src/config/ConfigWatcher.hpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/config/ConfigWatcher.hpp b/src/config/ConfigWatcher.hpp new file mode 100644 index 00000000..0a698fc8 --- /dev/null +++ b/src/config/ConfigWatcher.hpp @@ -0,0 +1,32 @@ +#pragma once +#include <memory> +#include <vector> +#include <string> +#include <functional> + +class CConfigWatcher { + public: + CConfigWatcher(); + ~CConfigWatcher(); + + struct SConfigWatchEvent { + std::string file; + }; + + int getInotifyFD(); + void setWatchList(const std::vector<std::string>& paths); + void setOnChange(const std::function<void(const SConfigWatchEvent&)>& fn); + void onInotifyEvent(); + + private: + struct SInotifyWatch { + int wd = -1; + std::string file; + }; + + std::function<void(const SConfigWatchEvent&)> m_watchCallback; + std::vector<SInotifyWatch> m_watches; + int m_inotifyFd = -1; +}; + +inline std::unique_ptr<CConfigWatcher> g_pConfigWatcher = std::make_unique<CConfigWatcher>();
\ No newline at end of file |
