Add nonStrict subscribe/unsubscribe
This commit is contained in:
+9
-4
@@ -278,7 +278,7 @@ public:
|
|||||||
return emptyVector;
|
return emptyVector;
|
||||||
}
|
}
|
||||||
|
|
||||||
void subscribe(std::string_view topic, Subscriber *subscriber) {
|
void subscribe(std::string_view topic, Subscriber *subscriber, bool nonStrict = false) {
|
||||||
/* Start iterating from the root */
|
/* Start iterating from the root */
|
||||||
Topic *iterator = root;
|
Topic *iterator = root;
|
||||||
|
|
||||||
@@ -322,7 +322,9 @@ public:
|
|||||||
|
|
||||||
/* If this topic is triggered, drain the tree before we join */
|
/* If this topic is triggered, drain the tree before we join */
|
||||||
if (iterator->triggered) {
|
if (iterator->triggered) {
|
||||||
drain();
|
if (!nonStrict) {
|
||||||
|
drain();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add socket to Topic's Set */
|
/* Add socket to Topic's Set */
|
||||||
@@ -346,7 +348,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Returns whether we were subscribed prior */
|
/* Returns whether we were subscribed prior */
|
||||||
bool unsubscribe(std::string_view topic, Subscriber *subscriber) {
|
bool unsubscribe(std::string_view topic, Subscriber *subscriber, bool nonStrict = false) {
|
||||||
/* Subscribers are likely to have very few subscriptions (20 or fewer) */
|
/* Subscribers are likely to have very few subscriptions (20 or fewer) */
|
||||||
if (subscriber) {
|
if (subscriber) {
|
||||||
/* Lookup exact Topic ptr from string */
|
/* Lookup exact Topic ptr from string */
|
||||||
@@ -369,7 +371,9 @@ public:
|
|||||||
if (*it == iterator) {
|
if (*it == iterator) {
|
||||||
/* If this topic is triggered, drain the tree before we leave */
|
/* If this topic is triggered, drain the tree before we leave */
|
||||||
if (iterator->triggered) {
|
if (iterator->triggered) {
|
||||||
drain();
|
if (!nonStrict) {
|
||||||
|
drain();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove topic ptr from our list */
|
/* Remove topic ptr from our list */
|
||||||
@@ -394,6 +398,7 @@ public:
|
|||||||
|
|
||||||
/* If this topic is triggered, drain the tree before we leave */
|
/* If this topic is triggered, drain the tree before we leave */
|
||||||
if (mayFlush && topic->triggered) {
|
if (mayFlush && topic->triggered) {
|
||||||
|
/* Never mind nonStrict here (yet?) */
|
||||||
drain();
|
drain();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -191,7 +191,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Subscribe to a topic according to MQTT rules and syntax */
|
/* Subscribe to a topic according to MQTT rules and syntax */
|
||||||
void subscribe(std::string_view topic) {
|
void subscribe(std::string_view topic, bool nonStrict = false) {
|
||||||
WebSocketContextData<SSL> *webSocketContextData = (WebSocketContextData<SSL> *) us_socket_context_ext(SSL,
|
WebSocketContextData<SSL> *webSocketContextData = (WebSocketContextData<SSL> *) us_socket_context_ext(SSL,
|
||||||
(us_socket_context_t *) us_socket_context(SSL, (us_socket_t *) this)
|
(us_socket_context_t *) us_socket_context(SSL, (us_socket_t *) this)
|
||||||
);
|
);
|
||||||
@@ -202,18 +202,18 @@ public:
|
|||||||
webSocketData->subscriber = new Subscriber(this);
|
webSocketData->subscriber = new Subscriber(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
webSocketContextData->topicTree.subscribe(topic, webSocketData->subscriber);
|
webSocketContextData->topicTree.subscribe(topic, webSocketData->subscriber, nonStrict);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unsubscribe from a topic, returns true if we were subscribed */
|
/* Unsubscribe from a topic, returns true if we were subscribed */
|
||||||
bool unsubscribe(std::string_view topic) {
|
bool unsubscribe(std::string_view topic, bool nonStrict = false) {
|
||||||
WebSocketContextData<SSL> *webSocketContextData = (WebSocketContextData<SSL> *) us_socket_context_ext(SSL,
|
WebSocketContextData<SSL> *webSocketContextData = (WebSocketContextData<SSL> *) us_socket_context_ext(SSL,
|
||||||
(us_socket_context_t *) us_socket_context(SSL, (us_socket_t *) this)
|
(us_socket_context_t *) us_socket_context(SSL, (us_socket_t *) this)
|
||||||
);
|
);
|
||||||
|
|
||||||
WebSocketData *webSocketData = (WebSocketData *) us_socket_ext(SSL, (us_socket_t *) this);
|
WebSocketData *webSocketData = (WebSocketData *) us_socket_ext(SSL, (us_socket_t *) this);
|
||||||
|
|
||||||
return webSocketContextData->topicTree.unsubscribe(topic, webSocketData->subscriber);
|
return webSocketContextData->topicTree.unsubscribe(topic, webSocketData->subscriber, nonStrict);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unsubscribe from all topics you might be subscribed to */
|
/* Unsubscribe from all topics you might be subscribed to */
|
||||||
|
|||||||
Reference in New Issue
Block a user