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
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
45namespace mqtt::bridge::lib {
46 class Bridge;
47}
48
49#ifndef DOXYGEN_SHOULD_SKIP_THIS
50
51#include <cstdint>
52#include <iot/mqtt/Topic.h> // IWYU pragma: export
53#include <list>
54#include <nlohmann/json.hpp>
55#include <string>
56
57// IWYU pragma: no_include <nlohmann/json_fwd.hpp>
58
59#endif // DOXYGEN_SHOULD_SKIP_THIS
60
61namespace mqtt::bridge::lib {
62
63 class Broker {
64 public:
65 Broker(Bridge& bridge,
66 const std::string& sessionStoreFileName,
67 const std::string& instanceName,
68 const std::string& protocol,
69 const std::string& encryption,
70 const std::string& transport,
71 const nlohmann::json& address,
72 const std::string& clientId,
73 const uint16_t keepAlive,
74 bool cleanSession,
75 const std::string& willTopic,
76 const std::string& willMessage,
77 const uint8_t willQoS,
78 bool willRetain,
79 const std::string& username,
80 const std::string& password,
81 bool loopPrevention,
82 const std::string& prefix,
83 bool disabled,
84 const std::list<iot::mqtt::Topic>& topics);
85
86 Broker(Broker&&) = default;
87 Broker(const Broker&) = delete;
88
89 Bridge& getBridge() const;
90
91 const std::string& getSessionStoreFileName() const;
92
93 const std::string& getClientId() const;
94 uint16_t getKeepAlive() const;
95 bool getCleanSession() const;
96 const std::string& getWillTopic() const;
97 const std::string& getWillMessage() const;
98 uint8_t getWillQoS() const;
99 bool getWillRetain() const;
100 const std::string& getUsername() const;
101 const std::string& getPassword() const;
102 bool getLoopPrevention() const;
103
104 const std::string& getName() const;
105 const std::string& getProtocol() const;
106 const std::string& getEncryption() const;
107 const std::string& getTransport() const;
108
109 const std::string& getPrefix() const;
110
111 bool getDisabled() const;
112
113 const std::list<iot::mqtt::Topic>& getTopics() const;
114 const nlohmann::json& getAddress() const;
115
116 private:
119
120 std::string instanceName;
121 std::string protocol;
122 std::string encryption;
123 std::string transport;
125
126 std::string clientId;
127 uint16_t keepAlive;
129 std::string willTopic;
130 std::string willMessage;
131 uint8_t willQoS;
133 std::string username;
134 std::string password;
136
137 std::string prefix;
139
140 std::list<iot::mqtt::Topic> topics;
141 };
142
143} // namespace mqtt::bridge::lib
144
145#endif // MQTT_BRIDGE_LIB_BROKER_H
const std::string & getName()
Definition Bridge.cpp:61
void addMqtt(mqtt::bridge::lib::Mqtt *mqtt)
Definition Bridge.cpp:65
const std::list< const mqtt::bridge::lib::Mqtt * > & getMqttList() const
Definition Bridge.cpp:95
void publish(const mqtt::bridge::lib::Mqtt *originMqtt, const iot::mqtt::packets::Publish &publish)
Definition Bridge.cpp:73
bool getDisabled() const
Definition Bridge.cpp:91
std::list< const mqtt::bridge::lib::Mqtt * > mqttList
Definition Bridge.h:86
Bridge(const std::string &name, const std::string &prefix, bool disabled)
Definition Bridge.cpp:55
void removeMqtt(mqtt::bridge::lib::Mqtt *mqtt)
Definition Bridge.cpp:69
const std::string & getPrefix() const
Definition Bridge.cpp:87
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:140
uint16_t getKeepAlive() const
Definition Broker.cpp:106
std::string willMessage
Definition Broker.h:130
nlohmann::json address
Definition Broker.h:124
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:120
const std::string & getProtocol() const
Definition Broker.cpp:146
Broker(Broker &&)=default
std::string sessionStoreFileName
Definition Broker.h:118
const std::string & getTransport() const
Definition Broker.cpp:154
std::string transport
Definition Broker.h:123
std::string willTopic
Definition Broker.h:129
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:122
const Broker & getBroker() const
Definition Mqtt.cpp:78