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

#include <SubscriptionTree.h>

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

Classes

class  TopicLevel

Public Member Functions

 SubscriptionTree (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)
std::list< std::string > getSubscriptions (const std::string &clientId) const
std::map< std::string, std::list< std::pair< std::string, uint8_t > > > getSubscriptionTree () const
void clear ()

Private Attributes

TopicLevel head

Detailed Description

Definition at line 65 of file SubscriptionTree.h.

Constructor & Destructor Documentation

◆ SubscriptionTree()

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

Definition at line 61 of file SubscriptionTree.cpp.

62 : head(broker, "") {
63 }

References head, and iot::mqtt::server::broker::SubscriptionTree::TopicLevel::TopicLevel().

Referenced by iot::mqtt::server::broker::Broker::Broker().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ appear()

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

Definition at line 65 of file SubscriptionTree.cpp.

65 {
66 head.appear(clientId, "");
67 }

References iot::mqtt::server::broker::SubscriptionTree::TopicLevel::appear(), and head.

Referenced by iot::mqtt::server::broker::Broker::restartSession().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

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

Definition at line 124 of file SubscriptionTree.cpp.

124 {
125 head.clear();
126 }

References iot::mqtt::server::broker::SubscriptionTree::TopicLevel::clear(), and head.

Referenced by iot::mqtt::server::broker::Broker::Broker().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromJson()

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

Definition at line 114 of file SubscriptionTree.cpp.

114 {
115 if (!json.empty()) {
116 head.fromJson(json);
117 }
118 }

References iot::mqtt::server::broker::SubscriptionTree::TopicLevel::fromJson(), and head.

Referenced by iot::mqtt::server::broker::Broker::Broker().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSubscriptions()

std::list< std::string > iot::mqtt::server::broker::SubscriptionTree::getSubscriptions ( const std::string & clientId) const

Definition at line 106 of file SubscriptionTree.cpp.

106 {
107 return head.getSubscriptions(clientId);
108 }

References iot::mqtt::server::broker::SubscriptionTree::TopicLevel::getSubscriptions(), and head.

Referenced by iot::mqtt::server::broker::Broker::getSubscriptions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSubscriptionTree()

std::map< std::string, std::list< std::pair< std::string, uint8_t > > > iot::mqtt::server::broker::SubscriptionTree::getSubscriptionTree ( ) const

Definition at line 110 of file SubscriptionTree.cpp.

110 {
111 return head.getSubscriptionTree();
112 }

References iot::mqtt::server::broker::SubscriptionTree::TopicLevel::getSubscriptionTree(), and head.

Referenced by iot::mqtt::server::broker::Broker::getSubscriptionTree().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ publish()

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

Definition at line 84 of file SubscriptionTree.cpp.

84 {
85 auto hashCount = std::ranges::count(message.getTopic(), '#');
86 if (!message.getTopic().empty() && (hashCount == 0 || (hashCount == 1 && message.getTopic().ends_with('#')))) {
87 head.publish(message, message.getTopic());
88 } else {
89 LOG(ERROR) << "MQTT Broker: Publish: Wrong '#' placement: " << message.getTopic();
90 }
91 }

References iot::mqtt::server::broker::Message::getTopic(), head, and iot::mqtt::server::broker::SubscriptionTree::TopicLevel::publish().

Referenced by iot::mqtt::server::broker::Broker::publish().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subscribe()

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

Definition at line 69 of file SubscriptionTree.cpp.

69 {
70 bool success = false;
71
72 auto hashCount = std::ranges::count(topic, '#');
73 if (!topic.empty() && (hashCount == 0 || (hashCount == 1 && topic.ends_with('#')))) {
74 head.subscribe(clientId, qoS, topic);
75
76 success = true;
77 } else {
78 LOG(ERROR) << "MQTT Broker: Subscribe: Wrong '#' placement: " << topic;
79 }
80
81 return success;
82 }

References head, and iot::mqtt::server::broker::SubscriptionTree::TopicLevel::subscribe().

Referenced by iot::mqtt::server::broker::Broker::subscribe().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toJson()

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

Definition at line 120 of file SubscriptionTree.cpp.

120 {
121 return head.toJson();
122 }

References head, and iot::mqtt::server::broker::SubscriptionTree::TopicLevel::toJson().

Referenced by iot::mqtt::server::broker::Broker::~Broker().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unsubscribe() [1/2]

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

Definition at line 102 of file SubscriptionTree.cpp.

102 {
103 head.unsubscribe(clientId);
104 }

References head, and iot::mqtt::server::broker::SubscriptionTree::TopicLevel::unsubscribe().

Referenced by iot::mqtt::server::broker::Broker::deleteSession(), and iot::mqtt::server::broker::Broker::unsubscribe().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unsubscribe() [2/2]

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

Definition at line 93 of file SubscriptionTree.cpp.

93 {
94 auto hashCount = std::ranges::count(topic, '#');
95 if (!topic.empty() && (hashCount == 0 || (hashCount == 1 && topic.ends_with('#')))) {
96 head.unsubscribe(clientId, topic);
97 } else {
98 LOG(ERROR) << "MQTT Broker: Unsubscribe: Wrong '#' placement: " << topic;
99 }
100 }

References head, and iot::mqtt::server::broker::SubscriptionTree::TopicLevel::unsubscribe().

Referenced by iot::mqtt::server::broker::Broker::unsubscribe().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ head

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

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