openMSX
PluggingController.hh
Go to the documentation of this file.
1 #ifndef PLUGGINGCONTROLLER_HH
2 #define PLUGGINGCONTROLLER_HH
3 
4 #include "RecordedCommand.hh"
5 #include "InfoTopic.hh"
6 #include "EmuTime.hh"
7 #include "string_view.hh"
8 #include <vector>
9 #include <memory>
10 
11 namespace openmsx {
12 
13 class MSXMotherBoard;
14 class Connector;
15 class Pluggable;
16 class CliComm;
17 
22 {
23 public:
24  explicit PluggingController(MSXMotherBoard& motherBoard);
26 
29  void registerConnector(Connector& connector);
30  void unregisterConnector(Connector& connector);
31 
35  Connector* findConnector(string_view name) const;
36 
39  void registerPluggable(std::unique_ptr<Pluggable> pluggable);
40 
44  Pluggable* findPluggable(string_view name) const;
45 
49 
52  EmuTime::param getCurrentTime() const;
53 
54 private:
55  Connector& getConnector(string_view name) const;
56  Pluggable& getPluggable(string_view name) const;
57 
58  MSXMotherBoard& motherBoard;
59  std::vector<Connector*> connectors; // no order
60  std::vector<std::unique_ptr<Pluggable>> pluggables;
61 
62  struct PlugCmd final : RecordedCommand {
63  PlugCmd(CommandController& commandController,
64  StateChangeDistributor& stateChangeDistributor,
65  Scheduler& scheduler);
66  void execute(array_ref<TclObject> tokens, TclObject& result,
67  EmuTime::param time) override;
68  std::string help(const std::vector<std::string>& tokens) const override;
69  void tabCompletion(std::vector<std::string>& tokens) const override;
70  bool needRecord(array_ref<TclObject> tokens) const override;
71  } plugCmd;
72 
73  struct UnplugCmd final : RecordedCommand {
74  UnplugCmd(CommandController& commandController,
75  StateChangeDistributor& stateChangeDistributor,
76  Scheduler& scheduler);
77  void execute(array_ref<TclObject> tokens, TclObject& result,
78  EmuTime::param time) override;
79  std::string help(const std::vector<std::string>& tokens) const override;
80  void tabCompletion(std::vector<std::string>& tokens) const override;
81  } unplugCmd;
82 
83  struct PluggableInfo final : InfoTopic {
84  explicit PluggableInfo(InfoCommand& machineInfoCommand);
85  void execute(array_ref<TclObject> tokens,
86  TclObject& result) const override;
87  std::string help(const std::vector<std::string>& tokens) const override;
88  void tabCompletion(std::vector<std::string>& tokens) const override;
89  } pluggableInfo;
90 
91  struct ConnectorInfo final : InfoTopic {
92  explicit ConnectorInfo(InfoCommand& machineInfoCommand);
93  void execute(array_ref<TclObject> tokens,
94  TclObject& result) const override;
95  std::string help(const std::vector<std::string>& tokens) const override;
96  void tabCompletion(std::vector<std::string>& tokens) const override;
97  } connectorInfo;
98 
99  struct ConnectionClassInfo final : InfoTopic {
100  explicit ConnectionClassInfo(InfoCommand& machineInfoCommand);
101  void execute(array_ref<TclObject> tokens,
102  TclObject& result) const override;
103  std::string help(const std::vector<std::string>& tokens) const override;
104  void tabCompletion(std::vector<std::string>& tokens) const override;
105  } connectionClassInfo;
106 };
107 
108 } // namespace openmsx
109 
110 #endif
Represents something you can plug devices into.
Definition: Connector.hh:20
Commands that directly influence the MSX state should send and events so that they can be recorded by...
void registerConnector(Connector &connector)
Connectors must be (un)registered.
Central administration of Connectors and Pluggables.
PluggingController(MSXMotherBoard &motherBoard)
EmuTime::param getCurrentTime() const
Convenience method: get current time.
CliComm & getCliComm()
Access to the MSX specific CliComm, so that Connectors can get it.
Pluggable * findPluggable(string_view name) const
Return the Pluggable with given name or nullptr if there is none with this name.
This class implements a subset of the proposal for std::array_ref (proposed for the next c++ standard...
Definition: array_ref.hh:19
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void registerPluggable(std::unique_ptr< Pluggable > pluggable)
Add a Pluggable to the registry.
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:15
void unregisterConnector(Connector &connector)
Connector * findConnector(string_view name) const
Return the Connector with given name or nullptr if there is none with this name.