openMSX
EventDistributor.hh
Go to the documentation of this file.
1#ifndef EVENTDISTRIBUTOR_HH
2#define EVENTDISTRIBUTOR_HH
3
4#include "Event.hh"
5#include <array>
6#include <condition_variable>
7#include <mutex>
8#include <vector>
9
10namespace openmsx {
11
12class Reactor;
13class EventListener;
14
16{
17public:
21 enum Priority {
23 HOTKEY_HIGH, // above IMGUI
25 HOTKEY_LOW, // below IMGUI
27 LOWEST, // should only be used internally in EventDistributor
28 };
29
30 explicit EventDistributor(Reactor& reactor);
31
40 Priority priority = OTHER);
41
48
53 void distributeEvent(Event&& event);
54
59 void deliverEvents();
60
67 bool sleep(unsigned us);
68
69private:
70 [[nodiscard]] bool isRegistered(EventType type, EventListener* listener) const;
71
72private:
73 Reactor& reactor;
74
75 struct Entry {
76 Priority priority;
77 EventListener* listener;
78 };
79 using PriorityMap = std::vector<Entry>; // sorted on priority
80 std::array<PriorityMap, size_t(EventType::NUM_EVENT_TYPES)> listeners;
81 using EventQueue = std::vector<Event>;
82 EventQueue scheduledEvents;
83 std::mutex mutex; // lock data structures
84 std::mutex cvMutex; // lock condition_variable
85 std::condition_variable condition;
86};
87
88} // namespace openmsx
89
90#endif
void unregisterEventListener(EventType type, EventListener &listener)
Unregisters a previously registered event listener.
void distributeEvent(Event &&event)
Schedule the given event for delivery.
bool sleep(unsigned us)
Sleep for the specified amount of time, but return early when (another thread) called the distributeE...
void registerEventListener(EventType type, EventListener &listener, Priority priority=OTHER)
Registers a given object to receive certain events.
void deliverEvents()
This actually delivers the events.
Priority
Priorities from high to low, higher priority listeners can block events for lower priority listeners.
Contains the main loop of openMSX.
Definition Reactor.hh:72
This file implemented 3 utility functions:
Definition Autofire.cc:11
EventType
Definition Event.hh:453
std::variant< KeyUpEvent, KeyDownEvent, MouseMotionEvent, MouseButtonUpEvent, MouseButtonDownEvent, MouseWheelEvent, JoystickAxisMotionEvent, JoystickHatEvent, JoystickButtonUpEvent, JoystickButtonDownEvent, OsdControlReleaseEvent, OsdControlPressEvent, WindowEvent, TextEvent, FileDropEvent, QuitEvent, FinishFrameEvent, CliCommandEvent, GroupEvent, BootEvent, FrameDrawnEvent, BreakEvent, SwitchRendererEvent, TakeReverseSnapshotEvent, AfterTimedEvent, MachineLoadedEvent, MachineActivatedEvent, MachineDeactivatedEvent, MidiInReaderEvent, MidiInWindowsEvent, MidiInCoreMidiEvent, MidiInCoreMidiVirtualEvent, MidiInALSAEvent, Rs232TesterEvent, Rs232NetEvent, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
Definition Event.hh:444