Debian Codegraph @

node/@parcel/watcher/src/kqueue/KqueueBackend.hh

raw
1 #ifndef KQUEUE_H
2 #define KQUEUE_H
3
4 #include <unordered_map>
5 #include <sys/event.h>
6 #include "../shared/BruteForceBackend.hh"
7 #include "../DirTree.hh"
8 #include "../Signal.hh"
9
10 struct KqueueSubscription {
11 WatcherRef watcher;
12 std::string path;
13 std::shared_ptr<DirTree> tree;
14 int fd;
15 };
16
17 class KqueueBackend : public BruteForceBackend {
18 public:
19 void start() override;
20 ~KqueueBackend();
21 void subscribe(WatcherRef watcher) override;
22 void unsubscribe(WatcherRef watcher) override;
23 private:
24 int mKqueue;
25 int mPipe[2];
26 std::unordered_multimap<std::string, KqueueSubscription> mSubscriptions;
27 std::unordered_map<int, DirEntry *> mFdToEntry;
28 Signal mEndedSignal;
29
30 bool watchDir(WatcherRef watcher, std::string path, std::shared_ptr<DirTree> tree);
31 bool compareDir(int fd, std::string &dir, std::unordered_set<WatcherRef> &watchers);
32 std::vector<KqueueSubscription *> findSubscriptions(std::string &path);
33 };
34
35 #endif