| e8555c89 Andy McCall |
1 |
#include "TclCallbackMessages.hh" |
| 2 |
|
| 3 |
#include "GlobalCliComm.hh" |
| 4 |
|
| 5 |
namespace openmsx { |
| 6 |
|
| 7 |
TclCallbackMessages::TclCallbackMessages(GlobalCliComm& cliComm_, |
| 8 |
CommandController& controller) |
| 9 |
: cliComm(cliComm_) |
| 10 |
, messageCallback( |
| 11 |
controller, "message_callback", |
| 12 |
"Tcl proc called when a new message is available", |
| 13 |
"", |
| 14 |
Setting::Save::YES, |
| 15 |
true) |
| 16 |
{ |
| 17 |
cliComm.addListener(std::unique_ptr<CliListener>(this)); |
| 18 |
} |
| 19 |
|
| 20 |
TclCallbackMessages::~TclCallbackMessages() |
| 21 |
{ |
| 22 |
std::unique_ptr<CliListener> ptr = cliComm.removeListener(*this); |
| 23 |
(void)ptr.release(); |
| 24 |
} |
| 25 |
|
| 26 |
void TclCallbackMessages::log(CliComm::LogLevel level, std::string_view message, float fraction) noexcept |
| 27 |
{ |
| 28 |
|
| 29 |
try { |
| 30 |
if (level == CliComm::LogLevel::PROGRESS && fraction >= 0.0f) { |
| 31 |
messageCallback.execute(tmpStrCat(message, "... ", int(100.0f * fraction), '%'), |
| 32 |
toString(level)); |
| 33 |
} else { |
| 34 |
messageCallback.execute(message, toString(level)); |
| 35 |
} |
| 36 |
} catch (TclObject& command) { |
| 37 |
|
| 38 |
|
| 39 |
postponedCommands.push_back(command); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
void TclCallbackMessages::update( |
| 44 |
CliComm::UpdateType , std::string_view , |
| 45 |
std::string_view , std::string_view ) noexcept |
| 46 |
{ |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
void TclCallbackMessages::redoPostponedCallbacks() |
| 51 |
{ |
| 52 |
for (auto& command: postponedCommands) { |
| 53 |
messageCallback.executeCommon(command); |
| 54 |
} |
| 55 |
postponedCommands.clear(); |
| 56 |
} |
| 57 |
|
| 58 |
} |