openMSX
MSXCommandController.hh
Go to the documentation of this file.
1 #ifndef MSXCOMMANDCONTROLLER_HH
2 #define MSXCOMMANDCONTROLLER_HH
3 
4 #include "CommandController.hh"
5 #include "Command.hh"
6 #include "MSXEventListener.hh"
7 #include "hash_set.hh"
8 #include "xxhash.hh"
9 #include <memory>
10 
11 namespace openmsx {
12 
13 class GlobalCommandController;
14 class InfoCommand;
15 class MSXEventDistributor;
16 class MSXMotherBoard;
17 class Reactor;
18 class Setting;
19 
21  : public CommandController, private MSXEventListener
22 {
23 public:
26 
27  MSXCommandController(GlobalCommandController& globalCommandController,
28  Reactor& reactor, MSXMotherBoard& motherboard,
29  MSXEventDistributor& msxEventDistributor,
30  const std::string& machineID);
32 
34  return globalCommandController;
35  }
37  return *machineInfoCommand;
38  }
40  return motherboard;
41  }
42  const std::string& getPrefix() const {
43  return machineID;
44  }
45 
46  Command* findCommand(std::string_view name) const;
47 
51  bool isActive() const;
52 
55  void transferSettings(const MSXCommandController& from);
56 
57  // CommandController
58  void registerCompleter(CommandCompleter& completer,
59  std::string_view str) override;
60  void unregisterCompleter(CommandCompleter& completer,
61  std::string_view str) override;
62  void registerCommand(Command& command,
63  const std::string& str) override;
64  void unregisterCommand(Command& command,
65  std::string_view str) override;
66  bool hasCommand(std::string_view command) const override;
67  TclObject executeCommand(const std::string& command,
68  CliConnection* connection = nullptr) override;
69  void registerSetting(Setting& setting) override;
70  void unregisterSetting(Setting& setting) override;
71  CliComm& getCliComm() override;
72  Interpreter& getInterpreter() override;
73 
74 private:
75  std::string getFullName(std::string_view name);
76 
77  // MSXEventListener
78  void signalMSXEvent(const std::shared_ptr<const Event>& event,
79  EmuTime::param time) override;
80 
81  GlobalCommandController& globalCommandController;
82  Reactor& reactor;
83  MSXMotherBoard& motherboard;
84  MSXEventDistributor& msxEventDistributor;
85  std::string machineID;
86  std::unique_ptr<InfoCommand> machineInfoCommand;
87 
88  struct NameFromCommand {
89  const std::string& operator()(const Command* c) const {
90  return c->getName();
91  }
92  };
94 
95  std::vector<Setting*> settings; // unordered
96 };
97 
98 } // namespace openmsx
99 
100 #endif
openmsx::MSXCommandController::hasCommand
bool hasCommand(std::string_view command) const override
Does a command with this name already exist?
Definition: MSXCommandController.cc:130
xxhash.hh
openmsx::CommandController
Definition: CommandController.hh:17
openmsx::MSXCommandController::unregisterCompleter
void unregisterCompleter(CommandCompleter &completer, std::string_view str) override
Definition: MSXCommandController.cc:97
openmsx::MSXEventDistributor
Definition: MSXEventDistributor.hh:13
openmsx::MSXCommandController::~MSXCommandController
~MSXCommandController()
Definition: MSXCommandController.cc:41
openmsx::MSXEventListener
Definition: MSXEventListener.hh:11
openmsx::MSXCommandController::getCliComm
CliComm & getCliComm() override
Definition: MSXCommandController.cc:141
openmsx::Setting
Definition: Setting.hh:119
hash_set.hh
openmsx::CliConnection
Definition: CliConnection.hh:19
openmsx::MSXCommandController::operator=
MSXCommandController & operator=(const MSXCommandController &)=delete
openmsx::MSXCommandController::registerCompleter
void registerCompleter(CommandCompleter &completer, std::string_view str) override
(Un)register a command completer, used to complete build-in Tcl cmds
Definition: MSXCommandController.cc:90
openmsx::Reactor
Contains the main loop of openMSX.
Definition: Reactor.hh:66
openmsx::MSXCommandController::unregisterSetting
void unregisterSetting(Setting &setting) override
Definition: MSXCommandController.cc:115
CommandController.hh
openmsx::CommandCompleter
Definition: Command.hh:19
MSXEventListener.hh
openmsx::InfoCommand
Definition: InfoCommand.hh:11
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:59
openmsx::MSXCommandController::getPrefix
const std::string & getPrefix() const
Definition: MSXCommandController.hh:42
openmsx::MSXCommandController::findCommand
Command * findCommand(std::string_view name) const
Definition: MSXCommandController.cc:124
openmsx::MSXCommandController::executeCommand
TclObject executeCommand(const std::string &command, CliConnection *connection=nullptr) override
Execute the given command.
Definition: MSXCommandController.cc:135
openmsx::MSXCommandController::isActive
bool isActive() const
Returns true iff the machine this controller belongs to is currently active.
Definition: MSXCommandController.cc:167
openmsx::MSXCommandController::MSXCommandController
MSXCommandController(const MSXCommandController &)=delete
openmsx::MSXCommandController::getGlobalCommandController
GlobalCommandController & getGlobalCommandController()
Definition: MSXCommandController.hh:33
openmsx::MSXCommandController::getMSXMotherBoard
MSXMotherBoard & getMSXMotherBoard() const
Definition: MSXCommandController.hh:39
openmsx::MSXCommandController::registerCommand
void registerCommand(Command &command, const std::string &str) override
(Un)register a command
Definition: MSXCommandController.cc:66
openmsx::MSXCommandController::transferSettings
void transferSettings(const MSXCommandController &from)
Transfer setting values from one machine to another, used for during 'reverse'.
Definition: MSXCommandController.cc:172
Command.hh
hash_set
Definition: hash_set.hh:265
openmsx::Command
Definition: Command.hh:40
openmsx::CliComm
Definition: CliComm.hh:10
openmsx::MSXCommandController::getInterpreter
Interpreter & getInterpreter() override
Definition: MSXCommandController.cc:146
openmsx::TclObject
Definition: TclObject.hh:21
openmsx::MSXCommandController
Definition: MSXCommandController.hh:20
openmsx::MSXCommandController::unregisterCommand
void unregisterCommand(Command &command, std::string_view str) override
Definition: MSXCommandController.cc:79
openmsx::MSXCommandController::getMachineInfoCommand
InfoCommand & getMachineInfoCommand()
Definition: MSXCommandController.hh:36
openmsx::Interpreter
Definition: Interpreter.hh:16
openmsx::MSXCommandController::registerSetting
void registerSetting(Setting &setting) override
TODO.
Definition: MSXCommandController.cc:104
openmsx::GlobalCommandController
Definition: GlobalCommandController.hh:35
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::Completer::getName
const std::string & getName() const
Definition: Completer.hh:20