30 #ifndef FSW__MONITOR_H 31 # define FSW__MONITOR_H 36 # ifdef HAVE_CXX_MUTEX 43 # include "../c/cmonitor.h" 200 void set_property(
const std::string& name,
const std::string& value);
210 void set_properties(
const std::map<std::string, std::string> options);
316 void set_filters(
const std::vector<monitor_filter>& filters);
423 const std::vector<fsw_event_type_filter>& filters);
502 virtual void run() = 0;
592 # ifdef HAVE_CXX_MUTEX 606 std::chrono::milliseconds get_latency_ms()
const;
607 std::vector<compiled_monitor_filter> filters;
608 std::vector<fsw_event_type_filter> event_type_filters;
610 #ifdef HAVE_CXX_MUTEX 611 # ifdef HAVE_CXX_ATOMIC 612 # define HAVE_INACTIVITY_CALLBACK 613 static void inactivity_callback(
monitor *mon);
614 mutable std::atomic<std::chrono::milliseconds> last_notification;
void set_event_type_filters(const std::vector< fsw_event_type_filter > &filters)
Set the event type filters.
Definition: monitor.cpp:117
void * context
Pointer to context data that will be passed to the monitor::callback.
Definition: monitor.hpp:542
fsw_event_flag
Backend-agnostic change flags.
Definition: cevent.h:63
Base class of all monitors.
Definition: monitor.hpp:146
std::mutex run_mutex
Mutex used to serialize access to the monitor state from multiple threads.
Definition: monitor.hpp:597
void start()
Start the monitor.
Definition: monitor.cpp:273
bool allow_overflow
If true, queue overflow events will be notified to the caller, otherwise the monitor will throw a lib...
Definition: monitor.hpp:560
Main namespace of libfswatch.
Definition: event.cpp:23
void set_follow_symlinks(bool follow)
Follow symlinks.
Definition: monitor.cpp:169
bool should_stop
Flag indicating whether the monitor should preemptively stop.
Definition: monitor.hpp:590
monitor & operator=(const monitor &that)=delete
This class is not copy assignable.
bool watch_access
Flag indicating whether file access should be watched.
Definition: monitor.hpp:580
Definition: monitor.cpp:37
std::string get_property(std::string name)
Gets the value of a property.
Definition: monitor.cpp:156
void notify_overflow(const std::string &path) const
Notify an overflow event.
Definition: monitor.cpp:336
bool accept_path(const std::string &path) const
Check whether a path should be accepted.
Definition: monitor.cpp:197
Type representing a file change event.
Definition: event.hpp:47
bool accept_event_type(fsw_event_flag event_type) const
Check whether an event should be accepted.
Definition: monitor.cpp:179
void set_filters(const std::vector< monitor_filter > &filters)
Set the path filters.
Definition: monitor.cpp:161
std::mutex notify_mutex
Mutex used to serialize access to the notify_events() method.
Definition: monitor.hpp:602
void set_properties(const std::map< std::string, std::string > options)
Sets the custom properties.
Definition: monitor.cpp:151
void set_directory_only(bool directory_only)
Watch directories only.
Definition: monitor.cpp:106
bool recursive
If true, directories will be scanned recursively.
Definition: monitor.hpp:565
void set_allow_overflow(bool overflow)
Notify buffer overflows as change events.
Definition: monitor.cpp:75
Event type filter.
Definition: cfilter.h:55
double latency
Latency of the monitor.
Definition: monitor.hpp:547
std::vector< fsw_event_flag > filter_flags(const event &evt) const
Filter event types.
Definition: monitor.cpp:321
void add_filter(const monitor_filter &filter)
Add a path filter.
Definition: monitor.cpp:124
std::map< std::string, std::string > properties
Map of custom properties.
Definition: monitor.hpp:530
void * get_context() const
Get the pointer to the context data.
Definition: monitor.cpp:214
bool follow_symlinks
If true, symbolic links are followed.
Definition: monitor.hpp:570
bool is_running()
Check whether the monitor is running.
Definition: monitor.cpp:315
void set_context(void *context)
Set the context data.
Definition: monitor.cpp:219
void set_watch_access(bool access)
Monitor file access.
Definition: monitor.cpp:174
void notify_events(const std::vector< event > &events) const
Notify change events.
Definition: monitor.cpp:346
bool fire_idle_event
If true, the monitor will notify an event when idle.
Definition: monitor.hpp:554
void set_recursive(bool recursive)
Recursively scan subdirectories.
Definition: monitor.cpp:101
Header of the fsw::event class.
virtual void run()=0
Execute monitor loop.
virtual void on_stop()
Execute an implementation-specific stop handler.
Definition: monitor.cpp:382
virtual ~monitor()
Destructs a monitor instance.
Definition: monitor.cpp:224
std::vector< std::string > paths
List of paths to watch.
Definition: monitor.hpp:522
void set_fire_idle_event(bool fire_idle_event)
Sets the fire idle event flag.
Definition: monitor.cpp:91
monitor(std::vector< std::string > paths, FSW_EVENT_CALLBACK *callback, void *context=nullptr)
Constructs a monitor watching the specified paths.
Definition: monitor.cpp:57
bool directory_only
Flag indicating whether only directories should be monitored.
Definition: monitor.hpp:575
void set_latency(double latency)
Sets the latency.
Definition: monitor.cpp:80
FSW_EVENT_CALLBACK * callback
Callback to which change events should be notified.
Definition: monitor.hpp:537
void stop()
Stop the monitor.
Definition: monitor.cpp:302
void FSW_EVENT_CALLBACK(const std::vector< event > &, void *)
Function definition of an event callback.
Definition: monitor.hpp:60
Header of the fsw::monitor_filter class.
Path filters used to accept or reject file change events.
Definition: filter.hpp:58
void set_property(const std::string &name, const std::string &value)
Sets a custom property.
Definition: monitor.cpp:146
bool running
Flag indicating whether the monitor is in the running state.
Definition: monitor.hpp:585
void add_event_type_filter(const fsw_event_type_filter &filter)
Add an event type filter.
Definition: monitor.cpp:111