#ifndef KQUEUE_H #define KQUEUE_H #include #include #include "../shared/BruteForceBackend.hh" #include "../DirTree.hh" #include "../Signal.hh" struct KqueueSubscription { WatcherRef watcher; std::string path; std::shared_ptr tree; int fd; }; class KqueueBackend : public BruteForceBackend { public: void start() override; ~KqueueBackend(); void subscribe(WatcherRef watcher) override; void unsubscribe(WatcherRef watcher) override; private: int mKqueue; int mPipe[2]; std::unordered_multimap mSubscriptions; std::unordered_map mFdToEntry; Signal mEndedSignal; bool watchDir(WatcherRef watcher, std::string path, std::shared_ptr tree); bool compareDir(int fd, std::string &dir, std::unordered_set &watchers); std::vector findSubscriptions(std::string &path); }; #endif