optris::sdk::view::ConfigWatcher
Polls a JSON config file for changes and reloads on modification.
Public functions
ConfigWatcher
ConfigWatcher(const std::filesystem::path &path)
Start watching path without reading it.
The constructor only records the file's current modification time. It never parses, so it cannot fail on a corrupt file, and a path that does not exist yet is not an error -- the watcher simply reports nothing until the file appears.
It starts in a first-check state, so the very first CheckAndReload() returns a config even though nothing has changed. That is the intended way to get the initial load; do not call ViewConfig::LoadOrDefault() as well or you parse twice.
The path is stored verbatim and cannot be changed afterwards. Watch a different file by constructing a new watcher.
CheckAndReload
std::optional< ViewConfig > CheckAndReload()
Returns a fresh ViewConfig if the file changed since the last check.
GetPath
const std::filesystem::path & GetPath() const
The path this watcher was constructed with, verbatim.
Neither canonicalized nor resolved against the working directory, so it is what to log or show a user rather than something to compare against a path obtained elsewhere. The reference is valid for the watcher's lifetime; the path never changes.