openMSX
ProxyCommand.cc
Go to the documentation of this file.
1 #include "ProxyCommand.hh"
4 #include "CommandException.hh"
5 #include "MSXMotherBoard.hh"
6 #include "Reactor.hh"
7 #include "checked_cast.hh"
8 
9 namespace openmsx {
10 
11 ProxyCmd::ProxyCmd(Reactor& reactor_, std::string_view name_)
12  : Command(reactor_.getGlobalCommandController(), name_)
13  , reactor(reactor_)
14 {
15 }
16 
17 Command* ProxyCmd::getMachineCommand() const
18 {
19  MSXMotherBoard* motherBoard = reactor.getMotherBoard();
20  if (!motherBoard) return nullptr;
21  return motherBoard->getMSXCommandController().findCommand(getName());
22 }
23 
25 {
26  if (Command* command = getMachineCommand()) {
27  if (!command->isAllowedInEmptyMachine()) {
28  auto* controller = checked_cast<MSXCommandController*>(
29  &command->getCommandController());
30  if (!controller->getMSXMotherBoard().getMachineConfig()) {
31  throw CommandException(
32  "Can't execute command in empty machine");
33  }
34  }
35  command->execute(tokens, result);
36  } else {
37  throw CommandException("Invalid command name \"", getName(), '"');
38  }
39 }
40 
41 std::string ProxyCmd::help(span<const TclObject> tokens) const
42 {
43  if (Command* command = getMachineCommand()) {
44  return command->help(tokens);
45  } else {
46  return "unknown command: " + getName();
47  }
48 }
49 
50 void ProxyCmd::tabCompletion(std::vector<std::string>& tokens) const
51 {
52  if (Command* command = getMachineCommand()) {
53  command->tabCompletion(tokens);
54  }
55 }
56 
57 } // namespace openmsx
const std::string & getName() const
Definition: Completer.hh:23
Command * findCommand(std::string_view name) const
MSXCommandController & getMSXCommandController()
void execute(span< const TclObject > tokens, TclObject &result) override
Execute this command.
Definition: ProxyCommand.cc:24
void tabCompletion(std::vector< std::string > &tokens) const override
Attempt tab completion for this command.
Definition: ProxyCommand.cc:50
std::string help(span< const TclObject > tokens) const override
Print help for this command.
Definition: ProxyCommand.cc:41
ProxyCmd(Reactor &reactor, std::string_view name)
Definition: ProxyCommand.cc:11
Contains the main loop of openMSX.
Definition: Reactor.hh:68
MSXMotherBoard * getMotherBoard() const
Definition: Reactor.cc:374
Definition: span.hh:126
This file implemented 3 utility functions:
Definition: Autofire.cc:9