| 1 |
#include "ProxyCommand.hh" |
| 2 |
|
| 3 |
#include "CommandException.hh" |
| 4 |
#include "GlobalCommandController.hh" |
| 5 |
#include "MSXCommandController.hh" |
| 6 |
|
| 7 |
#include "MSXMotherBoard.hh" |
| 8 |
#include "Reactor.hh" |
| 9 |
|
| 10 |
#include "checked_cast.hh" |
| 11 |
|
| 12 |
namespace openmsx { |
| 13 |
|
| 14 |
ProxyCmd::ProxyCmd(Reactor& reactor_, std::string_view name_) |
| 15 |
: Command(reactor_.getGlobalCommandController(), name_) |
| 16 |
, reactor(reactor_) |
| 17 |
{ |
| 18 |
} |
| 19 |
|
| 20 |
Command* ProxyCmd::getMachineCommand() const |
| 21 |
{ |
| 22 |
MSXMotherBoard* motherBoard = reactor.getMotherBoard(); |
| 23 |
if (!motherBoard) return nullptr; |
| 24 |
return motherBoard->getMSXCommandController().findCommand(getName()); |
| 25 |
} |
| 26 |
|
| 27 |
void ProxyCmd::execute(std::span<const TclObject> tokens, TclObject& result) |
| 28 |
{ |
| 29 |
if (Command* command = getMachineCommand()) { |
| 30 |
if (!command->isAllowedInEmptyMachine()) { |
| 31 |
const auto* controller = checked_cast<const MSXCommandController*>( |
| 32 |
&command->getCommandController()); |
| 33 |
if (!controller->getMSXMotherBoard().getMachineConfig()) { |
| 34 |
throw CommandException( |
| 35 |
"Can't execute command in empty machine"); |
| 36 |
} |
| 37 |
} |
| 38 |
command->execute(tokens, result); |
| 39 |
} else { |
| 40 |
throw CommandException("Invalid command name \"", getName(), '"'); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
std::string ProxyCmd::help(std::span<const TclObject> tokens) const |
| 45 |
{ |
| 46 |
if (const auto* command = getMachineCommand()) { |
| 47 |
return command->help(tokens); |
| 48 |
} else { |
| 49 |
return "unknown command: " + getName(); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
void ProxyCmd::tabCompletion(std::vector<std::string>& tokens) const |
| 54 |
{ |
| 55 |
if (const auto* command = getMachineCommand()) { |
| 56 |
command->tabCompletion(tokens); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
} |