MQTTSuite
Loading...
Searching...
No Matches
Broker.h
Go to the documentation of this file.
1/*
2 * MQTTSuite - A lightweight MQTT Integration System
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2022, 2023, 2024, 2025, 2026
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20/*
21 * MIT License
22 *
23 * Permission is hereby granted, free of charge, to any person obtaining a copy
24 * of this software and associated documentation files (the "Software"), to deal
25 * in the Software without restriction, including without limitation the rights
26 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27 * copies of the Software, and to permit persons to whom the Software is
28 * furnished to do so, subject to the following conditions:
29 *
30 * The above copyright notice and this permission notice shall be included in
31 * all copies or substantial portions of the Software.
32 *
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39 * THE SOFTWARE.
40 */
41
42#ifndef MQTT_BRIDGE_LIB_BROKER_H
43#define MQTT_BRIDGE_LIB_BROKER_H
44
45#include <iot/mqtt/Topic.h> // IWYU pragma: export
46
47namespace mqtt::bridge::lib {
48 class Bridge;
49}
50
51#ifndef DOXYGEN_SHOULD_SKIP_THIS
52
53#include <cstdint>
54#include <list>
55#include <nlohmann/json.hpp>
56#include <string>
57
58// IWYU pragma: no_include <nlohmann/json_fwd.hpp>
59
60#endif // DOXYGEN_SHOULD_SKIP_THIS
61
62namespace mqtt::bridge::lib {
63
64 class Broker {
65 public:
66 Broker(Bridge& bridge,
67 const std::string& sessionStoreFileName,
68 const std::string& instanceName,
69 const std::string& protocol,
70 const std::string& encryption,
71 const std::string& transport,
72 const nlohmann::json& address,
73 const std::string& clientId,
74 const uint16_t keepAlive,
75 bool cleanSession,
76 const std::string& willTopic,
77 const std::string& willMessage,
78 const uint8_t willQoS,
79 bool willRetain,
80 const std::string& username,
81 const std::string& password,
82 bool loopPrevention,
83 const std::string& prefix,
84 bool disabled,
85 const std::list<iot::mqtt::Topic>& topics);
86
87 Broker(Broker&&) = default;
88 Broker(const Broker&) = delete;
89
90 Bridge& getBridge() const;
91
92 const std::string& getSessionStoreFileName() const;
93
94 const std::string& getClientId() const;
95 uint16_t getKeepAlive() const;
96 bool getCleanSession() const;
97 const std::string& getWillTopic() const;
98 const std::string& getWillMessage() const;
99 uint8_t getWillQoS() const;
100 bool getWillRetain() const;
101 const std::string& getUsername() const;
102 const std::string& getPassword() const;
103 bool getLoopPrevention() const;
104
105 const std::string& getName() const;
106 const std::string& getProtocol() const;
107 const std::string& getEncryption() const;
108 const std::string& getTransport() const;
109
110 const std::string& getPrefix() const;
111
112 bool getDisabled() const;
113
114 const std::list<iot::mqtt::Topic>& getTopics() const;
115 const nlohmann::json& getAddress() const;
116
117 private:
120
121 std::string instanceName;
122 std::string protocol;
123 std::string encryption;
124 std::string transport;
126
127 std::string clientId;
128 uint16_t keepAlive;
130 std::string willTopic;
131 std::string willMessage;
132 uint8_t willQoS;
134 std::string username;
135 std::string password;
137
138 std::string prefix;
140
141 std::list<iot::mqtt::Topic> topics;
142 };
143
144} // namespace mqtt::bridge::lib
145
146#endif // MQTT_BRIDGE_LIB_BROKER_H
Broker * getBroker(const std::string &fullInstanceName)
Definition Bridge.cpp:77
void addMqtt(mqtt::bridge::lib::Mqtt *mqtt)
Definition Bridge.cpp:85
const std::string & getName() const
Definition Bridge.cpp:67
const std::list< const mqtt::bridge::lib::Mqtt * > & getMqttList() const
Definition Bridge.cpp:137
const std::map< const std::string, Broker > & getBrokerMap() const
Definition Bridge.cpp:81
void publish(const mqtt::bridge::lib::Mqtt *originMqtt, const iot::mqtt::packets::Publish &publish)
Definition Bridge.cpp:107
bool getDisabled() const
Definition Bridge.cpp:125
bool operator<(const Bridge &rhs) const
Definition Bridge.cpp:133
void addBroker(const std::string &fullInstanceName, Broker &&broker)
Definition Bridge.cpp:71
std::size_t enabledBroker
Definition Bridge.h:101
std::list< const mqtt::bridge::lib::Mqtt * > mqttList
Definition Bridge.h:104
bool getAllConnected1() const
Definition Bridge.cpp:129
Bridge(const std::string &name, const std::string &prefix, bool disabled)
Definition Bridge.cpp:61
std::map< const std::string, Broker > brokerMap
Definition Bridge.h:103
void removeMqtt(mqtt::bridge::lib::Mqtt *mqtt)
Definition Bridge.cpp:96
const std::string & getPrefix() const
Definition Bridge.cpp:121
const std::string & getName() const
Definition Broker.cpp:142
bool getLoopPrevention() const
Definition Broker.cpp:138
Broker(const Broker &)=delete
const nlohmann::json & getAddress() const
Definition Broker.cpp:170
bool getDisabled() const
Definition Broker.cpp:162
const std::string & getWillTopic() const
Definition Broker.cpp:114
bool getWillRetain() const
Definition Broker.cpp:126
const std::list< iot::mqtt::Topic > & getTopics() const
Definition Broker.cpp:166
std::list< iot::mqtt::Topic > topics
Definition Broker.h:141
uint16_t getKeepAlive() const
Definition Broker.cpp:106
std::string willMessage
Definition Broker.h:131
nlohmann::json address
Definition Broker.h:125
const std::string & getWillMessage() const
Definition Broker.cpp:118
const std::string & getSessionStoreFileName() const
Definition Broker.cpp:98
const std::string & getClientId() const
Definition Broker.cpp:102
const std::string & getEncryption() const
Definition Broker.cpp:150
const std::string & getUsername() const
Definition Broker.cpp:130
bool getCleanSession() const
Definition Broker.cpp:110
Broker(Bridge &bridge, const std::string &sessionStoreFileName, const std::string &instanceName, const std::string &protocol, const std::string &encryption, const std::string &transport, const nlohmann::json &address, const std::string &clientId, const uint16_t keepAlive, bool cleanSession, const std::string &willTopic, const std::string &willMessage, const uint8_t willQoS, bool willRetain, const std::string &username, const std::string &password, bool loopPrevention, const std::string &prefix, bool disabled, const std::list< iot::mqtt::Topic > &topics)
Definition Broker.cpp:52
const std::string & getPassword() const
Definition Broker.cpp:134
std::string instanceName
Definition Broker.h:121
const std::string & getProtocol() const
Definition Broker.cpp:146
Broker(Broker &&)=default
std::string sessionStoreFileName
Definition Broker.h:119
const std::string & getTransport() const
Definition Broker.cpp:154
std::string transport
Definition Broker.h:124
std::string willTopic
Definition Broker.h:130
Bridge & getBridge() const
Definition Broker.cpp:94
const std::string & getPrefix() const
Definition Broker.cpp:158
uint8_t getWillQoS() const
Definition Broker.cpp:122
std::string encryption
Definition Broker.h:123
const Broker & getBroker() const
Definition Mqtt.cpp:78
void bridgeStopped(const std::string &bridgeName)
void brokerConnected(const std::string &bridgeName, const std::string &instanceName)
void bridgeStarted(const std::string &bridgeName)
static SSEDistributor & instance()
void brokerDisconnected(const std::string &bridgeName, const std::string &instanceName)