From 94efd557b423be65e3a3cfe2fb4dc2d0a2c07d06 Mon Sep 17 00:00:00 2001 From: fpagliughi Date: Sun, 12 Nov 2023 20:04:14 -0500 Subject: [PATCH] #411 Missing virtual keyword for some client methods --- src/mqtt/async_client.h | 8 ++++---- src/mqtt/client.h | 8 ++++---- src/mqtt/iasync_client.h | 25 +++++++++++++++++++++++++ test/unit/mock_async_client.h | 12 +++++++++++- 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/mqtt/async_client.h b/src/mqtt/async_client.h index 2e5c6f3..6a4f4a5 100644 --- a/src/mqtt/async_client.h +++ b/src/mqtt/async_client.h @@ -697,26 +697,26 @@ public: * This initializes the client to receive messages through a queue that * can be read synchronously. */ - void start_consuming(); + void start_consuming() override; /** * Stop consuming messages. * This shuts down the internal callback and discards any unread * messages. */ - void stop_consuming(); + void stop_consuming() override; /** * Read the next message from the queue. * This blocks until a new message arrives. * @return The message and topic. */ - const_message_ptr consume_message() { return que_->get(); } + const_message_ptr consume_message() override { return que_->get(); } /** * Try to read the next message from the queue without blocking. * @param msg Pointer to the value to receive the message * @return @em true is a message was read, @em false if no message was * available. */ - bool try_consume_message(const_message_ptr* msg) { + bool try_consume_message(const_message_ptr* msg) override { return que_->try_get(msg); } /** diff --git a/src/mqtt/client.h b/src/mqtt/client.h index 4e9f737..6ba43f4 100644 --- a/src/mqtt/client.h +++ b/src/mqtt/client.h @@ -377,26 +377,26 @@ public: * This initializes the client to receive messages through a queue that * can be read synchronously. */ - void start_consuming() { cli_.start_consuming(); } + virtual void start_consuming() { cli_.start_consuming(); } /** * Stop consuming messages. * This shuts down the internal callback and discards any unread * messages. */ - void stop_consuming() { cli_.stop_consuming(); } + virtual void stop_consuming() { cli_.stop_consuming(); } /** * Read the next message from the queue. * This blocks until a new message arrives. * @return The message and topic. */ - const_message_ptr consume_message() { return cli_.consume_message(); } + virtual const_message_ptr consume_message() { return cli_.consume_message(); } /** * Try to read the next message from the queue without blocking. * @param msg Pointer to the value to receive the message * @return @em true is a message was read, @em false if no message was * available. */ - bool try_consume_message(const_message_ptr* msg) { + virtual bool try_consume_message(const_message_ptr* msg) { return cli_.try_consume_message(msg); } /** diff --git a/src/mqtt/iasync_client.h b/src/mqtt/iasync_client.h index cb6c83e..e011ab7 100644 --- a/src/mqtt/iasync_client.h +++ b/src/mqtt/iasync_client.h @@ -425,6 +425,31 @@ public: virtual token_ptr unsubscribe(const string& topicFilter, void* userContext, iaction_listener& cb, const properties& props=properties()) =0; + /** + * Start consuming messages. + * This initializes the client to receive messages through a queue that + * can be read synchronously. + */ + virtual void start_consuming() =0; + /** + * Stop consuming messages. + * This shuts down the internal callback and discards any unread + * messages. + */ + virtual void stop_consuming() =0; + /** + * Read the next message from the queue. + * This blocks until a new message arrives. + * @return The message and topic. + */ + virtual const_message_ptr consume_message() =0; + /** + * Try to read the next message from the queue without blocking. + * @param msg Pointer to the value to receive the message + * @return @em true is a message was read, @em false if no message was + * available. + */ + virtual bool try_consume_message(const_message_ptr* msg) =0; }; ///////////////////////////////////////////////////////////////////////////// diff --git a/test/unit/mock_async_client.h b/test/unit/mock_async_client.h index b0a1b43..51a3458 100644 --- a/test/unit/mock_async_client.h +++ b/test/unit/mock_async_client.h @@ -33,7 +33,7 @@ namespace mqtt { ///////////////////////////////////////////////////////////////////////////// -class mock_async_client : public mqtt::iasync_client +class mock_async_client : public virtual mqtt::iasync_client { public: void remove_token(mqtt::token* tok) override {} @@ -209,6 +209,16 @@ public: const properties& props=properties()) override { return mqtt::token_ptr{}; } + + void start_consuming() override {} + void stop_consuming() override {} + + const_message_ptr consume_message() override { + return const_message_ptr{}; + } + + bool try_consume_message(const_message_ptr*) override { return false; } + }; /////////////////////////////////////////////////////////////////////////////