KqueueBackend.hh 937 B

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