Backend.hh 874 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #ifndef BACKEND_H
  2. #define BACKEND_H
  3. #include "Event.hh"
  4. #include "Watcher.hh"
  5. #include "Signal.hh"
  6. #include <thread>
  7. class Backend {
  8. public:
  9. virtual ~Backend();
  10. void run();
  11. void notifyStarted();
  12. virtual void start();
  13. virtual void writeSnapshot(WatcherRef watcher, std::string *snapshotPath) = 0;
  14. virtual void getEventsSince(WatcherRef watcher, std::string *snapshotPath) = 0;
  15. virtual void subscribe(WatcherRef watcher) = 0;
  16. virtual void unsubscribe(WatcherRef watcher) = 0;
  17. static std::shared_ptr<Backend> getShared(std::string backend);
  18. void watch(WatcherRef watcher);
  19. void unwatch(WatcherRef watcher);
  20. void unref();
  21. void handleWatcherError(WatcherError &err);
  22. std::mutex mMutex;
  23. std::thread mThread;
  24. private:
  25. std::unordered_set<WatcherRef> mSubscriptions;
  26. Signal mStartedSignal;
  27. void handleError(std::exception &err);
  28. };
  29. #endif