openMSX
TclCallbackMessages.cc
Go to the documentation of this file.
1 #include "TclCallbackMessages.hh"
2 #include "GlobalCliComm.hh"
3 
4 namespace 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  false, // don't print callback err on cliComm (would cause infinite loop)
13  false) // don't save setting
14 {
15  cliComm.addListener(std::unique_ptr<CliListener>(this)); // wrap in unique_ptr
16 }
17 
19 {
20  std::unique_ptr<CliListener> ptr = cliComm.removeListener(*this);
21  ptr.release();
22 }
23 
24 void TclCallbackMessages::log(CliComm::LogLevel level, std::string_view message)
25 {
26  auto levelStr = CliComm::getLevelStrings();
27  messageCallback.execute(message, levelStr[level]);
28 }
29 
31  CliComm::UpdateType /*type*/, std::string_view /*machine*/,
32  std::string_view /*name*/, std::string_view /*value*/)
33 {
34  // ignore
35 }
36 
37 } // namespace openmsx
openmsx::CliComm::getLevelStrings
static span< const char *const > getLevelStrings()
Definition: CliComm.hh:78
openmsx::CommandController
Definition: CommandController.hh:18
openmsx::TclCallbackMessages::update
void update(CliComm::UpdateType type, std::string_view machine, std::string_view name, std::string_view value) override
Definition: TclCallbackMessages.cc:30
openmsx::CliComm::UpdateType
UpdateType
Definition: CliComm.hh:20
GlobalCliComm.hh
openmsx::TclCallbackMessages::~TclCallbackMessages
~TclCallbackMessages() override
Definition: TclCallbackMessages.cc:18
openmsx::CliComm::LogLevel
LogLevel
Definition: CliComm.hh:13
openmsx::GlobalCliComm
Definition: GlobalCliComm.hh:16
openmsx::TclCallback::execute
TclObject execute()
Definition: TclCallback.cc:40
openmsx::GlobalCliComm::removeListener
std::unique_ptr< CliListener > removeListener(CliListener &listener)
Definition: GlobalCliComm.cc:32
TclCallbackMessages.hh
openmsx::TclCallbackMessages::log
void log(CliComm::LogLevel level, std::string_view message) override
Definition: TclCallbackMessages.cc:24
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::GlobalCliComm::addListener
void addListener(std::unique_ptr< CliListener > listener)
Definition: GlobalCliComm.cc:19
openmsx::TclCallbackMessages::TclCallbackMessages
TclCallbackMessages(GlobalCliComm &cliComm, CommandController &controller)
Definition: TclCallbackMessages.cc:6