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