Skip to content

Commit

Permalink
#411 Missing virtual keyword for some client methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fpagliughi committed Nov 13, 2023
1 parent bb66355 commit 94efd55
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/mqtt/async_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -697,26 +697,26 @@ class async_client : public virtual iasync_client
* 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);
}
/**
Expand Down
8 changes: 4 additions & 4 deletions src/mqtt/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,26 +377,26 @@ class client : private callback
* 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);
}
/**
Expand Down
25 changes: 25 additions & 0 deletions src/mqtt/iasync_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,31 @@ class iasync_client
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;
};

/////////////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 11 additions & 1 deletion test/unit/mock_async_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down Expand Up @@ -209,6 +209,16 @@ class mock_async_client : public mqtt::iasync_client
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; }

};

/////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 94efd55

Please sign in to comment.