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
28{
29protected:
31
32#ifdef DEBUG
34#endif
36};
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
95private:
96 void tabCompletion(std::vector<std::string>& tokens);
97
98 using ProxySettings =
99 std::vector<std::pair<std::unique_ptr<ProxySetting>, unsigned>>;
100 ProxySettings::iterator findProxySetting(std::string_view name);
101
102 GlobalCliComm& cliComm;
103 CliConnection* connection = nullptr;
104
105 Reactor& reactor;
106
107 Interpreter interpreter;
108 InfoCommand openMSXInfoCommand;
109 HotKey hotKey;
110 SettingsConfig settingsConfig;
111
112 struct HelpCmd final : Command {
113 explicit HelpCmd(GlobalCommandController& controller);
114 void execute(std::span<const TclObject> tokens, TclObject& result) override;
115 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
116 void tabCompletion(std::vector<std::string>& tokens) const override;
117 } helpCmd;
118
119 struct TabCompletionCmd final : Command {
120 explicit TabCompletionCmd(GlobalCommandController& controller);
121 void execute(std::span<const TclObject> tokens, TclObject& result) override;
122 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
123 } tabCompletionCmd;
124
125 struct UpdateCmd final : Command {
126 explicit UpdateCmd(CommandController& commandController);
127 void execute(std::span<const TclObject> tokens, TclObject& result) override;
128 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
129 void tabCompletion(std::vector<std::string>& tokens) const override;
130 private:
131 CliConnection& getConnection();
132 } updateCmd;
133
134 struct PlatformInfo final : InfoTopic {
135 explicit PlatformInfo(InfoCommand& openMSXInfoCommand);
136 void execute(std::span<const TclObject> tokens,
137 TclObject& result) const override;
138 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
139 } platformInfo;
140
141 struct VersionInfo final : InfoTopic {
142 explicit VersionInfo(InfoCommand& openMSXInfoCommand);
143 void execute(std::span<const TclObject> tokens,
144 TclObject& result) const override;
145 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
146 } versionInfo;
147
148 RomInfoTopic romInfoTopic;
149
150 struct NameFromProxy {
151 template<typename Pair>
152 [[nodiscard]] const std::string& operator()(const Pair& p) const {
153 return p.second->getName();
154 }
155 };
157 ProxySettings proxySettings;
158};
159
160} // namespace openmsx
161
162#endif
BaseSetting * setting
Definition: Interpreter.cc:28
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:68
SettingsManager & getSettingsManager()
Manages all settings.
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
Definition: zstring_view.hh:22
This file implemented 3 utility functions:
Definition: Autofire.cc:9