Watches filesystem paths using Linux inotify API and dispatches events through callbacks.
More...
#include <dfx-fdwatch/InotifyWatcher.hpp>
|
| using | Callback = std::move_only_function<void (fs::path, uint32_t)> |
| | Callback invoked when a watched path produces an inotify event.
|
|
| | InotifyWatcher (Poller &poller) |
| | Constructs an inotify watcher and registers its FD into poller.
|
|
| DFX_PRIVATE_STATE_DECLARE_RULE_OF_5 (InotifyWatcher) |
| int | addWatch (fs::path const &path, uint32_t mask, Callback cb) |
| | Adds an inotify watch for path with the provided mask.
|
| void | rmWatch (int idx) noexcept |
| | Removes a previously added watch.
|
|
| static std::vector< std::string > | maskToString (uint32_t mask) |
| | Converts an inotify mask to a list of human-readable flag names.
|
Watches filesystem paths using Linux inotify API and dispatches events through callbacks.
InotifyWatcher owns an inotify instance FD and registers it into a Poller. Call addWatch() to watch a specific path with a given inotify mask; when an event is received for that watch, the associated callback is invoked with:
- the event path (base watched path + optional name component),
- the raw inotify event mask.
Watches are tracked internally and can be removed using the returned watch identifier.
◆ Callback
Callback invoked when a watched path produces an inotify event.
- Parameters
-
| path | Path associated with the event. |
| mask | Raw inotify mask (e.g. IN_CREATE | IN_ISDIR). |
◆ InotifyWatcher()
| dfx::FdWatch::InotifyWatcher::InotifyWatcher |
( |
Poller & | poller | ) |
|
Constructs an inotify watcher and registers its FD into poller.
- Parameters
-
| poller | Poller used to monitor the inotify FD. |
◆ addWatch()
| int dfx::FdWatch::InotifyWatcher::addWatch |
( |
fs::path const & | path, |
|
|
uint32_t | mask, |
|
|
Callback | cb ) |
Adds an inotify watch for path with the provided mask.
The same path can be monitored multiple times using different callbacks. When the specified path triggered a masked event, the all associated callback will be invoked.
- Parameters
-
| path | Path to watch (file or directory). |
| mask | Inotify mask (e.g. IN_CREATE, IN_MODIFY, IN_DELETE, ...). |
| cb | Callback invoked for events matching this watch. |
- Returns
- An identifier for the created watch.
◆ maskToString()
| std::vector< std::string > dfx::FdWatch::InotifyWatcher::maskToString |
( |
uint32_t | mask | ) |
|
|
static |
Converts an inotify mask to a list of human-readable flag names.
This is intended for logging/debugging (e.g. converting IN_CREATE|IN_ISDIR to {"IN_CREATE", "IN_ISDIR"}).
- Parameters
-
- Returns
- Vector of strings describing the set bits in
mask.
◆ rmWatch()
| void dfx::FdWatch::InotifyWatcher::rmWatch |
( |
int | idx | ) |
|
|
noexcept |
Removes a previously added watch.
- Parameters
-
The documentation for this class was generated from the following file: