openMSX
GlobalCommandController.hh
Go to the documentation of this file.
1#ifndef GLOBALCOMMANDCONTROLLER_HH
2#define GLOBALCOMMANDCONTROLLER_HH
3
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 "TclObject.hh"
13#include "hash_map.hh"
14#include "xxhash.hh"
15#include <string>
16#include <vector>
17#include <memory>
18
19namespace openmsx {
20
21class EventDistributor;
22class Reactor;
23class GlobalCliComm;
24class ProxyCmd;
25class ProxySetting;
26
37
39 , public CommandController
40{
41public:
43 GlobalCliComm& cliComm,
44 Reactor& reactor);
50
51 [[nodiscard]] InfoCommand& getOpenMSXInfoCommand() { return openMSXInfoCommand; }
52
56 void source(const std::string& script);
57
58 void registerProxyCommand(std::string_view name);
59 void unregisterProxyCommand(std::string_view name);
60
63
64 // CommandController
65 void registerCompleter(CommandCompleter& completer,
66 std::string_view str) override;
68 std::string_view str) override;
69 void registerCommand(Command& command,
70 zstring_view str) override;
71 void unregisterCommand(Command& command,
72 std::string_view str) override;
74 CliConnection* connection = nullptr) override;
75 void registerSetting(Setting& setting) override;
76 void unregisterSetting(Setting& setting) override;
77 [[nodiscard]] CliComm& getCliComm() override;
78 [[nodiscard]] Interpreter& getInterpreter() override;
79
83 [[nodiscard]] std::string tabCompletion(std::string_view command);
84
89 [[nodiscard]] bool isComplete(zstring_view command);
90
91 [[nodiscard]] SettingsConfig& getSettingsConfig() { return settingsConfig; }
92 [[nodiscard]] SettingsManager& getSettingsManager() { return settingsConfig.getSettingsManager(); }
93 [[nodiscard]] CliConnection* getConnection() const { return connection; }
94 [[nodiscard]] Reactor& getReactor() const { return reactor; }
95 [[nodiscard]] const HotKey& getHotKey() const { return hotKey; }
96
97private:
98 void tabCompletion(std::vector<std::string>& tokens);
99
100 using ProxySettings =
101 std::vector<std::pair<std::unique_ptr<ProxySetting>, unsigned>>;
102 ProxySettings::iterator findProxySetting(std::string_view name);
103
104 GlobalCliComm& cliComm;
105 CliConnection* connection = nullptr;
106
107 Reactor& reactor;
108
109 Interpreter interpreter;
110 InfoCommand openMSXInfoCommand;
111 HotKey hotKey;
112 SettingsConfig settingsConfig;
113
114 struct HelpCmd final : Command {
115 explicit HelpCmd(GlobalCommandController& controller);
116 void execute(std::span<const TclObject> tokens, TclObject& result) override;
117 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
118 void tabCompletion(std::vector<std::string>& tokens) const override;
119 } helpCmd;
120
121 struct TabCompletionCmd final : Command {
122 explicit TabCompletionCmd(GlobalCommandController& controller);
123 void execute(std::span<const TclObject> tokens, TclObject& result) override;
124 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
125 } tabCompletionCmd;
126
127 struct UpdateCmd final : Command {
128 explicit UpdateCmd(CommandController& commandController);
129 void execute(std::span<const TclObject> tokens, TclObject& result) override;
130 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
131 void tabCompletion(std::vector<std::string>& tokens) const override;
132 private:
133 CliConnection& getConnection();
134 } updateCmd;
135
136 struct PlatformInfo final : InfoTopic {
137 explicit PlatformInfo(InfoCommand& openMSXInfoCommand);
138 void execute(std::span<const TclObject> tokens,
139 TclObject& result) const override;
140 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
141 } platformInfo;
142
143 struct VersionInfo final : InfoTopic {
144 explicit VersionInfo(InfoCommand& openMSXInfoCommand);
145 void execute(std::span<const TclObject> tokens,
146 TclObject& result) const override;
147 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
148 } versionInfo;
149
150 RomInfoTopic romInfoTopic;
151
152 struct NameFromProxy {
153 template<typename Pair>
154 [[nodiscard]] const std::string& operator()(const Pair& p) const {
155 return p.second->getName();
156 }
157 };
159 ProxySettings proxySettings;
160};
161
162} // namespace openmsx
163
164#endif
BaseSetting * setting
hash_map< std::string, CommandCompleter *, XXHasher > commandCompleters
void registerProxySetting(const Setting &setting)
void unregisterProxySetting(const Setting &setting)
GlobalCommandController(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
GlobalCommandController & operator=(GlobalCommandController &&)=delete
GlobalCommandController & operator=(const GlobalCommandController &)=delete
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:75
SettingsManager & getSettingsManager()
Manages all settings.
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
This file implemented 3 utility functions:
Definition Autofire.cc:11