c320d1d3c4677e1c190e94bf68d9fed201db145ca400dc98c058131ca7c716859c886ef434a9b7c21cb011a457b3159b7c9b00d7d39c90166e3cdece29067c 946 B

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef INOTIFY_H
  2. #define INOTIFY_H
  3. #include <unordered_map>
  4. #include <sys/inotify.h>
  5. #include "../shared/BruteForceBackend.hh"
  6. #include "../DirTree.hh"
  7. #include "../Signal.hh"
  8. struct InotifySubscription {
  9. std::shared_ptr<DirTree> tree;
  10. std::string path;
  11. WatcherRef watcher;
  12. };
  13. class InotifyBackend : public BruteForceBackend {
  14. public:
  15. void start() override;
  16. ~InotifyBackend();
  17. void subscribe(WatcherRef watcher) override;
  18. void unsubscribe(WatcherRef watcher) override;
  19. private:
  20. int mPipe[2];
  21. int mInotify;
  22. std::unordered_multimap<int, std::shared_ptr<InotifySubscription>> mSubscriptions;
  23. Signal mEndedSignal;
  24. bool watchDir(WatcherRef watcher, std::string path, std::shared_ptr<DirTree> tree);
  25. void handleEvents();
  26. void handleEvent(struct inotify_event *event, std::unordered_set<WatcherRef> &watchers);
  27. bool handleSubscription(struct inotify_event *event, std::shared_ptr<InotifySubscription> sub);
  28. };
  29. #endif