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