1 #pragma once
2 
3 #include <jsi/jsi.h>
4 #include <map>
5 #include <memory>
6 #include <mutex>
7 #include <set>
8 #include <string>
9 #include <unordered_map>
10 #include <vector>
11 
12 using namespace facebook;
13 
14 namespace reanimated {
15 
16 class WorkletEventHandler;
17 
18 class EventHandlerRegistry {
19   std::map<
20       std::string,
21       std::unordered_map<uint64_t, std::shared_ptr<WorkletEventHandler>>>
22       eventMappings;
23   std::map<uint64_t, std::shared_ptr<WorkletEventHandler>> eventHandlers;
24   std::mutex instanceMutex;
25 
26  public:
27   void registerEventHandler(std::shared_ptr<WorkletEventHandler> eventHandler);
28   void unregisterEventHandler(uint64_t id);
29 
30   void processEvent(
31       jsi::Runtime &rt,
32       double eventTimestamp,
33       const std::string &eventName,
34       const jsi::Value &eventPayload);
35 
36   bool isAnyHandlerWaitingForEvent(const std::string &eventName);
37 };
38 
39 } // namespace reanimated
40