Skip to content

Commit

Permalink
add queue size
Browse files Browse the repository at this point in the history
  • Loading branch information
bertmelis committed Aug 31, 2023
1 parent 8b49865 commit 2ab5ca4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/MqttClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ const char* MqttClient::getClientId() const {
return _clientId;
}

size_t MqttClient::queueSize() const {
size_t ret = 0;
EMC_SEMAPHORE_TAKE();
ret = _outbox.size();
EMC_SEMAPHORE_GIVE();
return ret;
}

void MqttClient::loop() {
switch (_state) {
case State::disconnected:
Expand Down
1 change: 1 addition & 0 deletions src/MqttClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class MqttClient {
uint16_t publish(const char* topic, uint8_t qos, bool retain, espMqttClientTypes::PayloadCallback callback, size_t length);
void clearQueue(bool deleteSessionData = false); // Not MQTT compliant and may cause unpredictable results when `deleteSessionData` = true!
const char* getClientId() const;
size_t queueSize() const;
void loop();

protected:
Expand Down
10 changes: 10 additions & 0 deletions src/Outbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ class Outbox {
return false;
}

size_t size() const {
Node* n = _first;
size_t count = 0;
while (n) {
n = n->next;
++count;
}
return count;
}

private:
Node* _first;
Node* _last;
Expand Down

0 comments on commit 2ab5ca4

Please sign in to comment.