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 {
26 LOWEST, // should only be used internally in EventDistributor
27 };
28
29 explicit EventDistributor(Reactor& reactor);
30
39 Priority priority = OTHER);
40
47
52 void distributeEvent(Event&& event);
53
58 void deliverEvents();
59
66 bool sleep(unsigned us);
67
68private:
69 [[nodiscard]] bool isRegistered(EventType type, EventListener* listener) const;
70
71private:
72 Reactor& reactor;
73
74 struct Entry {
75 Priority priority;
76 EventListener* listener;
77 };
78 using PriorityMap = std::vector<Entry>; // sorted on priority
79 std::array<PriorityMap, size_t(EventType::NUM_EVENT_TYPES)> listeners;
80 using EventQueue = std::vector<Event>;
81 EventQueue scheduledEvents;
82 std::mutex mutex; // lock data structures
83 std::mutex cvMutex; // lock condition_variable
84 std::condition_variable condition;
85};
86
87} // namespace openmsx
88
89#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:9
EventType
Definition Event.hh:463
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:454