From f4f8d9a0ffdcc4e5a83d18736ebc9fec793ca4f7 Mon Sep 17 00:00:00 2001 From: fpagliughi Date: Tue, 24 Jun 2025 16:58:10 -0400 Subject: [PATCH 1/2] #558 Fixed cmake project version for release v1.5.2 --- CMakeLists.txt | 2 +- dist/paho-cpp.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e32efc3..807293f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ cmake_minimum_required(VERSION 3.13) -project(PahoMqttCpp VERSION "1.5.1") +project(PahoMqttCpp VERSION "1.5.2") ## --- Build options --- diff --git a/dist/paho-cpp.spec b/dist/paho-cpp.spec index c8049be0..c49826ad 100644 --- a/dist/paho-cpp.spec +++ b/dist/paho-cpp.spec @@ -1,6 +1,6 @@ Summary: MQTT CPP Client Name: paho-cpp -Version: 1.5.1 +Version: 1.5.2 Release: 0%{?dist} License: Eclipse Eclipse Public License 2.0 and Distribution License 1.0 Group: Development/Tools From f114ea8d36dd18f70eabc537e8ceb288125a1b57 Mon Sep 17 00:00:00 2001 From: LeoDJ Date: Sat, 26 Jul 2025 03:53:44 +0200 Subject: [PATCH 2/2] Implement async_client::get_buffered_messages_num() --- include/mqtt/async_client.h | 5 +++++ include/mqtt/iasync_client.h | 5 +++++ src/async_client.cpp | 20 ++++++++++++++++++++ test/unit/mock_async_client.h | 5 +++++ 4 files changed, 35 insertions(+) diff --git a/include/mqtt/async_client.h b/include/mqtt/async_client.h index 99f065db..8a9d210d 100644 --- a/include/mqtt/async_client.h +++ b/include/mqtt/async_client.h @@ -499,6 +499,11 @@ class async_client : public virtual iasync_client * @return delivery_token[] */ std::vector 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. diff --git a/include/mqtt/iasync_client.h b/include/mqtt/iasync_client.h index acff640c..188da937 100644 --- a/include/mqtt/iasync_client.h +++ b/include/mqtt/iasync_client.h @@ -181,6 +181,11 @@ class iasync_client * @return delivery_token[] */ virtual std::vector 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 diff --git a/src/async_client.cpp b/src/async_client.cpp index b11f00f2..8d1007ce 100644 --- a/src/async_client.cpp +++ b/src/async_client.cpp @@ -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 +#undef bool + #define UNUSED(x) (void)(x) namespace mqtt { @@ -559,8 +565,22 @@ std::vector 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 diff --git a/test/unit/mock_async_client.h b/test/unit/mock_async_client.h index 080c8ee1..2ca67748 100644 --- a/test/unit/mock_async_client.h +++ b/test/unit/mock_async_client.h @@ -109,6 +109,11 @@ class mock_async_client : public virtual mqtt::iasync_client return std::vector{}; }; + 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{}; };