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)
 
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 SubscribtionTree.h.

Constructor & Destructor Documentation

◆ SubscribtionTree()

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

Definition at line 61 of file SubscribtionTree.cpp.

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

References head, and iot::mqtt::server::broker::SubscribtionTree::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::SubscribtionTree::appear ( const std::string &  clientId)

Definition at line 65 of file SubscribtionTree.cpp.

65 {
66 head.appear(clientId, "");
67 }
void appear(const std::string &clientId, const std::string &topic)

References iot::mqtt::server::broker::SubscribtionTree::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::SubscribtionTree::clear ( )

Definition at line 126 of file SubscribtionTree.cpp.

References iot::mqtt::server::broker::SubscribtionTree::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::SubscribtionTree::fromJson ( const nlohmann::json &  json)

Definition at line 116 of file SubscribtionTree.cpp.

116 {
117 if (!json.empty()) {
118 head.fromJson(json);
119 }
120 }
TopicLevel & fromJson(const nlohmann::json &json)

References iot::mqtt::server::broker::SubscribtionTree::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::SubscribtionTree::getSubscriptions ( const std::string &  clientId) const

Definition at line 106 of file SubscribtionTree.cpp.

106 {
107 std::list<std::string> subscriptions = head.getSubscriptions(clientId);
108
109 return subscriptions;
110 }
std::list< std::string > getSubscriptions(const std::string &clientId) const

References iot::mqtt::server::broker::SubscribtionTree::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::SubscribtionTree::getSubscriptionTree ( ) const

Definition at line 112 of file SubscribtionTree.cpp.

112 {
113 return head.getSubscriptionTree();
114 }
std::map< std::string, std::list< std::pair< std::string, uint8_t > > > getSubscriptionTree() const

References iot::mqtt::server::broker::SubscribtionTree::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::SubscribtionTree::publish ( Message &&  message)

Definition at line 84 of file SubscribtionTree.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 }
void publish(Message &message, std::string topic)

References iot::mqtt::server::broker::Message::getTopic(), head, and iot::mqtt::server::broker::SubscribtionTree::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::SubscribtionTree::subscribe ( const std::string &  topic,
const std::string &  clientId,
uint8_t  qoS 
)

Definition at line 69 of file SubscribtionTree.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 }
bool subscribe(const std::string &clientId, uint8_t qoS, std::string topic)

References head, and iot::mqtt::server::broker::SubscribtionTree::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::SubscribtionTree::toJson ( ) const

Definition at line 122 of file SubscribtionTree.cpp.

122 {
123 return head.toJson();
124 }

References head, and iot::mqtt::server::broker::SubscribtionTree::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::SubscribtionTree::unsubscribe ( const std::string &  clientId)

Definition at line 102 of file SubscribtionTree.cpp.

102 {
103 head.unsubscribe(clientId);
104 }
bool unsubscribe(const std::string &clientId, std::string topic)

References head, and iot::mqtt::server::broker::SubscribtionTree::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::SubscribtionTree::unsubscribe ( const std::string &  topic,
const std::string &  clientId 
)

Definition at line 93 of file SubscribtionTree.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::SubscribtionTree::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::SubscribtionTree::head
private

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