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 
33 };
34 
36  , public CommandController
37 {
38 public:
40  GlobalCommandController& operator=(const GlobalCommandController&) = delete;
41 
42  GlobalCommandController(EventDistributor& eventDistributor,
43  GlobalCliComm& cliComm,
44  Reactor& reactor);
46 
47  InfoCommand& getOpenMSXInfoCommand() { return openMSXInfoCommand; }
48 
52  void source(const std::string& script);
53 
54  void registerProxyCommand(const std::string& name);
55  void unregisterProxyCommand(std::string_view name);
56 
57  void registerProxySetting(Setting& setting);
58  void unregisterProxySetting(Setting& setting);
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  const std::string& str) override;
67  void unregisterCommand(Command& command,
68  std::string_view str) override;
69  bool hasCommand(std::string_view command) const override;
70  TclObject executeCommand(const std::string& command,
71  CliConnection* connection = nullptr) override;
72  void registerSetting(Setting& setting) override;
73  void unregisterSetting(Setting& setting) override;
74  CliComm& getCliComm() override;
75  Interpreter& getInterpreter() override;
76 
80  std::string tabCompletion(std::string_view command);
81 
86  bool isComplete(const std::string& command);
87 
88  SettingsConfig& getSettingsConfig() { return settingsConfig; }
89  SettingsManager& getSettingsManager() { return settingsConfig.getSettingsManager(); }
90  CliConnection* getConnection() const { return connection; }
91 
92 private:
93  void split(std::string_view str,
94  std::vector<std::string>& tokens, char delimiter);
95  std::string removeEscaping(const std::string& str);
96  std::vector<std::string> removeEscaping(
97  const std::vector<std::string>& input, bool keepLastIfEmpty);
98  std::string addEscaping(const std::string& str, bool quote, bool finished);
99 
100  void tabCompletion(std::vector<std::string>& tokens);
101 
102  using ProxySettings =
103  std::vector<std::pair<std::unique_ptr<ProxySetting>, unsigned>>;
104  ProxySettings::iterator findProxySetting(std::string_view name);
105 
106  GlobalCliComm& cliComm;
107  CliConnection* connection;
108 
109  Reactor& reactor;
110 
111  Interpreter interpreter;
112  InfoCommand openMSXInfoCommand;
113  HotKey hotKey;
114  SettingsConfig settingsConfig;
115 
116  struct HelpCmd final : Command {
117  explicit HelpCmd(GlobalCommandController& controller);
118  void execute(span<const TclObject> tokens, TclObject& result) override;
119  std::string help(const std::vector<std::string>& tokens) const override;
120  void tabCompletion(std::vector<std::string>& tokens) const override;
121  } helpCmd;
122 
123  struct TabCompletionCmd final : Command {
124  explicit TabCompletionCmd(GlobalCommandController& controller);
125  void execute(span<const TclObject> tokens, TclObject& result) override;
126  std::string help(const std::vector<std::string>& tokens) const override;
127  } tabCompletionCmd;
128 
129  struct UpdateCmd final : Command {
130  explicit UpdateCmd(CommandController& commandController);
131  void execute(span<const TclObject> tokens, TclObject& result) override;
132  std::string help(const std::vector<std::string>& tokens) const override;
133  void tabCompletion(std::vector<std::string>& tokens) const override;
134  private:
135  CliConnection& getConnection();
136  } updateCmd;
137 
138  struct PlatformInfo final : InfoTopic {
139  explicit PlatformInfo(InfoCommand& openMSXInfoCommand);
140  void execute(span<const TclObject> tokens,
141  TclObject& result) const override;
142  std::string help(const std::vector<std::string>& tokens) const override;
143  } platformInfo;
144 
145  struct VersionInfo final : InfoTopic {
146  explicit VersionInfo(InfoCommand& openMSXInfoCommand);
147  void execute(span<const TclObject> tokens,
148  TclObject& result) const override;
149  std::string help(const std::vector<std::string>& tokens) const override;
150  } versionInfo;
151 
152  RomInfoTopic romInfoTopic;
153 
154  struct NameFromProxy {
155  template<typename Pair>
156  const std::string& operator()(const Pair& p) const {
157  return p.second->getName();
158  }
159  };
160  hash_set<std::pair<unsigned, std::unique_ptr<ProxyCmd>>, NameFromProxy, XXHasher> proxyCommandMap;
161  ProxySettings proxySettings;
162 };
163 
164 } // namespace openmsx
165 
166 #endif
Contains the main loop of openMSX.
Definition: Reactor.hh:66
hash_map< std::string, Command *, XXHasher > commands
vector< string_view > split(string_view str, char chars)
Definition: StringOp.cc:193
Definition: span.hh:34
const std::string & getName() const
Definition: Completer.hh:20
Manages all settings.
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
hash_map< std::string, CommandCompleter *, XXHasher > commandCompleters