qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::io::async::directory_watcher< _Derived > Class Template Reference

CRTP base class for watching a directory for attribute changes. More...

#include <io.h>

Inheritance diagram for qb::io::async::directory_watcher< _Derived >:
Collaboration diagram for qb::io::async::directory_watcher< _Derived >:

Public Types

using base_io_t = directory_watcher<_Derived>
 Base I/O type alias for CRTP.

Public Member Functions

 directory_watcher ()=default
 Default constructor.
 ~directory_watcher ()=default
 Destructor.
void start (std::string const &fpath, ev_tstamp ts=0.1) noexcept
 Starts watching a directory for attribute changes.
void disconnect () noexcept
 Stops watching the directory.

Static Public Attributes

static constexpr const bool do_read = false
 Flag indicating this watcher type does not read directory content directly.

Additional Inherited Members

Protected Member Functions inherited from qb::io::async::base< directory_watcher< _Derived >, event::file >
 base ()
 Constructor that registers the event watcher with the current listener.
 ~base ()
 Destructor that unregisters the event watcher.
Protected Attributes inherited from qb::io::async::base< directory_watcher< _Derived >, event::file >
event::file & _async_event
 Reference to the registered libev-based event watcher.

Detailed Description

template<typename _Derived>
class qb::io::async::directory_watcher< _Derived >

CRTP base class for watching a directory for attribute changes.

This template class uses an event::file (wrapping ev::stat) to monitor a specified directory path for changes in its attributes. Unlike file_watcher, it generally does not read directory contents itself but notifies the derived class of changes.

Template Parameters
_DerivedThe derived class type (CRTP pattern) that handles the on(event::file&) notification.

Member Function Documentation

◆ start()

template<typename _Derived>
void qb::io::async::directory_watcher< _Derived >::start ( std::string const & fpath,
ev_tstamp ts = 0.1 )
inlinenoexcept

Starts watching a directory for attribute changes.

Parameters
fpathPath to the directory to watch.
tsPolling interval in seconds for checking changes. Default is 0.1 seconds.

Initializes and starts the underlying ev::stat watcher for the specified directory path. The on(event::file&) handler will be called when changes to the directory's attributes are detected.

◆ disconnect()

template<typename _Derived>
void qb::io::async::directory_watcher< _Derived >::disconnect ( )
inlinenoexcept

Stops watching the directory.

Stops the underlying ev::stat watcher. No more file events for this directory will be generated.