22 std::scoped_lock lock(mutex);
23 auto* p = listener.get();
24 listeners.push_back(std::move(listener));
25 if (allowExternalCommands) {
36 std::scoped_lock lock(mutex);
38 [](
const auto& ptr) {
return ptr.get(); });
39 auto result = std::move(*it);
46 assert(!allowExternalCommands);
47 allowExternalCommands =
true;
48 for (
const auto& listener : listeners) {
49 if (
auto* conn =
dynamic_cast<CliConnection*
>(listener.get())) {
67 std::cerr <<
"Recursive cliComm message: " << message <<
'\n';
72 std::scoped_lock lock(mutex);
73 if (!listeners.empty()) {
74 for (
const auto& l : listeners) {
75 l->log(level, message, fraction);
81 std::cerr <<
"... " << int(100.0f * fraction) <<
'%';
89 updateHelper(type, {}, name, value);
94 if (
auto [it, inserted] = prevValues[type].try_emplace(name, value);
96 if (it->second == value) {
102 updateHelper(type, {}, name, value);
105void GlobalCliComm::updateHelper(UpdateType type, std::string_view machine,
106 std::string_view name, std::string_view value)
109 std::scoped_lock lock(mutex);
110 for (
const auto& l : listeners) {
111 l->update(type, machine, name, value);
Assign new value to some variable and restore the original value when this object goes out of scope.
CliListener * addListener(std::unique_ptr< CliListener > listener)
void log(LogLevel level, std::string_view message, float fraction) override
Log a message with a certain priority level.
void update(UpdateType type, std::string_view name, std::string_view value) override
std::unique_ptr< CliListener > removeListener(CliListener &listener)
void setAllowExternalCommands()
void updateFiltered(UpdateType type, std::string_view name, std::string_view value) override
Same as update(), but checks that the value for type-name is the same as in the previous call.
bool isMainThread()
Returns true when called from the main thread.
This file implemented 3 utility functions:
void move_pop_back(VECTOR &v, typename VECTOR::iterator it)
Erase the pointed to element from the given vector.
auto rfind_unguarded(RANGE &range, const VAL &val, Proj proj={})
Similar to the find(_if)_unguarded functions above, but searches from the back to front.