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::SaveSetting::SAVE, // 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 auto levelStr = CliComm::getLevelStrings();
29 try {
30 if (level == CliComm::PROGRESS && fraction >= 0.0f) {
31 messageCallback.execute(tmpStrCat(message, "... ", int(100.0f * fraction), '%'),
32 levelStr[level]);
33 } else {
34 messageCallback.execute(message, levelStr[level]);
35 }
36 } catch (TclObject& command) {
37 // Command for this message could not be executed yet.
38 // Buffer until we can redo them.
39 postponedCommands.push_back(command);
40 }
41}
42
44 CliComm::UpdateType /*type*/, std::string_view /*machine*/,
45 std::string_view /*name*/, std::string_view /*value*/) noexcept
46{
47 // ignore
48}
49
51{
52 for (auto& command: postponedCommands) {
53 messageCallback.executeCommon(command);
54 }
55 postponedCommands.clear();
56}
57
58} // namespace openmsx
static std::span< const std::string_view, NUM_LEVELS > getLevelStrings()
Definition CliComm.hh:93
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:9
TemporaryString tmpStrCat(Ts &&... ts)
Definition strCat.hh:742