PluggingController.hh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef PLUGGINGCONTROLLER_HH
  2. #define PLUGGINGCONTROLLER_HH
  3. #include "RecordedCommand.hh"
  4. #include "InfoTopic.hh"
  5. #include "EmuTime.hh"
  6. #include "string_view.hh"
  7. #include <vector>
  8. #include <memory>
  9. namespace openmsx {
  10. class MSXMotherBoard;
  11. class Connector;
  12. class Pluggable;
  13. class CliComm;
  14. /**
  15. * Central administration of Connectors and Pluggables.
  16. */
  17. class PluggingController
  18. {
  19. public:
  20. explicit PluggingController(MSXMotherBoard& motherBoard);
  21. ~PluggingController();
  22. /** Connectors must be (un)registered
  23. */
  24. void registerConnector(Connector& connector);
  25. void unregisterConnector(Connector& connector);
  26. /** Return the Connector with given name or
  27. * nullptr if there is none with this name.
  28. */
  29. Connector* findConnector(string_view name) const;
  30. /** Add a Pluggable to the registry.
  31. */
  32. void registerPluggable(std::unique_ptr<Pluggable> pluggable);
  33. /** Return the Pluggable with given name or
  34. * nullptr if there is none with this name.
  35. */
  36. Pluggable* findPluggable(string_view name) const;
  37. /** Access to the MSX specific CliComm, so that Connectors can get it.
  38. */
  39. CliComm& getCliComm();
  40. /** Convenience method: get current time.
  41. */
  42. EmuTime::param getCurrentTime() const;
  43. private:
  44. Connector& getConnector(string_view name) const;
  45. Pluggable& getPluggable(string_view name) const;
  46. MSXMotherBoard& motherBoard;
  47. std::vector<Connector*> connectors; // no order
  48. std::vector<std::unique_ptr<Pluggable>> pluggables;
  49. struct PlugCmd final : RecordedCommand {
  50. PlugCmd(CommandController& commandController,
  51. StateChangeDistributor& stateChangeDistributor,
  52. Scheduler& scheduler);
  53. void execute(array_ref<TclObject> tokens, TclObject& result,
  54. EmuTime::param time) override;
  55. std::string help(const std::vector<std::string>& tokens) const override;
  56. void tabCompletion(std::vector<std::string>& tokens) const override;
  57. bool needRecord(array_ref<TclObject> tokens) const override;
  58. } plugCmd;
  59. struct UnplugCmd final : RecordedCommand {
  60. UnplugCmd(CommandController& commandController,
  61. StateChangeDistributor& stateChangeDistributor,
  62. Scheduler& scheduler);
  63. void execute(array_ref<TclObject> tokens, TclObject& result,
  64. EmuTime::param time) override;
  65. std::string help(const std::vector<std::string>& tokens) const override;
  66. void tabCompletion(std::vector<std::string>& tokens) const override;
  67. } unplugCmd;
  68. struct PluggableInfo final : InfoTopic {
  69. explicit PluggableInfo(InfoCommand& machineInfoCommand);
  70. void execute(array_ref<TclObject> tokens,
  71. TclObject& result) const override;
  72. std::string help(const std::vector<std::string>& tokens) const override;
  73. void tabCompletion(std::vector<std::string>& tokens) const override;
  74. } pluggableInfo;
  75. struct ConnectorInfo final : InfoTopic {
  76. explicit ConnectorInfo(InfoCommand& machineInfoCommand);
  77. void execute(array_ref<TclObject> tokens,
  78. TclObject& result) const override;
  79. std::string help(const std::vector<std::string>& tokens) const override;
  80. void tabCompletion(std::vector<std::string>& tokens) const override;
  81. } connectorInfo;
  82. struct ConnectionClassInfo final : InfoTopic {
  83. explicit ConnectionClassInfo(InfoCommand& machineInfoCommand);
  84. void execute(array_ref<TclObject> tokens,
  85. TclObject& result) const override;
  86. std::string help(const std::vector<std::string>& tokens) const override;
  87. void tabCompletion(std::vector<std::string>& tokens) const override;
  88. } connectionClassInfo;
  89. };
  90. } // namespace openmsx
  91. #endif