blob: 34aab048d3c241f87fe512ddd9da1ef976ef8843 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/*
* Copyright (C) 2024 Konsulko Group
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "SignalUpdateHandlers.h"
void SignalUpdateHandlers::addSignalUpdateHandler(const std::string &path, std::shared_ptr<SignalUpdateHandler> &handler)
{
auto it = m_handlers.find(path);
if (it == m_handlers.end()) {
std::vector<std::shared_ptr<SignalUpdateHandler>> v;
v.push_back(handler);
m_handlers[path] = v;
} else {
m_handlers[path].push_back(handler);
}
}
std::vector<std::string> SignalUpdateHandlers::getSignals()
{
std::vector<std::string> signals;
for (auto it = m_handlers.begin(); it != m_handlers.end(); ++it) {
signals.push_back(it->first);
}
return signals;
}
void SignalUpdateHandlers::setClient(MqttClient *mqttClient)
{
for (auto it = m_handlers.begin(); it != m_handlers.end(); ++it) {
for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
std::shared_ptr<SignalUpdateHandler> handler = *it2;
if (handler)
handler->setClient(mqttClient);
}
}
}
void SignalUpdateHandlers::processSignalUpdate(const std::string &path, const Datapoint &dp)
{
auto it = m_handlers.find(path);
if (it == m_handlers.end())
return;
for (auto it2 = m_handlers[path].begin();
it2 != m_handlers[path].end();
++it2) {
std::shared_ptr<SignalUpdateHandler> handler = *it2;
if (handler)
handler->handleUpdate(dp);
}
}
|