WPILibC++ 2024.3.2
FsEvent.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#ifndef WPINET_UV_FSEVENT_H_
6#define WPINET_UV_FSEVENT_H_
7
8#include <uv.h>
9
10#include <memory>
11#include <string>
12#include <string_view>
13
14#include <wpi/Signal.h>
15
16#include "wpinet/uv/Handle.h"
17
18namespace wpi::uv {
19
20class Loop;
21
22/**
23 * Filesystem Event handle.
24 */
25class FsEvent final : public HandleImpl<FsEvent, uv_fs_event_t> {
26 struct private_init {};
27
28 public:
29 explicit FsEvent(const private_init&) {}
30 ~FsEvent() noexcept override = default;
31
32 /**
33 * Create a filesystem event handle.
34 *
35 * @param loop Loop object where this handle runs.
36 */
37 static std::shared_ptr<FsEvent> Create(Loop& loop);
38
39 /**
40 * Create a filesystem event handle.
41 *
42 * @param loop Loop object where this handle runs.
43 */
44 static std::shared_ptr<FsEvent> Create(const std::shared_ptr<Loop>& loop) {
45 return Create(*loop);
46 }
47
48 /**
49 * Start watching the specified path for changes.
50 *
51 * @param path Path to watch for changes
52 * @param events Bitmask of event flags. Only UV_FS_EVENT_RECURSIVE is
53 * supported (and only on OSX and Windows).
54 */
55 void Start(std::string_view path, unsigned int flags = 0);
56
57 /**
58 * Stop watching for changes.
59 */
61
62 /**
63 * Get the path being monitored. Signals error and returns empty string if
64 * an error occurs.
65 * @return Monitored path.
66 */
67 std::string GetPath();
68
69 /**
70 * Signal generated when a filesystem change occurs. The first parameter
71 * is the filename (if a directory was passed to Start(), the filename is
72 * relative to that directory). The second parameter is an ORed mask of
73 * UV_RENAME and UV_CHANGE.
74 */
76};
77
78} // namespace wpi::uv
79
80#endif // WPINET_UV_FSEVENT_H_
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition: Signal.h:495
Filesystem Event handle.
Definition: FsEvent.h:25
sig::Signal< const char *, int > fsEvent
Signal generated when a filesystem change occurs.
Definition: FsEvent.h:75
void Start(std::string_view path, unsigned int flags=0)
Start watching the specified path for changes.
~FsEvent() noexcept override=default
std::string GetPath()
Get the path being monitored.
void Stop()
Stop watching for changes.
Definition: FsEvent.h:60
static std::shared_ptr< FsEvent > Create(Loop &loop)
Create a filesystem event handle.
FsEvent(const private_init &)
Definition: FsEvent.h:29
bool Invoke(F &&f, Args &&... args) const
Definition: Handle.h:267
Handle.
Definition: Handle.h:290
uv_fs_event_t * GetRaw() const noexcept
Get the underlying handle data structure.
Definition: Handle.h:305
Event loop.
Definition: Loop.h:37
basic_string_view< char > string_view
Definition: core.h:501
Definition: array.h:89
Definition: WebSocket.h:27
flags
Definition: http_parser.h:206
UV_EXTERN int uv_fs_event_stop(uv_fs_event_t *handle)