userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
inotify.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#if defined(__linux__) || defined(DOXYGEN)
7
8
#include <sys/inotify.h>
9
10
#include <optional>
11
#include <queue>
12
#include <string>
13
#include <unordered_map>
14
15
#include <
userver/engine/io/fd_poller.hpp
>
16
#include <
userver/logging/fwd.hpp
>
17
#include <
userver/utils/flags.hpp
>
18
19
USERVER_NAMESPACE_BEGIN
20
21
namespace
engine::io::sys_linux {
22
24
enum class
EventType
{
25
kNone = 0,
26
kAccess = IN_ACCESS,
27
kAttribChanged = IN_ATTRIB,
28
kCloseWrite = IN_CLOSE_WRITE,
29
kCloseNoWrite = IN_CLOSE_NOWRITE,
30
kCreate = IN_CREATE,
31
kDelete = IN_DELETE,
32
kDeleteSelf = IN_DELETE_SELF,
33
kModify = IN_MODIFY,
34
kMoveSelf = IN_MOVE_SELF,
35
kMovedFrom = IN_MOVED_FROM,
36
kMovedTo = IN_MOVED_TO,
37
kOpen = IN_OPEN,
38
39
kIsDir = IN_ISDIR,
// event occurred against dir
40
kOnlyDir = IN_ONLYDIR,
// catch only dir events
41
};
42
43
std::string
ToString
(EventType);
44
46
using
EventTypeMask
=
utils::Flags<EventType>
;
47
48
std::string ToString(
EventTypeMask
);
49
51
struct
Event
{
52
std::string path;
53
EventTypeMask
mask;
54
55
bool
operator==(
const
Event
& other)
const
{
return
path == other.path && mask == other.mask; }
56
};
57
58
logging::LogHelper
& operator<<(
logging::LogHelper
& lh,
const
Event
& event)
noexcept
;
59
62
class
Inotify final {
63
public
:
64
Inotify();
65
66
Inotify(
const
Inotify&) =
delete
;
67
68
Inotify(Inotify&&) =
delete
;
69
70
~Inotify();
71
72
Inotify& operator=(Inotify&&) =
delete
;
73
74
Inotify& operator=(
const
Inotify&) =
delete
;
75
78
void
AddWatch
(
const
std::string& path,
EventTypeMask
flags);
79
81
void
RmWatch
(
const
std::string& path);
82
86
std::optional<Event>
Poll
(
engine::Deadline
deadline);
87
88
private
:
89
void
Dispatch();
90
91
FdPoller
fd_;
92
std::queue<Event> pending_events_;
93
std::unordered_map<std::string, int> path_to_wd_;
94
std::unordered_map<int, std::string> wd_to_path_;
95
};
96
97
}
// namespace engine::io::sys_linux
98
99
USERVER_NAMESPACE_END
100
101
#endif
userver
engine
io
sys_linux
inotify.hpp
Generated on
for userver by
Doxygen
1.17.0