| 1 |
#ifndef MSXCOMMANDCONTROLLER_HH |
| 2 |
#define MSXCOMMANDCONTROLLER_HH |
| 3 |
|
| 4 |
#include "Command.hh" |
| 5 |
#include "CommandController.hh" |
| 6 |
#include "InfoCommand.hh" |
| 7 |
|
| 8 |
#include "MSXCliComm.hh" |
| 9 |
#include "MSXEventListener.hh" |
| 10 |
|
| 11 |
#include "TemporaryString.hh" |
| 12 |
#include "hash_set.hh" |
| 13 |
#include "xxhash.hh" |
| 14 |
|
| 15 |
#include <memory> |
| 16 |
|
| 17 |
namespace openmsx { |
| 18 |
|
| 19 |
class GlobalCommandController; |
| 20 |
class MSXEventDistributor; |
| 21 |
class MSXMotherBoard; |
| 22 |
class Reactor; |
| 23 |
class Setting; |
| 24 |
|
| 25 |
class MSXCommandController final |
| 26 |
: public CommandController, private MSXEventListener |
| 27 |
{ |
| 28 |
public: |
| 29 |
MSXCommandController(GlobalCommandController& globalCommandController, |
| 30 |
Reactor& reactor, MSXMotherBoard& motherboard, |
| 31 |
MSXEventDistributor& msxEventDistributor, |
| 32 |
const std::string& machineID); |
| 33 |
MSXCommandController(const MSXCommandController&) = delete; |
| 34 |
MSXCommandController(MSXCommandController&&) = delete; |
| 35 |
MSXCommandController& operator=(const MSXCommandController&) = delete; |
| 36 |
MSXCommandController& operator=(MSXCommandController&&) = delete; |
| 37 |
~MSXCommandController(); |
| 38 |
|
| 39 |
[[nodiscard]] GlobalCommandController& getGlobalCommandController() { |
| 40 |
return globalCommandController; |
| 41 |
} |
| 42 |
[[nodiscard]] InfoCommand& getMachineInfoCommand() { |
| 43 |
return *machineInfoCommand; |
| 44 |
} |
| 45 |
[[nodiscard]] MSXMotherBoard& getMSXMotherBoard() const { |
| 46 |
return motherboard; |
| 47 |
} |
| 48 |
[[nodiscard]] const std::string& getPrefix() const { |
| 49 |
return machineID; |
| 50 |
} |
| 51 |
|
| 52 |
[[nodiscard]] Command* findCommand(std::string_view name) const; |
| 53 |
[[nodiscard]] Setting* findSetting(std::string_view name) const; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
[[nodiscard]] bool isActive() const; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
void transferSettings(const MSXCommandController& from); |
| 63 |
|
| 64 |
[[nodiscard]] bool hasCommand(std::string_view command) const; |
| 65 |
|
| 66 |
|
| 67 |
void registerCompleter(CommandCompleter& completer, |
| 68 |
std::string_view str) override; |
| 69 |
void unregisterCompleter(CommandCompleter& completer, |
| 70 |
std::string_view str) override; |
| 71 |
void registerCommand(Command& command, |
| 72 |
zstring_view str) override; |
| 73 |
void unregisterCommand(Command& command, |
| 74 |
std::string_view str) override; |
| 75 |
TclObject executeCommand(zstring_view command, |
| 76 |
CliConnection* connection = nullptr) override; |
| 77 |
void registerSetting(Setting& setting) override; |
| 78 |
void unregisterSetting(Setting& setting) override; |
| 79 |
[[nodiscard]] MSXCliComm& getCliComm() override; |
| 80 |
[[nodiscard]] Interpreter& getInterpreter() override; |
| 81 |
|
| 82 |
private: |
| 83 |
[[nodiscard]] TemporaryString getFullName(std::string_view name); |
| 84 |
|
| 85 |
|
| 86 |
void signalMSXEvent(const Event& event, |
| 87 |
EmuTime time) noexcept override; |
| 88 |
|
| 89 |
GlobalCommandController& globalCommandController; |
| 90 |
Reactor& reactor; |
| 91 |
MSXMotherBoard& motherboard; |
| 92 |
MSXEventDistributor& msxEventDistributor; |
| 93 |
std::string machineID; |
| 94 |
std::optional<InfoCommand> machineInfoCommand; |
| 95 |
|
| 96 |
struct NameFromCommand { |
| 97 |
[[nodiscard]] const std::string& operator()(const Command* c) const { |
| 98 |
return c->getName(); |
| 99 |
} |
| 100 |
}; |
| 101 |
hash_set<Command*, NameFromCommand, XXHasher> commandMap; |
| 102 |
|
| 103 |
std::vector<Setting*> settings; |
| 104 |
}; |
| 105 |
|
| 106 |
} |
| 107 |
|
| 108 |
#endif |