Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/mqtt/async_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@ class async_client : public virtual iasync_client
* @return delivery_token[]
*/
std::vector<delivery_token_ptr> get_pending_delivery_tokens() const override;
/**
* Returns the current number of buffered (publish) messages for this client.
* @return number of buffered messages
*/
virtual int get_buffered_messages_num() const override;
/**
* Returns the client ID used by this client.
* @return The client ID used by this client.
Expand Down
5 changes: 5 additions & 0 deletions include/mqtt/iasync_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ class iasync_client
* @return delivery_token[]
*/
virtual std::vector<delivery_token_ptr> get_pending_delivery_tokens() const = 0;
/**
* Returns the current number of buffered (publish) messages for this client.
* @return number of buffered messages
*/
virtual int get_buffered_messages_num() const = 0;
/**
* Returns the client ID used by this client.
* @return string
Expand Down
20 changes: 20 additions & 0 deletions src/async_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
#include "mqtt/response_options.h"
#include "mqtt/token.h"

// Include MQTTAsyncUtils, but need a workaround for the error
// ""redeclaration of C++ built-in type ‘bool’" inside this header"
#define bool c_bool
#include <MQTTAsyncUtils.h>
#undef bool

#define UNUSED(x) (void)(x)

namespace mqtt {
Expand Down Expand Up @@ -559,8 +565,22 @@ std::vector<delivery_token_ptr> async_client::get_pending_delivery_tokens() cons
}
}
return toks;

}

int async_client::get_buffered_messages_num() const
{
// Gets number of all buffered messages (QOS0-2)
// I'd like to have used MQTTAsync_getNoBufferedMessages() from MQTTAsyncUtils.h
// directly, but I haven't gotten it to compile correctly
// I hope the C++ lock_ also serves the same functionality as the C MQTTAsync mutex

guard g(lock_);
return ((MQTTAsyncs*)cli_)->noBufferedMessages;
}



// --------------------------------------------------------------------------
// Publish

Expand Down
5 changes: 5 additions & 0 deletions test/unit/mock_async_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ class mock_async_client : public virtual mqtt::iasync_client
return std::vector<mqtt::delivery_token_ptr>{};
};

int get_buffered_messages_num() const override
{
return 0;
}

std::string get_client_id() const override { return std::string{}; };

std::string get_server_uri() const override { return std::string{}; };
Expand Down