Class FileSystemWatcher#

Class Documentation#

class FileSystemWatcher#

Public Types

using EventCallbackFn = std::function<void(Events::Event&)>#

Describes a callback function which gets called when a event occurs.

Public Functions

explicit FileSystemWatcher(bool recursive = true, std::string debugName = "")#

Keeps track of the status of all files and folders inside the added folders.

Remark

Windows: Event based via ReadDirectoryChangesW.

Remark

Linux: Event-based via inotify and eventfd.

Note

This class uses an extra thread for tracking files and folders.

Parameters:
  • recursive – Whether to also include sub-folders recursively.

  • debugName – Name for the file watcher.

~FileSystemWatcher() = default#

Destructor.

consteval FileSystemWatcher(const FileSystemWatcher&) noexcept = delete#

Copy constructor.

consteval FileSystemWatcher(FileSystemWatcher&&) noexcept = delete#

Move constructor.

consteval FileSystemWatcher &operator=(const FileSystemWatcher&) noexcept = delete#

Copy assignment operator.

consteval FileSystemWatcher &operator=(FileSystemWatcher&&) noexcept = delete#

Move assignment operator.

void SetEventCallback(const EventCallbackFn &callback)#

Sets the callback function that is called when a filesystem change event occurs.

Thread safety

This function may be called from any thread.

Note

The callback must be threadsafe

Parameters:

callback – Callback function used to report events to.

EventCallbackFn GetEventCallback() const#

Get the function to call when an filesystem change event occurred.

Thread safety

This function may be called from any thread.

Returns:

EventCallbackFn.

std::future<void> AddFolder(const std::filesystem::path &path)#

Adds a new folder path to the tracked paths.

Thread safety

This function may be called from any thread.

Parameters:

path – Folder path to track.

Returns:

Future which can be used to wait for the changes to take effect.

std::future<void> AddFolders(std::vector<std::filesystem::path> paths)#

Adds new folder paths to the tracked paths.

Thread safety

This function may be called from any thread.

Parameters:

paths – Folder paths to track.

Returns:

Future which can be used to wait for the changes to take effect.

void RemoveFolder(const std::filesystem::path &path)#

Removes a folder path from the tracked paths.

Thread safety

This function may be called from any thread.

Parameters:

path – Folder path to untrack.

void RemoveFolders(std::span<const std::filesystem::path> paths)#

Removes folder paths from the tracked paths.

Thread safety

This function may be called from any thread.

Parameters:

paths – Folder paths to untrack.

constexpr std::vector<std::filesystem::path> GetFolders() const noexcept#

Returns the paths that are being watched.

Thread safety

This function may be called from any thread.

Note

If recursive watching is enabled then there may be additional paths being tracked which aren’t part of this list.

Returns:

The paths that are being watched.