OXYGENHUB
◆ main openmsx / src / PluggingController.hh
3.7 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef PLUGGINGCONTROLLER_HH
2
#define PLUGGINGCONTROLLER_HH
3
4
#include "EmuTime.hh"
5
#include "InfoTopic.hh"
6
#include "RecordedCommand.hh"
7
8
#include <memory>
9
#include <string_view>
10
#include <vector>
11
12
namespace openmsx {
13
14
class MSXMotherBoard;
15
class Connector;
16
class Pluggable;
17
class CliComm;
18
19
/**
20
 * Central administration of Connectors and Pluggables.
21
 */
22
class PluggingController
23
{
24
public:
25
	explicit PluggingController(MSXMotherBoard& motherBoard);
26
	~PluggingController();
27
28
	/** Connectors must be (un)registered
29
	  */
30
	void registerConnector(Connector& connector);
31
	void unregisterConnector(Connector& connector);
32
33
	/** Return the Connector with given name or
34
	  * nullptr if there is none with this name.
35
	  */
36
	[[nodiscard]] Connector* findConnector(std::string_view name) const;
37
38
	/** Add a Pluggable to the registry.
39
	 */
40
	void registerPluggable(std::unique_ptr<Pluggable> pluggable);
41
42
	/** Return the Pluggable with given name or
43
	  * nullptr if there is none with this name.
44
	  */
45
	[[nodiscard]] Pluggable* findPluggable(std::string_view name) const;
46
47
	[[nodiscard]] const auto& getConnectors() const { return connectors; }
48
	[[nodiscard]] const auto& getPluggables() const { return pluggables; }
49
50
	/** Access to the MSX specific CliComm, so that Connectors can get it.
51
	 */
52
	[[nodiscard]] CliComm& getCliComm();
53
54
	/** Convenience method: get current time.
55
	 */
56
	[[nodiscard]] EmuTime getCurrentTime() const;
57
58
private:
59
	[[nodiscard]] Connector& getConnector(std::string_view name) const;
60
	[[nodiscard]] Pluggable& getPluggable(std::string_view name) const;
61
62
private:
63
	MSXMotherBoard& motherBoard;
64
	std::vector<Connector*> connectors; // no order
65
	std::vector<std::unique_ptr<Pluggable>> pluggables;
66
67
	struct PlugCmd final : RecordedCommand {
68
		PlugCmd(CommandController& commandController,
69
			StateChangeDistributor& stateChangeDistributor,
70
			Scheduler& scheduler);
71
		void execute(std::span<const TclObject> tokens, TclObject& result,
72
			     EmuTime time) override;
73
		[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
74
		void tabCompletion(std::vector<std::string>& tokens) const override;
75
		[[nodiscard]] bool needRecord(std::span<const TclObject> tokens) const override;
76
	} plugCmd;
77
78
	struct UnplugCmd final : RecordedCommand {
79
		UnplugCmd(CommandController& commandController,
80
			  StateChangeDistributor& stateChangeDistributor,
81
			  Scheduler& scheduler);
82
		void execute(std::span<const TclObject> tokens, TclObject& result,
83
			     EmuTime time) override;
84
		[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
85
		void tabCompletion(std::vector<std::string>& tokens) const override;
86
	} unplugCmd;
87
88
	struct PluggableInfo final : InfoTopic {
89
		explicit PluggableInfo(InfoCommand& machineInfoCommand);
90
		void execute(std::span<const TclObject> tokens,
91
			     TclObject& result) const override;
92
		[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
93
		void tabCompletion(std::vector<std::string>& tokens) const override;
94
	} pluggableInfo;
95
96
	struct ConnectorInfo final : InfoTopic {
97
		explicit ConnectorInfo(InfoCommand& machineInfoCommand);
98
		void execute(std::span<const TclObject> tokens,
99
			     TclObject& result) const override;
100
		[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
101
		void tabCompletion(std::vector<std::string>& tokens) const override;
102
	} connectorInfo;
103
104
	struct ConnectionClassInfo final : InfoTopic {
105
		explicit ConnectionClassInfo(InfoCommand& machineInfoCommand);
106
		void execute(std::span<const TclObject> tokens,
107
			     TclObject& result) const override;
108
		[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
109
		void tabCompletion(std::vector<std::string>& tokens) const override;
110
	} connectionClassInfo;
111
};
112
113
} // namespace openmsx
114
115
#endif