51
51
#include < algorithm>
52
52
#include < nlohmann/json.hpp>
53
53
#include < string>
54
- #include < utility>
55
54
56
55
// IWYU pragma: no_include <nlohmann/detail/iterators/iteration_proxy.hpp>
57
56
@@ -110,6 +109,10 @@ namespace iot::mqtt::server::broker {
110
109
return subscriptions;
111
110
}
112
111
112
+ std::map<std::string, std::list<std::pair<std::string, uint8_t >>> SubscribtionTree::getSubscriptionTree () const {
113
+ return head.getSubscriptionTree ();
114
+ }
115
+
113
116
void SubscribtionTree::fromJson (const nlohmann::json& json) {
114
117
if (!json.empty ()) {
115
118
head.fromJson (json);
@@ -281,6 +284,10 @@ namespace iot::mqtt::server::broker {
281
284
return getSubscriptions (" " , clientId);
282
285
}
283
286
287
+ std::map<std::string, std::list<std::pair<std::string, uint8_t >>> SubscribtionTree::TopicLevel::getSubscriptionTree () const {
288
+ return getSubscriptionTree (" " );
289
+ }
290
+
284
291
std::list<std::string> SubscribtionTree::TopicLevel::getSubscriptions (const std::string& absoluteTopicLevel,
285
292
const std::string& clientId) const {
286
293
std::list<std::string> topicLevelList;
@@ -298,6 +305,26 @@ namespace iot::mqtt::server::broker {
298
305
return topicLevelList;
299
306
}
300
307
308
+ std::map<std::string, std::list<std::pair<std::string, uint8_t >>>
309
+ SubscribtionTree::TopicLevel::getSubscriptionTree (const std::string& absoluteTopicLevel) const {
310
+ std::map<std::string, std::list<std::pair<std::string, uint8_t >>> topicLevelTree;
311
+
312
+ for (const auto & [topicLevelName, nextTopicLevel] : topicLevels) {
313
+ const std::string composedAbsoluteTopicLevelName = absoluteTopicLevel + topicLevelName;
314
+
315
+ for (const auto & clientId : nextTopicLevel.clientIds ) {
316
+ topicLevelTree[composedAbsoluteTopicLevelName].emplace_back (clientId);
317
+ }
318
+
319
+ std::map<std::string, std::list<std::pair<std::string, uint8_t >>> subSubscriptionTree =
320
+ nextTopicLevel.getSubscriptionTree (composedAbsoluteTopicLevelName + " /" );
321
+
322
+ topicLevelTree.insert (subSubscriptionTree.begin (), subSubscriptionTree.end ());
323
+ }
324
+
325
+ return topicLevelTree;
326
+ }
327
+
301
328
SubscribtionTree::TopicLevel& SubscribtionTree::TopicLevel::fromJson (const nlohmann::json& json) {
302
329
clientIds.clear ();
303
330
topicLevels.clear ();
0 commit comments