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:
44
46 GlobalCliComm& cliComm,
47 Reactor& reactor);
49
50 [[nodiscard]] InfoCommand& getOpenMSXInfoCommand() { return openMSXInfoCommand; }
51
55 void source(const std::string& script);
56
57 void registerProxyCommand(std::string_view name);
58 void unregisterProxyCommand(std::string_view name);
59
62
63 // CommandController
64 void registerCompleter(CommandCompleter& completer,
65 std::string_view str) override;
67 std::string_view str) override;
68 void registerCommand(Command& command,
69 zstring_view str) override;
70 void unregisterCommand(Command& command,
71 std::string_view str) override;
73 CliConnection* connection = nullptr) override;
74 void registerSetting(Setting& setting) override;
75 void unregisterSetting(Setting& setting) override;
76 [[nodiscard]] CliComm& getCliComm() override;
77 [[nodiscard]] Interpreter& getInterpreter() override;
78
82 [[nodiscard]] std::string tabCompletion(std::string_view command);
83
88 [[nodiscard]] bool isComplete(zstring_view command);
89
90 [[nodiscard]] SettingsConfig& getSettingsConfig() { return settingsConfig; }
91 [[nodiscard]] SettingsManager& getSettingsManager() { return settingsConfig.getSettingsManager(); }
92 [[nodiscard]] CliConnection* getConnection() const { return connection; }
93 [[nodiscard]] Reactor& getReactor() const { return reactor; }
94 [[nodiscard]] const HotKey& getHotKey() const { return hotKey; }
95
96private:
97 void tabCompletion(std::vector<std::string>& tokens);
98
99 using ProxySettings =
100 std::vector<std::pair<std::unique_ptr<ProxySetting>, unsigned>>;
101 ProxySettings::iterator findProxySetting(std::string_view name);
102
103 GlobalCliComm& cliComm;
104 CliConnection* connection = nullptr;
105
106 Reactor& reactor;
107
108 Interpreter interpreter;
109 InfoCommand openMSXInfoCommand;
110 HotKey hotKey;
111 SettingsConfig settingsConfig;
112
113 struct HelpCmd final : Command {
114 explicit HelpCmd(GlobalCommandController& controller);
115 void execute(std::span<const TclObject> tokens, TclObject& result) override;
116 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
117 void tabCompletion(std::vector<std::string>& tokens) const override;
118 } helpCmd;
119
120 struct TabCompletionCmd final : Command {
121 explicit TabCompletionCmd(GlobalCommandController& controller);
122 void execute(std::span<const TclObject> tokens, TclObject& result) override;
123 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
124 } tabCompletionCmd;
125
126 struct UpdateCmd final : Command {
127 explicit UpdateCmd(CommandController& commandController);
128 void execute(std::span<const TclObject> tokens, TclObject& result) override;
129 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
130 void tabCompletion(std::vector<std::string>& tokens) const override;
131 private:
132 CliConnection& getConnection();
133 } updateCmd;
134
135 struct PlatformInfo final : InfoTopic {
136 explicit PlatformInfo(InfoCommand& openMSXInfoCommand);
137 void execute(std::span<const TclObject> tokens,
138 TclObject& result) const override;
139 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
140 } platformInfo;
141
142 struct VersionInfo final : InfoTopic {
143 explicit VersionInfo(InfoCommand& openMSXInfoCommand);
144 void execute(std::span<const TclObject> tokens,
145 TclObject& result) const override;
146 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
147 } versionInfo;
148
149 RomInfoTopic romInfoTopic;
150
151 struct NameFromProxy {
152 template<typename Pair>
153 [[nodiscard]] const std::string& operator()(const Pair& p) const {
154 return p.second->getName();
155 }
156 };
158 ProxySettings proxySettings;
159};
160
161} // namespace openmsx
162
163#endif
BaseSetting * setting
hash_map< std::string, CommandCompleter *, XXHasher > commandCompleters
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=(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:72
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:9