Added db logger functions. Chnaged to newest mqtt++ version.

This commit is contained in:
2020-11-17 10:08:34 +01:00
parent 0fff81be48
commit 2cb0fd1fed
14 changed files with 261 additions and 39 deletions

View File

@@ -1,22 +1,19 @@
#include "Cache.h"
#include <algorithm>
std::vector<TopicState> Cache::topic_states(std::vector<std::string>& topics) {
std::vector<TopicState> states;
for (const auto& topic : topics) {
auto hit = std::find_if(cache.begin(), cache.end(), [&](TopicState& cache_state) {
return cache_state.topic == topic;
});
if (hit != cache.end()) {
states.push_back(*hit);
#include "mqtt++.h"
#include <iostream>
std::optional<std::string> Cache::cached_topic_value(const std::string& topic) {
for (const auto& state : m_cache) {
if (state.topic == topic) {
return state.value;
}
}
return states;
return std::nullopt;
}
TopicState Cache::set_topic_value(const std::string& topic, const std::string& value) {
for (auto& state : cache) {
for (auto& state : m_cache) {
if (state.topic == topic) {
state.value = value;
@@ -24,5 +21,5 @@ TopicState Cache::set_topic_value(const std::string& topic, const std::string& v
}
}
return cache.emplace_back(topic, value);
return m_cache.emplace_back(topic, value);
}