dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
dfx::FdWatch::InotifyWatcher Class Reference

Watches filesystem paths using Linux inotify API and dispatches events through callbacks. More...

#include <dfx-fdwatch/InotifyWatcher.hpp>

Public Types

using Callback = std::move_only_function<void (fs::path, uint32_t)>
 Callback invoked when a watched path produces an inotify event.

Public Member Functions

 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 Public Member Functions

static std::vector< std::string > maskToString (uint32_t mask)
 Converts an inotify mask to a list of human-readable flag names.

Detailed Description

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.

Member Typedef Documentation

◆ Callback

using dfx::FdWatch::InotifyWatcher::Callback = std::move_only_function<void (fs::path, uint32_t)>

Callback invoked when a watched path produces an inotify event.

Parameters
pathPath associated with the event.
maskRaw inotify mask (e.g. IN_CREATE | IN_ISDIR).

Constructor & Destructor Documentation

◆ InotifyWatcher()

dfx::FdWatch::InotifyWatcher::InotifyWatcher ( Poller & poller)

Constructs an inotify watcher and registers its FD into poller.

Parameters
pollerPoller used to monitor the inotify FD.

Member Function Documentation

◆ 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
pathPath to watch (file or directory).
maskInotify mask (e.g. IN_CREATE, IN_MODIFY, IN_DELETE, ...).
cbCallback 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
maskRaw inotify mask.
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
idxWatch identifier returned by addWatch().

The documentation for this class was generated from the following file: