🐛 Secure sub and unsub with mutex
This commit is contained in:
@@ -55,8 +55,16 @@ class CommAdapterBase {
|
|||||||
void send(const char *data, int cid = -1) { send(reinterpret_cast<const uint8_t *>(data), strlen(data), cid); }
|
void send(const char *data, int cid = -1) { send(reinterpret_cast<const uint8_t *>(data), strlen(data), cid); }
|
||||||
virtual void send(const uint8_t *data, size_t len, int cid = -1) = 0;
|
virtual void send(const uint8_t *data, size_t len, int cid = -1) = 0;
|
||||||
|
|
||||||
void subscribe(const char *event, int cid = 0) { client_subscriptions[event].push_back(cid); }
|
void subscribe(const char *event, int cid = 0) {
|
||||||
void unsubscribe(const char *event, int cid = 0) { client_subscriptions[event].push_back(cid); }
|
xSemaphoreTake(mutex_, portMAX_DELAY);
|
||||||
|
client_subscriptions[event].push_back(cid);
|
||||||
|
xSemaphoreGive(mutex_);
|
||||||
|
}
|
||||||
|
void unsubscribe(const char *event, int cid = 0) {
|
||||||
|
xSemaphoreTake(mutex_, portMAX_DELAY);
|
||||||
|
client_subscriptions[event].remove(cid);
|
||||||
|
xSemaphoreGive(mutex_);
|
||||||
|
}
|
||||||
|
|
||||||
void handleEventCallbacks(std::string event, JsonVariant &jsonObject, int originId) {
|
void handleEventCallbacks(std::string event, JsonVariant &jsonObject, int originId) {
|
||||||
for (auto &callback : event_callbacks[event]) {
|
for (auto &callback : event_callbacks[event]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user