fswatch  1.14.0
C++ API

The C++ API provides users an easy to use, object-oriented interface to a wide range of file monitoring APIs. This API provides a common facade to a set of heterogeneous APIs that not only greatly simplifies their usage, but provides an indirection layer that makes applications more portable: as far as there is an available monitor in another platform, an existing application will just work.

In reality, a monitor may have platform-specific behaviours that should be taken into account when writing portable applications using this library. This differences complicate the task of writing portable applications that are truly independent of the file monitoring API they may be using. However, monitors try to ‘compensate’ for any behavioural difference across implementations.

The fsw::monitor class is the basic type of the C++ API: it defines the interface of every monitor and provides common functionality to inheritors of this class, such as:

Usage

The typical usage pattern of this API is similar to the following:

Example

// Create the default platform monitor
monitor *active_monitor =
  monitor_factory::create_monitor(fsw_monitor_type::system_default_monitor_type,
                                  paths,
                                  process_events);

// Configure the monitor
active_monitor->set_properties(monitor_properties);
active_monitor->set_allow_overflow(allow_overflow);
active_monitor->set_latency(latency);
active_monitor->set_recursive(recursive);
active_monitor->set_directory_only(directory_only);
active_monitor->set_event_type_filters(event_filters);
active_monitor->set_filters(filters);
active_monitor->set_follow_symlinks(follow_symlinks);
active_monitor->set_watch_access(watch_access);

// Start the monitor
active_monitor->start();