uvw  2.10.0
fs_event.h
1 #ifndef UVW_FS_EVENT_INCLUDE_H
2 #define UVW_FS_EVENT_INCLUDE_H
3 
4 
5 #include <type_traits>
6 #include <string>
7 #include <uv.h>
8 #include "handle.hpp"
9 #include "util.h"
10 #include "loop.h"
11 
12 
13 namespace uvw {
14 
15 
16 namespace details {
17 
18 
19 enum class UVFsEventFlags: std::underlying_type_t<uv_fs_event_flags> {
20  WATCH_ENTRY = UV_FS_EVENT_WATCH_ENTRY,
21  STAT = UV_FS_EVENT_STAT,
22  RECURSIVE = UV_FS_EVENT_RECURSIVE
23 };
24 
25 
26 enum class UVFsEvent: std::underlying_type_t<uv_fs_event> {
27  RENAME = UV_RENAME,
28  CHANGE = UV_CHANGE
29 };
30 
31 
32 }
33 
34 
40 struct FsEventEvent {
41  FsEventEvent(const char * pathname, Flags<details::UVFsEvent> events);
42 
49  const char * filename;
50 
60 };
61 
62 
76 class FsEventHandle final: public Handle<FsEventHandle, uv_fs_event_t> {
77  static void startCallback(uv_fs_event_t *handle, const char *filename, int events, int status);
78 
79 public:
80  using Watch = details::UVFsEvent;
81  using Event = details::UVFsEventFlags;
82 
83  using Handle::Handle;
84 
89  bool init();
90 
108  void start(const std::string &path, Flags<Event> flags = Flags<Event>{});
109 
127  void start(const std::string &path, Event flag);
128 
132  void stop();
133 
138  std::string path() noexcept;
139 };
140 
141 
142 }
143 
144 
145 #ifndef UVW_AS_LIB
146 #include "fs_event.cpp"
147 #endif
148 
149 
150 #endif // UVW_FS_EVENT_INCLUDE_H
The FsEventHandle handle.
Definition: fs_event.h:76
void stop()
Stops polling the file descriptor.
void start(const std::string &path, Flags< Event > flags=Flags< Event >{})
Starts watching the specified path.
bool init()
Initializes the handle.
void start(const std::string &path, Event flag)
Starts watching the specified path.
std::string path() noexcept
Gets the path being monitored.
Handle base class.
Definition: handle.hpp:30
uvw default namespace.
Definition: async.h:10
FsEventEvent event.
Definition: fs_event.h:40
const char * filename
The path to the file being monitored.
Definition: fs_event.h:49
Flags< details::UVFsEvent > flags
Detected events all in one.
Definition: fs_event.h:59