### start Method Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1fen__monitor-members.html Starts the file system monitoring process. ```APIDOC ## start() ### Description Starts the file system monitoring process. This method initiates the watching of specified paths for changes. ``` -------------------------------- ### Create and Start Basic Monitoring Session Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/c-api.html Creates a monitoring session, adds a path to watch, sets a callback function for events, and starts the monitor. Assumes library initialization has already occurred. ```c // Initialize the library fsw_init_library(); // Use the default monitor. const FSW_HANDLE handle = fsw_init_session(); fsw_add_path(handle, "my/path"); fsw_set_callback(handle, my_callback); fsw_start_monitor(handle); ``` -------------------------------- ### Starting Monitoring Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/libfswatch_8h.html Starts the file system monitoring process for the configured session. ```APIDOC ## fsw_start_monitor ### Description Starts the file system monitoring process. ### Parameters - **handle** (FSW_HANDLE): The handle to the monitoring session. ### Returns - FSW_STATUS: Returns FSW_STATUS_SUCCESS on success, or an error code on failure. ``` -------------------------------- ### Create, Configure, and Start fswatch Monitor Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/cpp-api.html Demonstrates the typical usage pattern for the fswatch C++ API: creating a monitor via the factory, configuring its properties, and starting the monitoring process. Ensure all necessary paths, event processing callbacks, and configuration options are correctly provided. ```cpp // 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_prune_filters(prune_filters); active_monitor->set_follow_symlinks(follow_symlinks); active_monitor->set_watch_access(watch_access); // Start the monitor active_monitor->start(); ``` -------------------------------- ### fsw::kqueue_monitor::run Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1kqueue__monitor-members.html Starts the monitoring loop for the kqueue_monitor. ```APIDOC ## run() ### Description Starts the event monitoring loop for the `kqueue_monitor`. This method is intended to be run in a separate thread or as part of the main event loop. ### Method protected virtual ### Returns This method does not return a value. ``` -------------------------------- ### Start Monitor Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/c-api.html Starts the monitoring process for the session. This function blocks until the monitor is stopped. ```APIDOC ## Start Monitor ### Description Starts the file system monitoring process for the given session. This function typically blocks and processes events until the monitor is stopped or an error occurs. ### Function Signature ```c FSW_STATUS fsw_start_monitor(FSW_HANDLE handle); ``` ### Parameters #### Path Parameters - **handle** (`FSW_HANDLE`): The handle of the monitoring session. ### Return Value - `FSW_OK` on successful start and completion (if not blocking indefinitely). - An error code if the monitor fails to start or encounters an error during operation. ### Example ```c fsw_start_monitor(handle); ``` ``` -------------------------------- ### run override Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1fsevents__monitor-members.html Starts the event monitoring loop for fsevents_monitor. ```APIDOC ## run() override ### Description Starts the event monitoring loop for fsevents_monitor. This method is called when the monitor is started and runs until stopped. ``` -------------------------------- ### Monitor Creation and Configuration Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/cpp-api.html Demonstrates how to create a platform-specific monitor using the factory, configure its properties, and start the monitoring process. ```APIDOC ## Monitor Creation and Configuration ### Description This example shows the typical usage pattern for the fswatch C++ API, including creating a monitor via the factory, setting various configuration properties, and starting the monitor. ### Usage ```cpp // 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_prune_filters(prune_filters); active_monitor->set_follow_symlinks(follow_symlinks); active_monitor->set_watch_access(watch_access); // Start the monitor active_monitor->start(); ``` ### Methods - `monitor_factory::create_monitor`: Creates a monitor instance. - `monitor::set_properties`: Sets general monitor properties. - `monitor::set_allow_overflow`: Configures overflow handling. - `monitor::set_latency`: Sets the latency for event reporting. - `monitor::set_recursive`: Enables or disables recursive monitoring. - `monitor::set_directory_only`: Restricts monitoring to directories. - `monitor::set_event_type_filters`: Filters events by type. - `monitor::set_filters`: Applies path filters. - `monitor::set_prune_filters`: Applies prune filters. - `monitor::set_follow_symlinks`: Configures symbolic link following. - `monitor::set_watch_access`: Enables watching for access events. - `monitor::start`: Starts the file system monitoring. ### Parameters - `fsw_monitor_type::system_default_monitor_type`: Specifies the type of monitor to create. - `paths`: A collection of paths to monitor. - `process_events`: A callback function to process events. - `monitor_properties`: Properties for the monitor. - `allow_overflow`: Boolean to allow overflow. - `latency`: Time interval for latency. - `recursive`: Boolean to enable recursive monitoring. - `directory_only`: Boolean to monitor only directories. - `event_filters`: Filters for event types. - `filters`: Path filters. - `prune_filters`: Prune filters. - `follow_symlinks`: Boolean to follow symbolic links. - `watch_access`: Boolean to watch for access events. ``` -------------------------------- ### fsw_start_monitor Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/globals_func.html Starts the file system monitoring. This function is declared in libfswatch.h and implemented in libfswatch.cpp. ```APIDOC ## fsw_start_monitor ### Description Starts the file system monitoring. ### Declaration libfswatch.cpp, libfswatch.h ``` -------------------------------- ### fsw::monitor::start Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/monitor_8hpp_source.html Starts the file system monitor. This method should be called after configuring the monitor's properties and filters. ```APIDOC ## fsw::monitor::start ### Description Starts the file system monitor. ### Method void start() ### Definition monitor.cpp:340 ``` -------------------------------- ### fsw::monitor::start() Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1monitor.html Starts the monitor, marking its state as running and initiating the watching of change events. This function blocks until the monitor is stopped. ```APIDOC ## start() ### Description Starts the monitor. The monitor status is marked as _running_ and it starts watching for change events. This function performs the following tasks: * Atomically marks the thread state as _running_ , locking on monitor::run_mutex. * Calls the run() function: the monitor::run_mutex is **not** locked during this call. * When run() returns, it atomically marks the thread state as _stopped_ , locking on monitor::run_mutex. This call does _not_ return until the monitor is stopped and events are notified from its thread. State changes are performed thread-safely locking on monitor::run_mutex. ### See Also run() stop() ### Method void fsw::monitor::start() ``` -------------------------------- ### Display fswatch Version Source: https://emcrisostomo.github.io/fswatch/documentation.html Use this command to check the installed version of fswatch. ```bash $ fswatch --version fswatch 1.21.0 ``` -------------------------------- ### fsw::poll_monitor::run Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1poll__monitor-members.html Starts the monitoring process for file system events. ```APIDOC ## run() override ### Description Executes the main monitoring loop for the `poll_monitor`. This method is intended to be called after the monitor has been configured and started. ### Method `protected virtual` ### Overrides `fsw::monitor::run` ``` -------------------------------- ### Session Management Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/libfswatch_8h_source.html Functions for initializing, starting, and destroying monitoring sessions. ```APIDOC ## fsw_init_session ### Description Initializes a new file system monitoring session. ### Method `fsw_init_session` ### Parameters - **type** (enum fsw_monitor_type) - The type of monitor to initialize. ### Returns - FSW_HANDLE - A handle to the newly created session, or NULL on failure. ``` ```APIDOC ## fsw_start_monitor ### Description Starts monitoring for file system events on a given session. ### Method `fsw_start_monitor` ### Parameters - **handle** (FSW_HANDLE) - The handle to the monitoring session. ### Returns - FSW_STATUS - FSW_OK on success, or an error code on failure. ``` ```APIDOC ## fsw_destroy_session ### Description Destroys a file system monitoring session and releases associated resources. ### Method `fsw_destroy_session` ### Parameters - **handle** (FSW_HANDLE) - The handle to the monitoring session to destroy. ### Returns - FSW_STATUS - FSW_OK on success, or an error code on failure. ``` -------------------------------- ### fsw_start_monitor Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/libfswatch_8h.html Starts the file system monitor associated with the given handle. The behavior of this function can vary depending on the monitor type. ```APIDOC ## fsw_start_monitor() ### Description Starts the file system monitor associated with the given handle. The behavior of this function can vary depending on the monitor type. This call might return when a monitor is stopped or not, depending on its configuration. ### Signature `FSW_STATUS fsw_start_monitor(const FSW_HANDLE _handle_)` ### Parameters * **_handle_** (const FSW_HANDLE) - Required - A handle to the configured file system monitor. ### Return Value * **FSW_STATUS** - Indicates the success or failure of starting the monitor. ``` -------------------------------- ### run Method Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1fen__monitor-members.html Starts the monitoring process. This method overrides the base class's run method and is responsible for the main monitoring loop. ```APIDOC ## run() override ### Description Starts the monitoring loop for the `fen_monitor`. This method overrides the base class's `run` method. ### Method `protected virtual` ``` -------------------------------- ### fsw::fanotify_monitor::run Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/fanotify__monitor_8hpp_source.html Starts the monitor's event loop, continuously processing file system events until the monitor is stopped. ```APIDOC ## fsw::fanotify_monitor::run ### Description Executes the monitor's main event processing loop. This method is intended to be called to start monitoring for file system events. It will block until the monitor is stopped. ### Signature void run() override ### Remarks This method overrides the `run` method from the base `monitor` class. ``` -------------------------------- ### Monitor Lifecycle Control Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/monitor_8hpp_source.html Methods to start, stop, and check the running status of the file system monitor. ```APIDOC ## Start Monitor ### Description Starts the file system monitoring process. This method typically blocks until the monitor is stopped. ### Signature `void start();` ## Stop Monitor ### Description Stops the file system monitoring process. ### Signature `void stop();` ## Is Running ### Description Checks if the monitor is currently running. ### Signature `bool is_running();` ### Returns `true` if the monitor is running, `false` otherwise. ``` -------------------------------- ### run Override Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1inotify__monitor-members.html Starts the inotify monitoring process, overriding the base class's run method. ```APIDOC ## run() override ### Description Starts the inotify monitoring loop. This method overrides the base class's run method and is responsible for processing file system events. ### Method override ``` -------------------------------- ### Monitor Configuration Properties Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/monitor_8hpp_source.html Methods for setting and getting various properties of the monitor, controlling its behavior and filtering capabilities. ```APIDOC ## Set Property ### Description Sets a specific property of the monitor. ### Signature `void set_property(const std::string& name, const std::string& value);` ### Parameters - **name** (const std::string&) - The name of the property to set. - **value** (const std::string&) - The value to set for the property. ## Set Properties ### Description Sets multiple properties of the monitor at once. ### Signature `void set_properties(const std::map options); ` ### Parameters - **options** (const std::map&) - A map where keys are property names and values are their corresponding values. ## Get Property ### Description Retrieves the value of a specific property. ### Signature `std::string get_property(std::string name); ` ### Parameters - **name** (std::string) - The name of the property to retrieve. ### Returns The value of the specified property as a string. ``` -------------------------------- ### fsw::windows_monitor::run Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1windows__monitor-members.html Starts the monitoring process for the windows_monitor. This protected virtual function is responsible for the main event loop of the monitor on Windows systems. ```APIDOC ## run() ### Description Executes the main monitoring loop specific to the Windows operating system. This method is called internally to start processing file system events. ### Remarks This is a protected virtual function, intended to be overridden by derived classes or called by the base class's internal mechanisms. ``` -------------------------------- ### Basic Monitor run() Method Implementation Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1monitor.html This skeleton demonstrates a typical implementation of the run() method for a monitor. It includes API initialization, an event loop with thread safety checks, path scanning, event waiting, filtering, and notification. ```cpp void run() { initialize_api(); for (;;) { unique_lock run_guard(run_mutex); if (should_stop) break; run_guard.unlock(); scan_paths(); wait_for_events(); vector evts = get_changes(); vector events; for (auto & evt : evts) { if (accept(evt.get_path)) { events.push_back({event from evt}); } } if (events.size()) notify_events(events); } terminate_api(); } ``` -------------------------------- ### get_property Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1fanotify__monitor.html Gets the value of a specified property. ```APIDOC ## std::string get_property(std::string name) ### Description Gets the value of a property. ### Parameters * **name** (std::string) - The name of the property to retrieve. ### Returns std::string - The value of the specified property. ``` -------------------------------- ### Library Initialization and Session Management Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/libfswatch_8h_source.html Functions for initializing the libfswatch library and creating/destroying monitoring sessions. ```APIDOC ## fsw_init_library ### Description Initializes the libfswatch library. This function must be called before any other libfswatch functions. ### Method `FSW_STATUS fsw_init_library(void);` ### Returns - `FSW_STATUS`: Indicates success or failure of the initialization. ## fsw_init_session ### Description Initializes a new file system monitoring session. ### Method `FSW_HANDLE fsw_init_session(const enum fsw_monitor_type type);` ### Parameters - `type` (enum fsw_monitor_type): The type of monitor to initialize. ### Returns - `FSW_HANDLE`: A handle to the newly created session, or NULL on failure. ## fsw_destroy_session ### Description Destroys a file system monitoring session and releases associated resources. ### Method `FSW_STATUS fsw_destroy_session(const FSW_HANDLE handle);` ### Parameters - `handle` (FSW_HANDLE): The handle of the session to destroy. ### Returns - `FSW_STATUS`: Indicates success or failure of the destruction. ``` -------------------------------- ### Monitoring Control Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/globals.html Functions to start, stop, and check the status of monitoring. ```APIDOC ## fsw_start_monitor() ### Description Starts the fswatch monitoring process. ### Method (Not applicable, C function) ### Endpoint (Not applicable) ### Parameters None ### Request Example (Not applicable) ### Response (Not applicable) ``` ```APIDOC ## fsw_stop_monitor() ### Description Stops the fswatch monitoring process. ### Method (Not applicable, C function) ### Endpoint (Not applicable) ### Parameters None ### Request Example (Not applicable) ### Response (Not applicable) ``` ```APIDOC ## fsw_is_running() ### Description Checks if the fswatch monitor is currently running. ### Method (Not applicable, C function) ### Endpoint (Not applicable) ### Parameters None ### Request Example (Not applicable) ### Response (Not applicable) ``` -------------------------------- ### get_subdirectories Function Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/namespacefsw.html Gets a vector of direct subdirectories for a given path. ```APIDOC std::vector get_subdirectories(const std::filesystem::path &path) ``` -------------------------------- ### Create a File System Watch Session Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/libfswatch_8cpp.html Initializes a new file system monitoring session using the default monitor type. Error checking code was omitted for brevity. ```c // Use the default monitor. const FSW_HANDLE handle = fsw_init_session(system_default_monitor_type); fsw_add_path(handle, "my/path"); fsw_set_callback(handle, my_callback); fsw_start_monitor(handle); ``` -------------------------------- ### get() Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/structfsw_1_1scoped__fd.html Retrieves the managed file descriptor without releasing ownership. ```APIDOC ## int get() const ### Description Returns the currently managed file descriptor. This method does not release ownership of the file descriptor. ### Returns - **int** - The managed file descriptor. ``` -------------------------------- ### fsw::libfsw_exception::error_code() Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1libfsw__exception.html Gets the error code associated with the exception. ```APIDOC ## int error_code() const noexcept ### Description Gets the error code. ### Returns The error code. ``` -------------------------------- ### Initialize fswatch Library Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/c-api.html Initializes the fswatch library. This must be called before any other library functions. Error checking is recommended. ```c // Initialize the library FSW_STATUS ret = fsw_init_library(); if (ret != FSW_OK) { exit(1); } ``` -------------------------------- ### fsw::libfsw_exception::what() Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1libfsw__exception.html Gets the error message associated with the exception. ```APIDOC ## const char* what() const noexcept override ### Description Gets the error message. ### Returns The error message. ``` -------------------------------- ### Initialization and Session Management Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/globals.html Functions for initializing the fswatch library and managing monitoring sessions. ```APIDOC ## fsw_init_library() ### Description Initializes the fswatch library. This function should be called before any other fswatch functions. ### Method (Not applicable, C function) ### Endpoint (Not applicable) ### Parameters None ### Request Example (Not applicable) ### Response (Not applicable) ``` ```APIDOC ## fsw_init_session() ### Description Initializes a new fswatch monitoring session. ### Method (Not applicable, C function) ### Endpoint (Not applicable) ### Parameters None ### Request Example (Not applicable) ### Response (Not applicable) ``` ```APIDOC ## fsw_destroy_session() ### Description Destroys an fswatch monitoring session and releases associated resources. ### Method (Not applicable, C function) ### Endpoint (Not applicable) ### Parameters None ### Request Example (Not applicable) ### Response (Not applicable) ``` -------------------------------- ### create_monitor (fsw_monitor_type type, std::vector paths, FSW_EVENT_CALLBACK *callback, void *context) Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1monitor__factory.html Creates a monitor of the specified type. This method allows for the instantiation of a monitor by providing its type enumeration, a list of paths to monitor, a callback function to handle events, and an optional context pointer. ```APIDOC ## create_monitor (fsw_monitor_type type, std::vector paths, FSW_EVENT_CALLBACK *callback, void *context) ### Description Creates a monitor of the specified type. ### Method static ### Parameters #### Path Parameters - **type** (fsw_monitor_type) - Required - The type of monitor to create. - **paths** (std::vector) - Required - A vector of strings representing the paths to monitor. - **callback** (FSW_EVENT_CALLBACK *) - Required - A pointer to the callback function to handle events. - **context** (void *) - Optional - A pointer to user-defined context data. ``` -------------------------------- ### create_monitor (const std::string &name, std::vector paths, FSW_EVENT_CALLBACK *callback, void *context) Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1monitor__factory.html Creates a monitor whose type is specified by name. This method allows for the instantiation of a monitor by providing its registered name, a list of paths to monitor, a callback function to handle events, and an optional context pointer. ```APIDOC ## create_monitor (const std::string &name, std::vector paths, FSW_EVENT_CALLBACK *callback, void *context) ### Description Creates a monitor whose type is specified by name. ### Method static ### Parameters #### Path Parameters - **name** (const std::string &) - Required - The name of the monitor type to create. - **paths** (std::vector) - Required - A vector of strings representing the paths to monitor. - **callback** (FSW_EVENT_CALLBACK *) - Required - A pointer to the callback function to handle events. - **context** (void *) - Optional - A pointer to user-defined context data. ``` -------------------------------- ### get_directory_entries Function Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/namespacefsw.html Gets a vector of direct directory entries for a given path. ```APIDOC std::vector get_directory_entries(const std::filesystem::path &path) ``` -------------------------------- ### Getting Last Error Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/libfswatch_8h.html Retrieves the status code of the last encountered error. ```APIDOC ## fsw_last_error ### Description Retrieves the status code of the last encountered error. ### Returns - FSW_STATUS: The status code of the last error. ``` -------------------------------- ### Get Last Error Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/c-api.html Retrieves the last error code that occurred in the library. ```APIDOC ## Get Last Error ### Description Retrieves the last error code that occurred within the `libfswatch` library. This function is useful for diagnosing issues when API calls return an error status. ### Function Signature ```c FSW_STATUS fsw_last_error(); ``` ### Return Value - The last `FSW_STATUS` code encountered. ### Example ```c // Assuming a previous call returned an error status FSW_STATUS error_code = fsw_last_error(); // Handle the error based on error_code ``` ``` -------------------------------- ### fsw_init_session Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/libfswatch_8cpp.html Creates a new monitor session using the specified monitor type and returns a handle to it. This is the primary entry point for the libfswatch API. ```APIDOC ## fsw_init_session() ### Description Creates a new monitor session using the specified monitor type and returns a handle to it. This function is the `libfswatch` API entry point. ### Signature `FSW_HANDLE fsw_init_session(const enum fsw_monitor_type _type)` ### Parameters * `_type` (enum fsw_monitor_type) - The type of monitor to use for the session. See `cmonitor.h` for available monitor types. ### Returns A `FSW_HANDLE` to the newly created monitor session, or an invalid handle if creation fails. ``` -------------------------------- ### Initialize libfswatch Library Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/libfswatch_8cpp.html This function initializes the libfswatch library. It must be invoked before any other calls to the C or C++ API. Successful initialization returns FSW_OK. ```c FSW_STATUS fsw_init_library(void); ``` -------------------------------- ### Monitor Control Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/libfswatch_8cpp.html Functions for starting, stopping, and checking the status of file system monitors. ```APIDOC ## Monitor Control Functions ### `is_running` Checks if the file system monitor is currently running. - **Parameters**: - `handle` (const FSW_HANDLE): The handle of the session. - **Returns**: - `bool`: `true` if the monitor is running, `false` otherwise. ### `start_monitor` Starts the file system monitor. - **Parameters**: - `handle` (const FSW_HANDLE): The handle of the session. - **Returns**: - `FSW_STATUS`: Status code indicating success or failure. ### `stop_monitor` Stops the file system monitor. - **Parameters**: - `handle` (const FSW_HANDLE): The handle of the session. - **Returns**: - `FSW_STATUS`: Status code indicating success or failure. ``` -------------------------------- ### run override Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1fanotify__monitor-members.html Executes the main monitoring loop. ```APIDOC ## run() override ### Description Starts the monitoring loop. Overrides the base class method. ``` -------------------------------- ### fsw_init_library Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/libfswatch_8cpp.html Initializes the libfswatch library. This must be called before any other C or C++ API functions. ```APIDOC ## fsw_init_library() ### Description Initializes the `libfswatch` library. This function must be invoked before any other calls to the C or C++ API. If the function succeeds, it returns FSW_OK, otherwise the initialization routine failed and the library should not be usable. The `libfswatch` C API allows users to create monitor sessions and receive file system events matching specified criteria. Most API functions return a status code of type FSW_STATUS, which can take any value specified in the error.h header. A successful API call returns FSW_OK, and the last error can be obtained by calling the fsw_last_error() function. If the compiler and the C++ library used to build `libfswatch` support `thread_local` storage, this API is thread-safe, maintaining a different state on a per-thread basis. Session-modifying API calls (such as fsw_add_path) will take effect the next time a monitor is started with fsw_start_monitor. Currently, not all monitors support being stopped; in such cases, fsw_start_monitor is a non-returning API call. A basic session requires at least: * A path to watch. * A callback to process the events sent by the monitor. ### Signature ```c FSW_STATUS fsw_init_library(void) ``` ### Returns * FSW_OK: If the library was initialized successfully. * Other FSW_STATUS values: Indicate an error during initialization. ``` -------------------------------- ### Session Initialization Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/libfswatch_8h.html Initializes a new file system monitoring session. A session represents a distinct monitoring context. ```APIDOC ## fsw_init_session ### Description Initializes a new file system monitoring session. ### Parameters - **type** (enum fsw_monitor_type): The type of monitor to initialize. ### Returns - FSW_HANDLE: A handle to the newly created session on success, or NULL on failure. ``` -------------------------------- ### run() Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1windows__monitor.html Executes the monitor loop. This function is responsible for continuously monitoring the specified paths for file system events. ```APIDOC ## run() ### Description Executes the monitor loop. ### Signature `void run()` ``` -------------------------------- ### fsw::monitor::get_property Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1monitor.html Gets the value of a specified property. Returns an empty string if the property is not set. ```APIDOC ## fsw::monitor::get_property(std::string name) ### Description Gets the value of a property by its name. If the property is not set, an empty string is returned. ### Parameters #### Path Parameters - **name** (std::string) - Required - The name of the property. ### Returns - **std::string** - The value of the property. ``` -------------------------------- ### fsw_init_library Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/globals_func.html Initializes the fswatch library. This function is declared in libfswatch.h and implemented in libfswatch.cpp. ```APIDOC ## fsw_init_library ### Description Initializes the fswatch library. ### Declaration libfswatch.cpp, libfswatch.h ``` -------------------------------- ### stat_path Function (without follow_symlink) Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/namespacefsw.html Wraps a stat call to get file status. Invokes perror() on failure. ```APIDOC bool stat_path(const std::string &path, struct stat &fd_stat) ``` -------------------------------- ### Callback and Event Handling Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/libfswatch_8cpp.html Functions for setting up callbacks to handle file system events and managing the monitoring loop. ```APIDOC ## Callback and Event Handling Functions ### `set_callback` Sets a callback function to be invoked when file system events occur. - **Parameters**: - `handle` (const FSW_HANDLE): The handle of the session. - `callback` (const FSW_CEVENT_CALLBACK): The callback function pointer. - `data` (void *): User-defined data to pass to the callback. - **Returns**: - `FSW_STATUS`: Status code indicating success or failure. ### `set_callback_v2` Sets a callback function (version 2) to be invoked when file system events occur. - **Parameters**: - `handle` (const FSW_HANDLE): The handle of the session. - `callback` (const FSW_CEVENT_CALLBACK_V2): The callback function pointer (version 2). - `data` (void *): User-defined data to pass to the callback. - **Returns**: - `FSW_STATUS`: Status code indicating success or failure. ### `libfsw_cpp_callback_proxy` A proxy function used internally to bridge C++ callbacks with the C interface. - **Parameters**: - `events` (const std::vector< event > &): A vector of file system events. - `context_ptr` (void *): Pointer to the callback context. ``` -------------------------------- ### create_stream Method Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/fsevents__monitor_8hpp_source.html Creates the FSEvents stream to monitor the specified paths. This method is part of the internal setup for the fsevents_monitor. ```cpp void create_stream(CFArrayRef pathsToWatch) ``` -------------------------------- ### Library Initialization Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/c-api.html Initializes the fswatch library. This function must be called before any other library method. ```APIDOC ## Library Initialization ### Description Initializes the library. This function must be called before calling any other library method. ### Function Signature ```c FSW_STATUS fsw_init_library(); ``` ### Return Value - `FSW_OK`: The library was initialized successfully. - Other `FSW_STATUS` codes indicate an error. ### Example ```c // Initialize the library FSW_STATUS ret = fsw_init_library(); if (ret != FSW_OK) { exit(1); } ``` ``` -------------------------------- ### fsw_init_library Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/libfswatch_8h.html Initializes the libfswatch library. This function must be invoked before any other calls to the C or C++ API. It supports thread-local storage for thread safety. ```APIDOC ## fsw_init_library() ### Description Initializes the `libfswatch` library. This function must be invoked before any other calls to the C or C++ API. If the function succeeds, it returns FSW_OK, otherwise the initialization routine failed and the library should not be usable. The API is thread-safe if the compiler and C++ library support thread_local storage. ### Returns - FSW_OK on success. - An error code on failure. ``` -------------------------------- ### Library Initialization and Error Handling Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/libfswatch_8cpp.html Functions for initializing the library and handling errors. ```APIDOC ## Library Initialization and Error Handling Functions ### `init_library` Initializes the libfswatch library. - **Returns**: - `FSW_STATUS`: Status code indicating success or failure. ### `set_last_error` Sets the last error code for the library. - **Parameters**: - `error` (const int): The error code to set. - **Returns**: - `FSW_STATUS`: Status code indicating success or failure. ### `last_error` Retrieves the last error code set for the library. - **Returns**: - `FSW_STATUS`: The last error code. ``` -------------------------------- ### Add Path to Monitor Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/c-api.html Adds a path to be monitored by the session. Changes take effect the next time the monitor is started. ```APIDOC ## Add Path to Monitor ### Description Adds a path to the monitoring session. Session-modifying API calls will take effect the next time a monitor is started with `fsw_start_monitor()`. ### Function Signature ```c FSW_STATUS fsw_add_path(FSW_HANDLE handle, const char *path); ``` ### Parameters #### Path Parameters - **handle** (`FSW_HANDLE`): The handle of the monitoring session. - **path** (`const char *`): A NUL-terminated string representing the path to add. ### Return Value - `FSW_OK` on success. - An error code on failure. ### Example ```c fsw_add_path(handle, "my/path"); ``` ``` -------------------------------- ### kqueue_monitor Constructor Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1kqueue__monitor.html Constructs an instance of the kqueue_monitor class, initializing it to watch specified file system paths. ```APIDOC ## kqueue_monitor(std::vector paths, FSW_EVENT_CALLBACK *callback, void *context = nullptr) ### Description Constructs an instance of this class. ### Parameters * **paths** (std::vector) - The list of file system paths to monitor. * **callback** (FSW_EVENT_CALLBACK *) - A pointer to the callback function to be invoked when file system events occur. * **context** (void *) - Optional pointer to user-defined context data. ``` -------------------------------- ### fsw_init_session Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/globals_func.html Initializes a new monitoring session. This function is declared in libfswatch.h and implemented in libfswatch.cpp. ```APIDOC ## fsw_init_session ### Description Initializes a new monitoring session. ### Declaration libfswatch.cpp, libfswatch.h ``` -------------------------------- ### lstat_path Function Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/namespacefsw.html Wraps an lstat call to get file status without following symbolic links. Invokes perror() on failure. ```APIDOC bool lstat_path(const std::string &path, struct stat &fd_stat) ``` -------------------------------- ### fswatch Get Correlation ID Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/event_8hpp_source.html Retrieves the correlation ID of the file system event. This ID can be used to group related events. ```cpp unsigned long get_correlation_id() const; ``` -------------------------------- ### fsw::monitor::run Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/monitor_8hpp_source.html Executes the monitor loop. ```APIDOC ## fsw::monitor::run ### Description Execute monitor loop. ### Signature virtual void run()=0 ``` -------------------------------- ### Open fswatch PDF Manual Source: https://emcrisostomo.github.io/fswatch/doc Opens the generated fswatch manual in PDF format. This command is typically used from a terminal. ```bash $ open fswatch-1.21.0.pdf ``` -------------------------------- ### fswatch Get Event Time Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/event_8hpp_source.html Retrieves the time at which the file system event occurred. This method is part of the fsw::event class. ```cpp time_t get_time() const; ``` -------------------------------- ### Get Event Flag by Name Function Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/cevent_8h_source.html Converts a string name into its corresponding fsw_event_flag. Returns FSW_STATUS indicating success or failure. ```c FSW_STATUS fsw_get_event_flag_by_name(const char *name, enum fsw_event_flag *flag); ``` -------------------------------- ### Constructor with HANDLE Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/win__handle_8hpp_source.html Constructs a win_handle instance by wrapping a provided Windows HANDLE. ```cpp win_handle(HANDLE handle); ``` -------------------------------- ### Get Event Flag Name Function Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/cevent_8h_source.html Retrieves the string name corresponding to a given fsw_event_flag. Ensure the flag is valid before calling. ```c char *fsw_get_event_flag_name(const enum fsw_event_flag flag); ``` -------------------------------- ### fsw::windows_monitor Constructor Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/windows__monitor_8hpp_source.html Constructs a new `windows_monitor` instance to monitor file system events on Windows. ```APIDOC ## fsw::windows_monitor::windows_monitor ### Description Constructs an instance of this class. ### Signature windows_monitor(std::vector paths, FSW_EVENT_CALLBACK *callback, void *context = nullptr) ### Parameters * **paths** (std::vector) - List of paths to watch. * **callback** (FSW_EVENT_CALLBACK *) - Callback function to notify about file system events. * **context** (void *) - Optional pointer to context data passed to the callback. ``` -------------------------------- ### fsw::kqueue_monitor::kqueue_monitor Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/kqueue__monitor_8hpp_source.html Constructs an instance of the kqueue_monitor class, initializing it to watch the specified paths. It takes a vector of paths, a callback function to be invoked upon event detection, and an optional context pointer. ```APIDOC ## fsw::kqueue_monitor::kqueue_monitor ### Description Constructs an instance of this class. ### Signature kqueue_monitor(std::vector paths, FSW_EVENT_CALLBACK *callback, void *context = nullptr) ### Parameters * **paths** (std::vector) - List of paths to watch. * **callback** (FSW_EVENT_CALLBACK *) - Callback function to notify on events. * **context** (void *) - Optional pointer to context data passed to the callback. ``` -------------------------------- ### fsw::windows_monitor Constructor Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1windows__monitor-members.html Constructs a new windows_monitor object. This constructor is used to initialize the monitor with a list of paths to watch, a callback function to be invoked when events occur, and an optional context pointer. ```APIDOC ## windows_monitor(std::vector< std::string > paths, FSW_EVENT_CALLBACK *callback, void *context=nullptr) ### Description Initializes the `windows_monitor` with the specified paths, callback function, and context. ### Parameters * **paths** (std::vector< std::string >) - A vector of strings representing the paths to monitor. * **callback** (FSW_EVENT_CALLBACK *) - A pointer to the callback function to be executed when an event occurs. * **context** (void *) - Optional. A pointer to user-defined data to be passed to the callback function. Defaults to nullptr. ``` -------------------------------- ### fswatch Get Process PIDFD Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/event_8hpp_source.html Retrieves the process file descriptor associated with the event. Returns -1 if no PID file descriptor is available. ```cpp int get_process_pidfd() const; ``` -------------------------------- ### run() Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1kqueue__monitor.html Executes the monitor loop. This call does not return until the monitor is stopped. It implements the run() method from the fsw::monitor base class. ```APIDOC ## void fsw::kqueue_monitor::run() ### Description Executes the monitor loop. This call does not return until the monitor is stopped. ### Method `void run()` ### Remarks Implements `fsw::monitor::run()`. ### See Also `stop()` ``` -------------------------------- ### fsw::monitor Constructor Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1monitor.html Constructs a monitor instance to watch a specified list of paths. It takes a callback function and an optional context pointer. ```APIDOC ## monitor(std::vector paths, FSW_EVENT_CALLBACK *callback, void *context=nullptr) ### Description Constructs a monitor watching the specified `paths`. ### Parameters * **paths** (std::vector) - The list of file system paths to monitor. * **callback** (FSW_EVENT_CALLBACK *) - A pointer to the callback function to be invoked when events occur. * **context** (void *) - Optional pointer to user-defined context data. ``` -------------------------------- ### stat_path Function (with follow_symlink) Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/namespacefsw.html Wraps a stat or lstat call to get file status, with an option to follow symbolic links. Invokes perror() on failure. ```APIDOC bool stat_path(const std::string &path, struct stat &fd_stat, bool follow_symlink) ``` -------------------------------- ### fswatch Get Event Flag Name Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/event_8hpp_source.html Converts an fsw_event_flag enum value to its string representation. This static utility function is part of the fsw::event class. ```cpp static std::string get_event_flag_name(const fsw_event_flag& flag); ``` -------------------------------- ### fsw::monitor Constructor Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1monitor.html Constructs a monitor instance to watch specified file system paths and notify a callback function upon event occurrences. ```APIDOC ## fsw::monitor::monitor() ### Description Constructs a monitor watching the specified `paths`. The monitor will notify change events to the specified `callback`, passing it the pointer to the specified `context`. ### Parameters - **paths** (std::vector) - The list of paths to watch. - **callback** (FSW_EVENT_CALLBACK *) - The callback to which change events will be notified. This cannot be null, otherwise a libfsw_exception will be thrown. - **context** (void *) - An optional pointer to context data. The monitor stores a copy of this pointer to pass it to the `callback`. Defaults to `nullptr`. ``` -------------------------------- ### fswatch Get Event Flag by Name Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/event_8hpp_source.html Retrieves an fsw_event_flag enum value from its string name. This static utility function is part of the fsw::event class. ```cpp static fsw_event_flag get_event_flag_by_name(const std::string& name); ``` -------------------------------- ### windows_monitor Constructor Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1windows__monitor.html Constructs a new instance of the windows_monitor class, initializing it to watch the specified paths with a given callback function and context. ```APIDOC ## windows_monitor(std::vector paths, FSW_EVENT_CALLBACK *callback, void *context = nullptr) ### Description Constructs an instance of this class. ### Parameters * **paths** (std::vector) - The list of paths to monitor. * **callback** (FSW_EVENT_CALLBACK *) - A pointer to the callback function to be invoked when file system events occur. * **context** (void *) - Optional pointer to user-defined context data. ``` -------------------------------- ### fswatch Get Process ID Kind Name Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/event_8hpp_source.html Converts a process_id_kind enum value to its string representation. This utility function is static within the fsw::event class. ```cpp static std::string get_process_id_kind_name(process_id_kind kind); ``` -------------------------------- ### fsw::win_error_message Member Functions Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1win__error__message.html Details the public member functions of the win_error_message class, including methods to get the error code, the error message, and an overloaded conversion operator. ```APIDOC ## Static Member Function: current() ### Description Constructs an instance of this class using the last error code of the calling thread, returned by a call to `GetLastError()`. ### Returns An instance of `win_error_message`. ### See Also * `win_error_message()` ``` ```APIDOC ## Member Function: get_error_code() ### Description Gets the error code. ### Returns The error code (DWORD). ``` ```APIDOC ## Member Function: get_message() ### Description Gets the system-defined error message. The system-defined error message is retrieved with a call to `FormatMessage` with the `FORMAT_MESSAGE_FROM_SYSTEM` formatting option. ### Returns The error message (std::wstring). ``` ```APIDOC ## Conversion Operator: operator std::wstring() ### Description Gets the system-defined error message. ### Returns The error message (std::wstring). ### See Also * `get_message()` ``` -------------------------------- ### monitor Constructor Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1fsevents__monitor.html Constructs a monitor instance, inheriting from the base monitor class, to watch specified file system paths. ```APIDOC ## monitor(std::vector paths, FSW_EVENT_CALLBACK *callback, void *context=nullptr) ### Description Constructs a monitor watching the specified `paths`. This is the base constructor for setting up file system event monitoring. ### Parameters * **paths** (std::vector) - A vector of directory paths to monitor. * **callback** (FSW_EVENT_CALLBACK *) - A pointer to the callback function to be invoked when file system events occur. * **context** (void *) - Optional pointer to user-defined data to be passed to the callback function. ``` -------------------------------- ### fsw::monitor::run Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1monitor.html Implements the monitor event watching logic and is called from start() on its own thread. This function should block until the monitoring loop terminates and cooperatively check the monitor::should_stop field. ```APIDOC ## fsw::monitor::run() ### Description Execute monitor loop. This function implements the monitor event watching logic. This function is called from start() and it is executed on its thread. This function should _block_ until the monitoring loop terminates: when it returns, the monitor is marked as stopped. This function should cooperatively check the monitor::should_stop field locking monitor::run_mutex and return if set to `true`. ### See Also - start() - stop() ### Implemented In - fsw::windows_monitor - fsw::kqueue_monitor - fsw::fanotify_monitor - fsw::fen_monitor - fsw::fsevents_monitor - fsw::inotify_monitor - fsw::poll_monitor ### Signature `virtual void fsw::monitor::run() pure virtual` ``` -------------------------------- ### fsw::poll_monitor::run() Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1poll__monitor.html Executes the monitor event watching loop. This function is called from start() and runs on its own thread. It should block until the monitoring loop terminates and cooperatively check the monitor::should_stop field. ```APIDOC ## run() ### Description Execute monitor loop. This function implements the monitor event watching logic. This function is called from start() and it is executed on its thread. This function should _block_ until the monitoring loop terminates: when it returns, the monitor is marked as stopped. This function should cooperatively check the monitor::should_stop field locking monitor::run_mutex and return if set to `true`. ### Signature `void fsw::poll_monitor::run()` ### Remarks Implements `fsw::monitor`. See also: start() stop() ``` -------------------------------- ### fsw::monitor_factory::create_monitor (by name) Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/classfsw_1_1monitor__factory.html Creates a monitor of a specified type, identified by its name. The monitor's paths, callback, and context are then forwarded to the fsw::monitor constructor. ```APIDOC ## create_monitor(name, paths, callback, context) ### Description Creates a monitor whose type is specified by `name`. The other parameters are forwarded to the fsw::monitor() constructor. ### Method Signature `monitor * fsw::monitor_factory::create_monitor(const std::string & _name, std::vector _paths, FSW_EVENT_CALLBACK * _callback, void * _context = nullptr)` ### Parameters #### Path Parameters * **name** (string) - The monitor type. * **paths** (std::vector) - The paths to watch. * **callback** (FSW_EVENT_CALLBACK *) - The callback to invoke during the notification of a change event. * **context** (void *) - Optional context pointer, defaults to nullptr. ### Returns The newly created monitor. ### Exceptions * `libfsw_exception` - if a monitor of the type specified by `name` cannot be found. ### See Also fsw::monitor() ``` -------------------------------- ### fsw::windows_monitor::run Source: https://emcrisostomo.github.io/fswatch/doc/libfswatch/1.21.0/windows__monitor_8hpp_source.html Executes the main monitoring loop for the Windows monitor. ```APIDOC ## fsw::windows_monitor::run ### Description Executes the monitor loop. ### Signature void run() ### Remarks This method starts the process of monitoring the specified paths for file system changes. ```