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 "Setting.hh"
8 #include "hash_set.hh"
9 #include "xxhash.hh"
10 #include <memory>
11 
12 namespace openmsx {
13 
14 class GlobalCommandController;
15 class Reactor;
16 class MSXMotherBoard;
17 class MSXEventDistributor;
18 class InfoCommand;
19 
21  : public CommandController, private MSXEventListener
22 {
23 public:
26 
27  MSXCommandController(GlobalCommandController& globalCommandController,
28  Reactor& reactor, MSXMotherBoard& motherboard,
29  MSXEventDistributor& msxEventDistributor,
30  const std::string& machineID);
32 
34  return globalCommandController;
35  }
37  return *machineInfoCommand;
38  }
40  return motherboard;
41  }
42  const std::string& getPrefix() const {
43  return machineID;
44  }
45 
46  Command* findCommand(string_ref name) const;
47 
51  bool isActive() const;
52 
55  void transferSettings(const MSXCommandController& from);
56 
57  // CommandController
58  void registerCompleter(CommandCompleter& completer,
59  string_ref str) override;
60  void unregisterCompleter(CommandCompleter& completer,
61  string_ref str) override;
62  void registerCommand(Command& command,
63  const std::string& str) override;
64  void unregisterCommand(Command& command,
65  string_ref str) override;
66  bool hasCommand(string_ref command) const override;
67  TclObject executeCommand(const std::string& command,
68  CliConnection* connection = nullptr) override;
69  void registerSetting(Setting& setting) override;
70  void unregisterSetting(Setting& setting) override;
71  CliComm& getCliComm() override;
72  Interpreter& getInterpreter() override;
73 
74 private:
75  std::string getFullName(string_ref name);
76 
77  // MSXEventListener
78  void signalEvent(const std::shared_ptr<const Event>& event,
79  EmuTime::param time) override;
80 
81  GlobalCommandController& globalCommandController;
82  Reactor& reactor;
83  MSXMotherBoard& motherboard;
84  MSXEventDistributor& msxEventDistributor;
85  std::string machineID;
86  std::unique_ptr<InfoCommand> machineInfoCommand;
87 
88  struct NameFromCommand {
89  const std::string& operator()(const Command* c) const {
90  return c->getName();
91  }
92  };
94 
95  std::vector<Setting*> settings; // unordered
96 };
97 
98 } // namespace openmsx
99 
100 #endif
const std::string & getPrefix() const
void transferSettings(const MSXCommandController &from)
Transfer setting values from one machine to another, used for during 'reverse'.
Contains the main loop of openMSX.
Definition: Reactor.hh:61
TclObject executeCommand(const std::string &command, CliConnection *connection=nullptr) override
Execute the given command.
MSXCommandController(const MSXCommandController &)=delete
bool isActive() const
Returns true iff the machine this controller belongs to is currently active.
void unregisterCommand(Command &command, string_ref str) override
const std::string & getName() const
Definition: Completer.hh:16
void unregisterSetting(Setting &setting) override
GlobalCommandController & getGlobalCommandController()
Command * findCommand(string_ref name) const
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
void registerCommand(Command &command, const std::string &str) override
(Un)register a command
Interpreter & getInterpreter() override
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void registerCompleter(CommandCompleter &completer, string_ref str) override
(Un)register a command completer, used to complete build-in Tcl cmds
MSXCommandController & operator=(const MSXCommandController &)=delete
void registerSetting(Setting &setting) override
TODO.
MSXMotherBoard & getMSXMotherBoard() const
bool hasCommand(string_ref command) const override
Does a command with this name already exist?
void unregisterCompleter(CommandCompleter &completer, string_ref str) override