Class FsEventHandle

Synopsis

#include <src/uvw/fs_event.h>

class FsEventHandle final: public Handle<FsEventHandle, uv_fs_event_t>

Description

The FsEventHandle handle.

These handles allow the user to monitor a given path for changes, for example, if the file was renamed or there was a generic change in it. The best backend for the job on each platform is chosen by the handle.

To create a FsEventHandle through a Loop, no arguments are required.

See the official documentation for further details.

Inheritance

Ancestors: Handle

Methods

initInitializes the handle.
pathGets the path being monitored.
start overloadStarts watching the specified path.
stopStops polling the file descriptor.

Source

Lines 76-139 in src/uvw/fs_event.h.

class FsEventHandle final: public Handle<FsEventHandle, uv_fs_event_t> {
    static void startCallback(uv_fs_event_t *handle, const char *filename, int events, int status);

public:
    using Watch = details::UVFsEvent;
    using Event = details::UVFsEventFlags;

    using Handle::Handle;

    /**
     * @brief Initializes the handle.
     * @return True in case of success, false otherwise.
     */
    bool init();

    /**
     * @brief Starts watching the specified path.
     *
     * It will watch the specified path for changes.<br/>
     * As soon as a change is observed, a FsEventEvent is emitted by the
     * handle.<br>
     * It could happen that ErrorEvent events are emitted while running.
     *
     * Available flags are:
     *
     * * `FsEventHandle::Event::WATCH_ENTRY`
     * * `FsEventHandle::Event::STAT`
     * * `FsEventHandle::Event::RECURSIVE`
     *
     * @param path The file or directory to be monitored.
     * @param flags Additional flags to control the behavior.
     */
    void start(const std::string &path, Flags<Event> flags = Flags<Event>{});

    /**
     * @brief Starts watching the specified path.
     *
     * It will watch the specified path for changes.<br/>
     * As soon as a change is observed, a FsEventEvent is emitted by the
     * handle.<br>
     * It could happen that ErrorEvent events are emitted while running.
     *
     * Available flags are:
     *
     * * `FsEventHandle::Event::WATCH_ENTRY`
     * * `FsEventHandle::Event::STAT`
     * * `FsEventHandle::Event::RECURSIVE`
     *
     * @param path The file or directory to be monitored.
     * @param flag Additional flag to control the behavior.
     */
    void start(const std::string &path, Event flag);

    /**
     * @brief Stops polling the file descriptor.
     */
    void stop();

    /**
     * @brief Gets the path being monitored.
     * @return The path being monitored, an empty string in case of errors.
     */
    std::string path() noexcept;
};





Add Discussion as Guest

Log in