openMSX
Reactor.hh
Go to the documentation of this file.
1#ifndef REACTOR_HH
2#define REACTOR_HH
3
4#include "EnumSetting.hh"
5#include "EventListener.hh"
6#include "Observer.hh"
7
8#include "view.hh"
9
10#include <cassert>
11#include <memory>
12#include <mutex>
13#include <string>
14#include <string_view>
15#include <vector>
16
17namespace openmsx {
18
19class RTScheduler;
20class EventDistributor;
21class CommandController;
22class InfoCommand;
23class GlobalCliComm;
24class GlobalCommandController;
25class GlobalSettings;
26class CliComm;
27class ImGuiManager;
28class Interpreter;
29class Display;
30class Mixer;
31class InputEventGenerator;
32class DiskFactory;
33class DiskManipulator;
34class DiskChanger;
35class FilePool;
36class HotKey;
37class UserSettings;
38class RomDatabase;
39class TclCallbackMessages;
40class MsxChar2Unicode;
41class MSXMotherBoard;
42class Setting;
43class CommandLineParser;
44class AfterCommand;
45class ExitCommand;
46class MessageCommand;
47class MachineCommand;
48class TestMachineCommand;
49class CreateMachineCommand;
50class DeleteMachineCommand;
51class ListMachinesCommand;
52class ActivateMachineCommand;
53class StoreMachineCommand;
54class RestoreMachineCommand;
55class GetClipboardCommand;
56class SetClipboardCommand;
57class AviRecorder;
58class ConfigInfo;
59class RealTimeInfo;
60class SoftwareInfoTopic;
61class SymbolManager;
62
63extern int exitCode;
64
73class Reactor final : private Observer<Setting>, private EventListener
74{
75public:
77 void init();
78 ~Reactor();
79
83 void run(const CommandLineParser& parser);
84
85 void enterMainLoop();
86
87 [[nodiscard]] RTScheduler& getRTScheduler() { return *rtScheduler; }
88 [[nodiscard]] EventDistributor& getEventDistributor() { return *eventDistributor; }
89 [[nodiscard]] GlobalCliComm& getGlobalCliComm() { return *globalCliComm; }
90 [[nodiscard]] GlobalCommandController& getGlobalCommandController() { return *globalCommandController; }
91 [[nodiscard]] InputEventGenerator& getInputEventGenerator() { return *inputEventGenerator; }
92 [[nodiscard]] Display& getDisplay() { assert(display); return *display; }
93 [[nodiscard]] Mixer& getMixer();
94 [[nodiscard]] DiskFactory& getDiskFactory() { return *diskFactory; }
95 [[nodiscard]] DiskManipulator& getDiskManipulator() { return *diskManipulator; }
96 [[nodiscard]] EnumSetting<int>& getMachineSetting() { return *machineSetting; }
97 [[nodiscard]] FilePool& getFilePool() { return *filePool; }
98 [[nodiscard]] ImGuiManager& getImGuiManager() { return *imGuiManager; }
99 [[nodiscard]] const HotKey& getHotKey() const;
100 [[nodiscard]] SymbolManager& getSymbolManager() const { return *symbolManager; }
101 [[nodiscard]] AviRecorder& getRecorder() const { return *aviRecordCommand; }
102
103 [[nodiscard]] RomDatabase& getSoftwareDatabase();
104
105 void switchMachine(const std::string& machine);
106 [[nodiscard]] MSXMotherBoard* getMotherBoard() const;
107
108 [[nodiscard]] static std::vector<std::string> getHwConfigs(std::string_view type);
109
110 [[nodiscard]] const MsxChar2Unicode& getMsxChar2Unicode() const;
111
112 void block();
113 void unblock();
114
115 // convenience methods
116 [[nodiscard]] GlobalSettings& getGlobalSettings() { return *globalSettings; }
117 [[nodiscard]] InfoCommand& getOpenMSXInfoCommand();
119 [[nodiscard]] CliComm& getCliComm();
120 [[nodiscard]] Interpreter& getInterpreter();
121 [[nodiscard]] std::string_view getMachineID() const;
122
123 using Board = std::shared_ptr<MSXMotherBoard>;
124 [[nodiscard]] Board createEmptyMotherBoard();
125 void replaceBoard(MSXMotherBoard& oldBoard, Board newBoard); // for reverse
126 [[nodiscard]] Board getMachine(std::string_view machineID) const;
127
128 [[nodiscard]] bool isFullyStarted() const { return fullyStarted; }
129
130 [[nodiscard]] auto getMachineIDs() const {
131 return view::transform(boards,
132 [](auto& b) -> std::string_view { return b->getMachineID(); });
133 }
134private:
135 void createMachineSetting();
136 void switchBoard(Board newBoard);
137 void deleteBoard(Board board);
138
139 // Observer<Setting>
140 void update(const Setting& setting) noexcept override;
141
142 // EventListener
143 int signalEvent(const Event& event) override;
144
145 // Run 1 iteration of the openMSX event loop. Typically this will
146 // emulate about 1 frame (but could be more or less depending on
147 // various factors). Returns true when openMSX wants to continue
148 // running.
149 [[nodiscard]] bool doOneIteration();
150
151 void unpause();
152 void pause();
153
154private:
155 std::mutex mbMutex; // this should come first, because it's still used by
156 // the destructors of the unique_ptr below
157
158 // note: order of unique_ptr's is important
159 std::unique_ptr<RTScheduler> rtScheduler;
160 std::unique_ptr<EventDistributor> eventDistributor;
161 std::unique_ptr<GlobalCliComm> globalCliComm;
162 std::unique_ptr<GlobalCommandController> globalCommandController;
163 std::unique_ptr<GlobalSettings> globalSettings;
164 std::unique_ptr<InputEventGenerator> inputEventGenerator;
165 std::unique_ptr<SymbolManager> symbolManager; // before imGuiManager
166 std::unique_ptr<ImGuiManager> imGuiManager; // before display
167 std::unique_ptr<Display> display;
168 std::unique_ptr<Mixer> mixer; // lazy initialized
169 std::unique_ptr<DiskFactory> diskFactory;
170 std::unique_ptr<DiskManipulator> diskManipulator;
171 std::unique_ptr<DiskChanger> virtualDrive;
172 std::unique_ptr<FilePool> filePool;
173
174 std::unique_ptr<EnumSetting<int>> machineSetting;
175 std::unique_ptr<UserSettings> userSettings;
176 std::unique_ptr<RomDatabase> softwareDatabase; // lazy initialized
177
178 std::unique_ptr<AfterCommand> afterCommand;
179 std::unique_ptr<ExitCommand> exitCommand;
180 std::unique_ptr<MessageCommand> messageCommand;
181 std::unique_ptr<MachineCommand> machineCommand;
182 std::unique_ptr<TestMachineCommand> testMachineCommand;
183 std::unique_ptr<CreateMachineCommand> createMachineCommand;
184 std::unique_ptr<DeleteMachineCommand> deleteMachineCommand;
185 std::unique_ptr<ListMachinesCommand> listMachinesCommand;
186 std::unique_ptr<ActivateMachineCommand> activateMachineCommand;
187 std::unique_ptr<StoreMachineCommand> storeMachineCommand;
188 std::unique_ptr<RestoreMachineCommand> restoreMachineCommand;
189 std::unique_ptr<GetClipboardCommand> getClipboardCommand;
190 std::unique_ptr<SetClipboardCommand> setClipboardCommand;
191 std::unique_ptr<AviRecorder> aviRecordCommand;
192 std::unique_ptr<ConfigInfo> extensionInfo;
193 std::unique_ptr<ConfigInfo> machineInfo;
194 std::unique_ptr<RealTimeInfo> realTimeInfo;
195 std::unique_ptr<SoftwareInfoTopic> softwareInfoTopic;
196 std::unique_ptr<TclCallbackMessages> tclCallbackMessages;
197
198 // Locking rules for activeBoard access:
199 // - main thread can always access activeBoard without taking a lock
200 // - changing activeBoard handle can only be done in the main thread
201 // and needs to take the mbMutex lock
202 // - non-main thread can only access activeBoard via specific
203 // member functions (atm only via enterMainLoop()), it needs to take
204 // the mbMutex lock
205 std::vector<Board> boards; // unordered
206 Board activeBoard; // either nullptr or a board inside 'boards'
207
208 int blockedCounter = 0;
209 bool paused = false;
210 bool fullyStarted = false; // all start up actions completed
211
217 bool running = true;
218
219 bool isInit = false; // has the init() method been run successfully
220
221 friend class MachineCommand;
222 friend class TestMachineCommand;
229};
230
231} // namespace openmsx
232
233#endif // REACTOR_HH
BaseSetting * setting
Represents the output window/screen of openMSX.
Definition Display.hh:32
This class contains settings that are used by several other class (including some singletons).
Generic Gang-of-Four Observer class, templatized edition.
Definition Observer.hh:10
Contains the main loop of openMSX.
Definition Reactor.hh:74
GlobalSettings & getGlobalSettings()
Definition Reactor.hh:116
ImGuiManager & getImGuiManager()
Definition Reactor.hh:98
MSXMotherBoard * getMotherBoard() const
Definition Reactor.cc:409
AviRecorder & getRecorder() const
Definition Reactor.hh:101
std::shared_ptr< MSXMotherBoard > Board
Definition Reactor.hh:123
CommandController & getCommandController()
Definition Reactor.cc:333
DiskManipulator & getDiskManipulator()
Definition Reactor.hh:95
void enterMainLoop()
Definition Reactor.cc:520
GlobalCommandController & getGlobalCommandController()
Definition Reactor.hh:90
InfoCommand & getOpenMSXInfoCommand()
Definition Reactor.cc:338
void switchMachine(const std::string &machine)
Definition Reactor.cc:454
void run(const CommandLineParser &parser)
Main loop.
Definition Reactor.cc:536
Display & getDisplay()
Definition Reactor.hh:92
CliComm & getCliComm()
Definition Reactor.cc:323
bool isFullyStarted() const
Definition Reactor.hh:128
EnumSetting< int > & getMachineSetting()
Definition Reactor.hh:96
DiskFactory & getDiskFactory()
Definition Reactor.hh:94
GlobalCliComm & getGlobalCliComm()
Definition Reactor.hh:89
Board createEmptyMotherBoard()
Definition Reactor.cc:429
RTScheduler & getRTScheduler()
Definition Reactor.hh:87
Interpreter & getInterpreter()
Definition Reactor.cc:328
const HotKey & getHotKey() const
Definition Reactor.cc:343
void replaceBoard(MSXMotherBoard &oldBoard, Board newBoard)
Definition Reactor.cc:434
std::string_view getMachineID() const
Definition Reactor.cc:415
EventDistributor & getEventDistributor()
Definition Reactor.hh:88
Mixer & getMixer()
Definition Reactor.cc:307
SymbolManager & getSymbolManager() const
Definition Reactor.hh:100
const MsxChar2Unicode & getMsxChar2Unicode() const
Definition Reactor.cc:374
static std::vector< std::string > getHwConfigs(std::string_view type)
Definition Reactor.cc:348
InputEventGenerator & getInputEventGenerator()
Definition Reactor.hh:91
RomDatabase & getSoftwareDatabase()
Definition Reactor.cc:315
FilePool & getFilePool()
Definition Reactor.hh:97
Board getMachine(std::string_view machineID) const
Definition Reactor.cc:420
auto getMachineIDs() const
Definition Reactor.hh:130
This file implemented 3 utility functions:
Definition Autofire.cc:11
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:446
int exitCode
Definition Reactor.cc:67
constexpr auto transform(Range &&range, UnaryOp op)
Definition view.hh:520