SNode.C
Loading...
Searching...
No Matches
RetainTree.h
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef IOT_MQTT_SERVER_BROKER_TOPICTREE_H
21#define IOT_MQTT_SERVER_BROKER_TOPICTREE_H
22
23#include "iot/mqtt/server/broker/Message.h"
24
25namespace iot::mqtt::server::broker {
26 class Broker;
27} // namespace iot::mqtt::server::broker
28
29#ifndef DOXYGEN_SHOULD_SKIP_THIS
30
31#include <cstdint>
32#include <map>
33#include <nlohmann/json_fwd.hpp>
34#include <string>
35
36#endif // DOXYGEN_SHOULD_SKIP_THIS
37
38namespace iot::mqtt::server::broker {
39
40 class RetainTree {
41 public:
42 explicit RetainTree(iot::mqtt::server::broker::Broker* broker);
43
44 void retain(Message&& message);
45 void appear(const std::string& clientId, const std::string& topic, uint8_t qoS);
46
47 nlohmann::json toJson() const;
48 void fromJson(const nlohmann::json& json);
49
50 void clear();
51
52 private:
53 class TopicLevel {
54 public:
55 explicit TopicLevel(iot::mqtt::server::broker::Broker* broker);
56
57 void retain(const Message& message, std::string topic);
58 bool release(std::string topic);
59
60 void appear(const std::string& clientId, std::string topic, uint8_t qoS);
61
62 TopicLevel& fromJson(const nlohmann::json& json);
63 nlohmann::json toJson() const;
64
65 void clear();
66
67 private:
68 void appear(const std::string& clientId, uint8_t clientQoS);
69
71
73
74 iot::mqtt::server::broker::Broker* broker = nullptr;
75 };
76
78 };
79
80} // namespace iot::mqtt::server::broker
81
82#endif // APPS_MQTT_SERVER_TOPICTREE_H
#define SUBSCRIBTION_MAX_QOS
Definition Broker.h:40
virtual core::socket::stream::SocketContext * create(core::socket::stream::SocketConnection *socketConnection, std::shared_ptr< iot::mqtt::server::broker::Broker > broker)=0
core::socket::stream::SocketContext * create(core::socket::stream::SocketConnection *socketConnection) final
void restartSession(const std::string &clientId)
Definition Broker.cpp:187
uint8_t subscribe(const std::string &clientId, const std::string &topic, uint8_t qoS)
Definition Broker.cpp:142
bool hasActiveSession(const std::string &clientId)
Definition Broker.cpp:165
static std::shared_ptr< Broker > instance(uint8_t maxQoS)
Definition Broker.cpp:119
bool isActiveSession(const std::string &clientId, const Mqtt *mqtt)
Definition Broker.cpp:173
iot::mqtt::server::broker::RetainTree retainTree
Definition Broker.h:81
void publish(const std::string &originClientId, const std::string &topic, const std::string &message, uint8_t qoS, bool retain)
Definition Broker.cpp:134
bool hasSession(const std::string &clientId)
Definition Broker.cpp:161
void appear(const std::string &clientId, const std::string &topic, uint8_t qoS)
Definition Broker.cpp:125
void unsubscribe(const std::string &clientId, const std::string &topic)
Definition Broker.cpp:157
Session * renewSession(const std::string &clientId, iot::mqtt::server::Mqtt *mqtt)
Definition Broker.cpp:183
void deleteSession(const std::string &clientId)
Definition Broker.cpp:199
void unsubscribe(const std::string &clientId)
Definition Broker.cpp:129
bool hasRetainedSession(const std::string &clientId)
Definition Broker.cpp:169
iot::mqtt::server::broker::SubscribtionTree subscribtionTree
Definition Broker.h:80
Session * newSession(const std::string &clientId, iot::mqtt::server::Mqtt *mqtt)
Definition Broker.cpp:177
void sendPublish(const std::string &clientId, Message &message, uint8_t qoS, bool retain)
Definition Broker.cpp:204
void retainSession(const std::string &clientId)
Definition Broker.cpp:195
void retain(const Message &message, std::string topic)
void appear(const std::string &clientId, uint8_t clientQoS)
TopicLevel(iot::mqtt::server::broker::Broker *broker)
TopicLevel & fromJson(const nlohmann::json &json)
void appear(const std::string &clientId, std::string topic, uint8_t qoS)
void appear(const std::string &clientId, const std::string &topic, uint8_t qoS)
void fromJson(const nlohmann::json &json)
RetainTree(iot::mqtt::server::broker::Broker *broker)