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