7a449f2bdd11da4ad1051cee3f6f7fa3379e76eb21525c864ac70b8ac08e483180558fbc43fb7c4baea34e22d37fffb5658943e40d7be1a1f208bcce09e427 963 B

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef WASM_H
  2. #define WASM_H
  3. #include <unordered_map>
  4. #include "../shared/BruteForceBackend.hh"
  5. #include "../DirTree.hh"
  6. extern "C" {
  7. int wasm_backend_add_watch(const char *filename, void *backend);
  8. void wasm_backend_remove_watch(int wd);
  9. void wasm_backend_event_handler(void *backend, int wd, int type, char *filename);
  10. };
  11. struct WasmSubscription {
  12. std::shared_ptr<DirTree> tree;
  13. std::string path;
  14. WatcherRef watcher;
  15. };
  16. class WasmBackend : public BruteForceBackend {
  17. public:
  18. void start() override;
  19. void subscribe(WatcherRef watcher) override;
  20. void unsubscribe(WatcherRef watcher) override;
  21. void handleEvent(int wd, int type, char *filename);
  22. private:
  23. int mWasm;
  24. std::unordered_multimap<int, std::shared_ptr<WasmSubscription>> mSubscriptions;
  25. void watchDir(WatcherRef watcher, std::string path, std::shared_ptr<DirTree> tree);
  26. bool handleSubscription(int type, char *filename, std::shared_ptr<WasmSubscription> sub);
  27. };
  28. #endif