openMSX
GlobalCommandController.hh
Go to the documentation of this file.
1 #ifndef GLOBALCOMMANDCONTROLLER_HH
2 #define GLOBALCOMMANDCONTROLLER_HH
3 
4 #include "CommandController.hh"
5 #include "Command.hh"
6 #include "Interpreter.hh"
7 #include "InfoCommand.hh"
8 #include "InfoTopic.hh"
9 #include "HotKey.hh"
10 #include "SettingsConfig.hh"
11 #include "RomInfoTopic.hh"
12 #include "hash_map.hh"
13 #include "xxhash.hh"
14 #include <string>
15 #include <vector>
16 #include <memory>
17 
18 namespace openmsx {
19 
20 class EventDistributor;
21 class Reactor;
22 class GlobalCliComm;
23 class ProxyCmd;
24 class ProxySetting;
25 
27 {
28 protected:
30 
31 #ifdef DEBUG
33 #endif
35 };
36 
38  , public CommandController
39 {
40 public:
43 
44  GlobalCommandController(EventDistributor& eventDistributor,
45  GlobalCliComm& cliComm,
46  Reactor& reactor);
48 
49  [[nodiscard]] InfoCommand& getOpenMSXInfoCommand() { return openMSXInfoCommand; }
50 
54  void source(const std::string& script);
55 
56  void registerProxyCommand(std::string_view name);
57  void unregisterProxyCommand(std::string_view name);
58 
59  void registerProxySetting(Setting& setting);
60  void unregisterProxySetting(Setting& setting);
61 
62  // CommandController
63  void registerCompleter(CommandCompleter& completer,
64  std::string_view str) override;
65  void unregisterCompleter(CommandCompleter& completer,
66  std::string_view str) override;
67  void registerCommand(Command& command,
68  zstring_view str) override;
69  void unregisterCommand(Command& command,
70  std::string_view str) override;
72  CliConnection* connection = nullptr) override;
73  void registerSetting(Setting& setting) override;
74  void unregisterSetting(Setting& setting) override;
75  [[nodiscard]] CliComm& getCliComm() override;
76  [[nodiscard]] Interpreter& getInterpreter() override;
77 
81  [[nodiscard]] std::string tabCompletion(std::string_view command);
82 
87  [[nodiscard]] bool isComplete(zstring_view command);
88 
89  [[nodiscard]] SettingsConfig& getSettingsConfig() { return settingsConfig; }
90  [[nodiscard]] SettingsManager& getSettingsManager() { return settingsConfig.getSettingsManager(); }
91  [[nodiscard]] CliConnection* getConnection() const { return connection; }
92 
93 private:
94  void tabCompletion(std::vector<std::string>& tokens);
95 
96  using ProxySettings =
97  std::vector<std::pair<std::unique_ptr<ProxySetting>, unsigned>>;
98  ProxySettings::iterator findProxySetting(std::string_view name);
99 
100  GlobalCliComm& cliComm;
101  CliConnection* connection;
102 
103  Reactor& reactor;
104 
105  Interpreter interpreter;
106  InfoCommand openMSXInfoCommand;
107  HotKey hotKey;
108  SettingsConfig settingsConfig;
109 
110  struct HelpCmd final : Command {
111  explicit HelpCmd(GlobalCommandController& controller);
112  void execute(span<const TclObject> tokens, TclObject& result) override;
113  [[nodiscard]] std::string help(const std::vector<std::string>& tokens) const override;
114  void tabCompletion(std::vector<std::string>& tokens) const override;
115  } helpCmd;
116 
117  struct TabCompletionCmd final : Command {
118  explicit TabCompletionCmd(GlobalCommandController& controller);
119  void execute(span<const TclObject> tokens, TclObject& result) override;
120  [[nodiscard]] std::string help(const std::vector<std::string>& tokens) const override;
121  } tabCompletionCmd;
122 
123  struct UpdateCmd final : Command {
124  explicit UpdateCmd(CommandController& commandController);
125  void execute(span<const TclObject> tokens, TclObject& result) override;
126  [[nodiscard]] std::string help(const std::vector<std::string>& tokens) const override;
127  void tabCompletion(std::vector<std::string>& tokens) const override;
128  private:
129  CliConnection& getConnection();
130  } updateCmd;
131 
132  struct PlatformInfo final : InfoTopic {
133  explicit PlatformInfo(InfoCommand& openMSXInfoCommand);
134  void execute(span<const TclObject> tokens,
135  TclObject& result) const override;
136  [[nodiscard]] std::string help(const std::vector<std::string>& tokens) const override;
137  } platformInfo;
138 
139  struct VersionInfo final : InfoTopic {
140  explicit VersionInfo(InfoCommand& openMSXInfoCommand);
141  void execute(span<const TclObject> tokens,
142  TclObject& result) const override;
143  [[nodiscard]] std::string help(const std::vector<std::string>& tokens) const override;
144  } versionInfo;
145 
146  RomInfoTopic romInfoTopic;
147 
148  struct NameFromProxy {
149  template<typename Pair>
150  [[nodiscard]] const std::string& operator()(const Pair& p) const {
151  return p.second->getName();
152  }
153  };
154  hash_set<std::pair<unsigned, std::unique_ptr<ProxyCmd>>, NameFromProxy, XXHasher> proxyCommandMap;
155  ProxySettings proxySettings;
156 };
157 
158 } // namespace openmsx
159 
160 #endif
hash_map< std::string, CommandCompleter *, XXHasher > commandCompleters
GlobalCommandController & operator=(const GlobalCommandController &)=delete
GlobalCommandController(const GlobalCommandController &)=delete
void registerSetting(Setting &setting) override
TODO.
std::string tabCompletion(std::string_view command)
Complete the given command.
void registerProxyCommand(std::string_view name)
void unregisterProxyCommand(std::string_view name)
void registerCommand(Command &command, zstring_view str) override
(Un)register a command
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 unregisterSetting(Setting &setting) override
void unregisterCompleter(CommandCompleter &completer, std::string_view str) override
void unregisterCommand(Command &command, std::string_view str) override
bool isComplete(zstring_view command)
Returns true iff the command is complete (all braces, quotes etc.
void source(const std::string &script)
Executes all defined auto commands.
Contains the main loop of openMSX.
Definition: Reactor.hh:67
SettingsManager & getSettingsManager()
Manages all settings.
Definition: span.hh:126
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