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 "default_message_callback",
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) noexcept
26{
27 auto levelStr = CliComm::getLevelStrings();
28 try {
29 messageCallback.execute(message, levelStr[level]);
30 } catch (TclObject& command) {
31 // Command for this message could not be executed yet.
32 // Buffer until we can redo them.
33 postponedCommands.push_back(command);
34 }
35}
36
38 CliComm::UpdateType /*type*/, std::string_view /*machine*/,
39 std::string_view /*name*/, std::string_view /*value*/) noexcept
40{
41 // ignore
42}
43
45{
46 for (auto& command: postponedCommands) {
47 messageCallback.executeCommon(command);
48 }
49 postponedCommands.clear();
50}
51
52} // namespace openmsx
static std::span< const std::string_view, NUM_LEVELS > getLevelStrings()
Definition: CliComm.hh:88
void addListener(std::unique_ptr< CliListener > listener)
std::unique_ptr< CliListener > removeListener(CliListener &listener)
void update(CliComm::UpdateType type, std::string_view machine, std::string_view name, std::string_view value) noexcept override
void log(CliComm::LogLevel level, std::string_view message) noexcept override
TclCallbackMessages(GlobalCliComm &cliComm, CommandController &controller)
This file implemented 3 utility functions:
Definition: Autofire.cc:9