forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwatcher_impl.h
More file actions
52 lines (40 loc) · 1.34 KB
/
watcher_impl.h
File metadata and controls
52 lines (40 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once
#include <cstdint>
#include <list>
#include <string>
#include "envoy/api/api.h"
#include "envoy/event/dispatcher.h"
#include "envoy/filesystem/watcher.h"
#include "source/common/common/logger.h"
#include "absl/container/node_hash_map.h"
namespace Envoy {
namespace Filesystem {
/**
* Implementation of Watcher that uses inotify. inotify is an awful API. In order to make this work
* in a somewhat sane way we always watch the directory that owns the thing being watched, and then
* filter for events that are relevant to the thing being watched.
*/
class WatcherImpl : public Watcher, Logger::Loggable<Logger::Id::file> {
public:
WatcherImpl(Event::Dispatcher& dispatcher, Filesystem::Instance& file_system);
~WatcherImpl() override;
// Filesystem::Watcher
absl::Status addWatch(absl::string_view path, uint32_t events, OnChangedCb cb) override;
private:
struct FileWatch {
std::string file_;
uint32_t events_;
OnChangedCb cb_;
};
struct DirectoryWatch {
std::list<FileWatch> watches_;
};
absl::Status onInotifyEvent();
void callAndLogOnError(OnChangedCb& cb, uint32_t events, const std::string& file);
Filesystem::Instance& file_system_;
int inotify_fd_;
Event::FileEventPtr inotify_event_;
absl::node_hash_map<int, DirectoryWatch> callback_map_;
};
} // namespace Filesystem
} // namespace Envoy