22 std::lock_guard<std::mutex> lock(mutex);
23 auto* p = listener.get();
24 listeners.push_back(std::move(listener));
25 if (allowExternalCommands) {
35 std::lock_guard<std::mutex> lock(mutex);
37 [](
const auto& ptr) {
return ptr.get(); });
38 auto result = std::move(*it);
45 assert(!allowExternalCommands);
46 allowExternalCommands =
true;
47 for (
auto& listener : listeners) {
48 if (
auto* conn =
dynamic_cast<CliConnection*
>(listener.get())) {
66 std::cerr <<
"Recursive cliComm message: " << message <<
'\n';
71 std::lock_guard<std::mutex> lock(mutex);
72 if (!listeners.empty()) {
73 for (
auto& l : listeners) {
74 l->log(level, message);
78 std::cerr << message <<
'\n';
85 updateHelper(type, {}, name, value);
91 if (
auto [it, inserted] = prevValues[type].try_emplace(name, value);
93 if (it->second == value) {
99 updateHelper(type, {}, name, value);
102void GlobalCliComm::updateHelper(UpdateType type, std::string_view machine,
103 std::string_view name, std::string_view value)
106 std::lock_guard<std::mutex> lock(mutex);
107 for (
auto& l : listeners) {
108 l->update(type, machine, name, value);
Assign new value to some variable and restore the original value when this object goes out of scope.
void addListener(std::unique_ptr< CliListener > listener)
void log(LogLevel level, std::string_view message) override
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.