WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
FsEvent.hpp
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#pragma once
6
7#include <memory>
8#include <string>
9#include <string_view>
10
11#include <uv.h>
12
13#include "wpi/net/uv/Handle.hpp"
14#include "wpi/util/Signal.h"
15
16namespace wpi::net::uv {
17
18class Loop;
19
20/**
21 * Filesystem Event handle.
22 */
23class FsEvent final : public HandleImpl<FsEvent, uv_fs_event_t> {
24 struct private_init {};
25
26 public:
27 explicit FsEvent(const private_init&) {}
28 ~FsEvent() noexcept override = default;
29
30 /**
31 * Create a filesystem event handle.
32 *
33 * @param loop Loop object where this handle runs.
34 */
35 static std::shared_ptr<FsEvent> Create(Loop& loop);
36
37 /**
38 * Create a filesystem event handle.
39 *
40 * @param loop Loop object where this handle runs.
41 */
42 static std::shared_ptr<FsEvent> Create(const std::shared_ptr<Loop>& loop) {
43 return Create(*loop);
44 }
45
46 /**
47 * Start watching the specified path for changes.
48 *
49 * @param path Path to watch for changes
50 * @param flags Bitmask of event flags. Only UV_FS_EVENT_RECURSIVE is
51 * supported (and only on OSX and Windows).
52 */
53 void Start(std::string_view path, unsigned int flags = 0);
54
55 /**
56 * Stop watching for changes.
57 */
59
60 /**
61 * Get the path being monitored. Signals error and returns empty string if
62 * an error occurs.
63 * @return Monitored path.
64 */
65 std::string GetPath();
66
67 /**
68 * Signal generated when a filesystem change occurs. The first parameter
69 * is the filename (if a directory was passed to Start(), the filename is
70 * relative to that directory). The second parameter is an ORed mask of
71 * UV_RENAME and UV_CHANGE.
72 */
74};
75
76} // namespace wpi::net::uv
~FsEvent() noexcept override=default
std::string GetPath()
Get the path being monitored.
void Start(std::string_view path, unsigned int flags=0)
Start watching the specified path for changes.
void Stop()
Stop watching for changes.
Definition FsEvent.hpp:58
wpi::util::sig::Signal< const char *, int > fsEvent
Signal generated when a filesystem change occurs.
Definition FsEvent.hpp:73
static std::shared_ptr< FsEvent > Create(Loop &loop)
Create a filesystem event handle.
FsEvent(const private_init &)
Definition FsEvent.hpp:27
bool Invoke(F &&f, Args &&... args) const
Definition Handle.hpp:265
uv_fs_event_t * GetRaw() const noexcept
Definition Handle.hpp:303
Event loop.
Definition Loop.hpp:35
Definition StringMap.hpp:773
Definition Prepare.hpp:14
flags
Definition http_parser.hpp:206
SignalBase< detail::NullMutex, T... > Signal
Specialization of SignalBase to be used in single threaded contexts.
Definition Signal.h:809
UV_EXTERN int uv_fs_event_stop(uv_fs_event_t *handle)