openMSX
TclCallbackMessages.cc
Go to the documentation of this file.
2#include "GlobalCliComm.hh"
3
4namespace openmsx {
5
7 CommandController& controller)
8 : cliComm(cliComm_)
9 , messageCallback(
10 controller, "message_callback",
11 "Tcl proc called when a new message is available",
12 "",
13 Setting::Save::YES, // the user must be able to override
14 true) // this is a message callback (so the TclCallback must prevent recursion)
15{
16 cliComm.addListener(std::unique_ptr<CliListener>(this)); // wrap in unique_ptr
17}
18
20{
21 std::unique_ptr<CliListener> ptr = cliComm.removeListener(*this);
22 (void)ptr.release();
23}
24
25void TclCallbackMessages::log(CliComm::LogLevel level, std::string_view message, float fraction) noexcept
26{
27 // TODO Possibly remove this? No longer needed now that ImGui displays messages?
28 try {
29 if (level == CliComm::LogLevel::PROGRESS && fraction >= 0.0f) {
30 messageCallback.execute(tmpStrCat(message, "... ", int(100.0f * fraction), '%'),
31 toString(level));
32 } else {
33 messageCallback.execute(message, toString(level));
34 }
35 } catch (TclObject& command) {
36 // Command for this message could not be executed yet.
37 // Buffer until we can redo them.
38 postponedCommands.push_back(command);
39 }
40}
41
43 CliComm::UpdateType /*type*/, std::string_view /*machine*/,
44 std::string_view /*name*/, std::string_view /*value*/) noexcept
45{
46 // ignore
47}
48
50{
51 for (auto& command: postponedCommands) {
52 messageCallback.executeCommon(command);
53 }
54 postponedCommands.clear();
55}
56
57} // namespace openmsx
CliListener * addListener(std::unique_ptr< CliListener > listener)
std::unique_ptr< CliListener > removeListener(CliListener &listener)
void log(CliComm::LogLevel level, std::string_view message, float fraction) noexcept override
void update(CliComm::UpdateType type, std::string_view machine, std::string_view name, std::string_view value) noexcept override
TclCallbackMessages(GlobalCliComm &cliComm, CommandController &controller)
This file implemented 3 utility functions:
Definition Autofire.cc:11
std::string toString(const BooleanInput &input)
TemporaryString tmpStrCat(Ts &&... ts)
Definition strCat.hh:742