Notifies about events (add, remove, rename, modified) on files and directories. More...
#include <FileSystemWatcher.h>
Classes | |
struct | EventLoopRunner |
Delivers notifications using Async (SC::AsyncEventLoop). More... | |
struct | FolderWatcher |
Represents a single folder being watched. More... | |
struct | Notification |
Notification holding type and path. More... | |
Public Types | |
enum class | Operation { Modified , AddRemoveRename } |
Specifies the event classes. More... | |
using | ThreadRunner = OpaqueObject< ThreadRunnerDefinition > |
Delivers notifications on a background thread. More... | |
Public Member Functions | |
Result | init (ThreadRunner &runner) |
Setup watcher to receive notifications from a background thread. More... | |
Result | init (EventLoopRunner &runner, AsyncEventLoop &eventLoop) |
Setup watcher to receive async notifications on SC::AsyncEventLoop. More... | |
Result | close () |
Stops all watchers and frees the ThreadRunner or EventLoopRunner passed in init. More... | |
Result | watch (FolderWatcher &watcher, StringView path) |
Starts watching a single directory, calling FolderWatcher::notifyCallback on file events. More... | |
Friends | |
decltype(internal) friend decltype(FolderWatcher::internal) IntrusiveDoubleLinkedList< FolderWatcher > | watchers |
Notifies about events (add, remove, rename, modified) on files and directories.
Caller can specify a callback for receiving notifications the SC::FileSystemWatcher::watch method.
Changes are grouped in two categories:
There are two modes in which FileSystemWatcher can be initialized, defining how notifications are delivered:
Mode | Description |
---|---|
SC::FileSystemWatcher::ThreadRunner | Delivers notifications on a background thread. |
SC::FileSystemWatcher::EventLoopRunner | Delivers notifications using Async (SC::AsyncEventLoop). |
Example using SC::FileSystemWatcher::EventLoopRunner:
Example using SC::FileSystemWatcher::ThreadRunner:
using SC::FileSystemWatcher::ThreadRunner = OpaqueObject<ThreadRunnerDefinition> |
Delivers notifications on a background thread.
|
strong |
Specifies the event classes.
Some events are grouped in a single one because it's non-trivial providing precise notifications that are consistent across platforms.
Enumerator | |
---|---|
Modified | A file or directory has been modified in its contents and/or timestamp. |
AddRemoveRename | A file or directory has been added, removed or renamed. |
Result SC::FileSystemWatcher::close | ( | ) |
Stops all watchers and frees the ThreadRunner or EventLoopRunner passed in init.
Result SC::FileSystemWatcher::init | ( | EventLoopRunner & | runner, |
AsyncEventLoop & | eventLoop | ||
) |
Setup watcher to receive async notifications on SC::AsyncEventLoop.
runner | Address of a ThreadRunner object that must be valid until close() |
eventLoop | A valid AsyncEventLoop |
Result SC::FileSystemWatcher::init | ( | ThreadRunner & | runner | ) |
Result SC::FileSystemWatcher::watch | ( | FolderWatcher & | watcher, |
StringView | path | ||
) |
Starts watching a single directory, calling FolderWatcher::notifyCallback on file events.
watcher | Reference to a (not already used) watcher, with a valid FolderWatcher::notifyCallback. Its address must not change until FolderWatcher::stopWatching or FileSystemWatcher::close |
path | The directory being monitored |