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
9namespace openmsx {
10
11ProxyCmd::ProxyCmd(Reactor& reactor_, std::string_view name_)
12 : Command(reactor_.getGlobalCommandController(), name_)
13 , reactor(reactor_)
14{
15}
16
17Command* ProxyCmd::getMachineCommand() const
18{
19 MSXMotherBoard* motherBoard = reactor.getMotherBoard();
20 if (!motherBoard) return nullptr;
21 return motherBoard->getMSXCommandController().findCommand(getName());
22}
23
24void ProxyCmd::execute(std::span<const TclObject> tokens, TclObject& result)
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
41std::string ProxyCmd::help(std::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
50void 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:27
Command * findCommand(std::string_view name) const
MSXCommandController & getMSXCommandController()
void tabCompletion(std::vector< std::string > &tokens) const override
Attempt tab completion for this command.
std::string help(std::span< const TclObject > tokens) const override
Print help for this command.
ProxyCmd(Reactor &reactor, std::string_view name)
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
Contains the main loop of openMSX.
Definition Reactor.hh:74
MSXMotherBoard * getMotherBoard() const
Definition Reactor.cc:409
This file implemented 3 utility functions:
Definition Autofire.cc:11