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 "TemporaryString.hh"
8 #include "hash_set.hh"
9 #include "xxhash.hh"
10 #include <memory>
11 
12 namespace openmsx {
13 
14 class GlobalCommandController;
15 class InfoCommand;
16 class MSXEventDistributor;
17 class MSXMotherBoard;
18 class Reactor;
19 class Setting;
20 
22  : public CommandController, private MSXEventListener
23 {
24 public:
27 
28  MSXCommandController(GlobalCommandController& globalCommandController,
29  Reactor& reactor, MSXMotherBoard& motherboard,
30  MSXEventDistributor& msxEventDistributor,
31  const std::string& machineID);
33 
35  return globalCommandController;
36  }
38  return *machineInfoCommand;
39  }
40  [[nodiscard]] MSXMotherBoard& getMSXMotherBoard() const {
41  return motherboard;
42  }
43  [[nodiscard]] const std::string& getPrefix() const {
44  return machineID;
45  }
46 
47  [[nodiscard]] Command* findCommand(std::string_view name) const;
48 
52  [[nodiscard]] bool isActive() const;
53 
56  void transferSettings(const MSXCommandController& from);
57 
58  [[nodiscard]] bool hasCommand(std::string_view command) const;
59 
60  // CommandController
61  void registerCompleter(CommandCompleter& completer,
62  std::string_view str) override;
63  void unregisterCompleter(CommandCompleter& completer,
64  std::string_view str) override;
65  void registerCommand(Command& command,
66  zstring_view str) override;
67  void unregisterCommand(Command& command,
68  std::string_view str) override;
70  CliConnection* connection = nullptr) override;
71  void registerSetting(Setting& setting) override;
72  void unregisterSetting(Setting& setting) override;
73  [[nodiscard]] CliComm& getCliComm() override;
74  [[nodiscard]] Interpreter& getInterpreter() override;
75 
76 private:
77  [[nodiscard]] TemporaryString getFullName(std::string_view name);
78 
79  // MSXEventListener
80  void signalMSXEvent(const std::shared_ptr<const Event>& event,
81  EmuTime::param time) noexcept override;
82 
83  GlobalCommandController& globalCommandController;
84  Reactor& reactor;
85  MSXMotherBoard& motherboard;
86  MSXEventDistributor& msxEventDistributor;
87  std::string machineID;
88  std::unique_ptr<InfoCommand> machineInfoCommand;
89 
90  struct NameFromCommand {
91  [[nodiscard]] const std::string& operator()(const Command* c) const {
92  return c->getName();
93  }
94  };
96 
97  std::vector<Setting*> settings; // unordered
98 };
99 
100 } // namespace openmsx
101 
102 #endif
TemporaryString.
const std::string & getName() const
Definition: Completer.hh:20
const std::string & getPrefix() const
bool hasCommand(std::string_view command) const
Interpreter & getInterpreter() override
void registerCompleter(CommandCompleter &completer, std::string_view str) override
(Un)register a command completer, used to complete build-in Tcl cmds
TclObject executeCommand(zstring_view command, CliConnection *connection=nullptr) override
Execute the given command.
void unregisterCompleter(CommandCompleter &completer, std::string_view str) override
void registerCommand(Command &command, zstring_view str) override
(Un)register a command
void transferSettings(const MSXCommandController &from)
Transfer setting values from one machine to another, used for during 'reverse'.
void unregisterSetting(Setting &setting) override
bool isActive() const
Returns true iff the machine this controller belongs to is currently active.
MSXCommandController(const MSXCommandController &)=delete
MSXCommandController & operator=(const MSXCommandController &)=delete
void unregisterCommand(Command &command, std::string_view str) override
void registerSetting(Setting &setting) override
TODO.
MSXMotherBoard & getMSXMotherBoard() const
GlobalCommandController & getGlobalCommandController()
Command * findCommand(std::string_view name) const
Contains the main loop of openMSX.
Definition: Reactor.hh:67
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
Definition: zstring_view.hh:21
This file implemented 3 utility functions:
Definition: Autofire.cc:9