SNode.C
Loading...
Searching...
No Matches
iot::mqtt::server::broker::SubscribtionTree Class Reference

#include <SubscribtionTree.h>

Collaboration diagram for iot::mqtt::server::broker::SubscribtionTree:

Classes

class  TopicLevel
 

Public Member Functions

 SubscribtionTree (iot::mqtt::server::broker::Broker *broker)
 
void appear (const std::string &clientId)
 
bool subscribe (const std::string &topic, const std::string &clientId, uint8_t qoS)
 
void publish (Message &&message)
 
void unsubscribe (const std::string &topic, const std::string &clientId)
 
void unsubscribe (const std::string &clientId)
 
nlohmann::json toJson () const
 
void fromJson (const nlohmann::json &json)
 
void clear ()
 

Private Attributes

TopicLevel head
 

Detailed Description

Definition at line 39 of file SubscribtionTree.h.

Constructor & Destructor Documentation

◆ SubscribtionTree()

iot::mqtt::server::broker::SubscribtionTree::SubscribtionTree ( iot::mqtt::server::broker::Broker * broker)
explicit

Definition at line 40 of file SubscribtionTree.cpp.

41 : head(broker, "") {
42 }

Member Function Documentation

◆ appear()

void iot::mqtt::server::broker::SubscribtionTree::appear ( const std::string & clientId)

Definition at line 44 of file SubscribtionTree.cpp.

44 {
45 head.appear(clientId, "");
46 }
void appear(const std::string &clientId, const std::string &topic)

◆ clear()

void iot::mqtt::server::broker::SubscribtionTree::clear ( )

◆ fromJson()

void iot::mqtt::server::broker::SubscribtionTree::fromJson ( const nlohmann::json & json)

Definition at line 261 of file SubscribtionTree.cpp.

261 {
262 if (!json.empty()) {
263 head.fromJson(json);
264 }
265 }
TopicLevel & fromJson(const nlohmann::json &json)

◆ publish()

void iot::mqtt::server::broker::SubscribtionTree::publish ( Message && message)

Definition at line 63 of file SubscribtionTree.cpp.

63 {
64 auto hashCount = std::ranges::count(message.getTopic(), '#');
65 if (!message.getTopic().empty() && (hashCount == 0 || (hashCount == 1 && message.getTopic().ends_with('#')))) {
66 head.publish(message, message.getTopic());
67 } else {
68 LOG(ERROR) << "MQTT Broker: Publish: Wrong '#' placement: " << message.getTopic();
69 }
70 }
void publish(Message &message, std::string topic)

◆ subscribe()

bool iot::mqtt::server::broker::SubscribtionTree::subscribe ( const std::string & topic,
const std::string & clientId,
uint8_t qoS )

Definition at line 48 of file SubscribtionTree.cpp.

48 {
49 bool success = false;
50
51 auto hashCount = std::ranges::count(topic, '#');
52 if (!topic.empty() && (hashCount == 0 || (hashCount == 1 && topic.ends_with('#')))) {
53 head.subscribe(clientId, qoS, topic);
54
55 success = true;
56 } else {
57 LOG(ERROR) << "MQTT Broker: Subscribe: Wrong '#' placement: " << topic;
58 }
59
60 return success;
61 }
bool subscribe(const std::string &clientId, uint8_t qoS, std::string topic)

◆ toJson()

nlohmann::json iot::mqtt::server::broker::SubscribtionTree::toJson ( ) const

Definition at line 271 of file SubscribtionTree.cpp.

271 {
272 return head.toJson();
273 }

◆ unsubscribe() [1/2]

void iot::mqtt::server::broker::SubscribtionTree::unsubscribe ( const std::string & clientId)

Definition at line 81 of file SubscribtionTree.cpp.

81 {
82 head.unsubscribe(clientId);
83 }
bool unsubscribe(const std::string &clientId, std::string topic)

◆ unsubscribe() [2/2]

void iot::mqtt::server::broker::SubscribtionTree::unsubscribe ( const std::string & topic,
const std::string & clientId )

Definition at line 72 of file SubscribtionTree.cpp.

72 {
73 auto hashCount = std::ranges::count(topic, '#');
74 if (!topic.empty() && (hashCount == 0 || (hashCount == 1 && topic.ends_with('#')))) {
75 head.unsubscribe(clientId, topic);
76 } else {
77 LOG(ERROR) << "MQTT Broker: Unsubscribe: Wrong '#' placement: " << topic;
78 }
79 }

Member Data Documentation

◆ head

TopicLevel iot::mqtt::server::broker::SubscribtionTree::head
private

Definition at line 85 of file SubscribtionTree.h.


The documentation for this class was generated from the following files: