Paho C++
1.0
The Paho MQTT C++ Client Library
|
Lightweight client for talking to an MQTT server using methods that block until an operation completes. More...
#include <client.h>
Public Types | |
using | ptr_t = std::shared_ptr< client > |
Smart pointer type for this object. | |
using | qos_collection = async_client::qos_collection |
Type for a collection of QOS values. | |
Public Member Functions | |
client (const string &serverURI, const string &clientId, iclient_persistence *persistence=nullptr) | |
Create a client that can be used to communicate with an MQTT server. More... | |
client (const string &serverURI, const string &clientId, const string &persistDir) | |
Create an async_client that can be used to communicate with an MQTT server. More... | |
client (const string &serverURI, const string &clientId, int maxBufferedMessages, iclient_persistence *persistence=nullptr) | |
Create a client that can be used to communicate with an MQTT server, which allows for off-line message buffering. More... | |
client (const string &serverURI, const string &clientId, int maxBufferedMessages, const string &persistDir) | |
Create a client that can be used to communicate with an MQTT server, which allows for off-line message buffering. More... | |
virtual | ~client () |
Virtual destructor. | |
virtual void | connect () |
Connects to an MQTT server using the default options. | |
virtual void | connect (connect_options opts) |
Connects to an MQTT server using the specified options. More... | |
virtual void | reconnect () |
Reconnects the client using options from the previous connect. More... | |
virtual void | disconnect () |
Disconnects from the server. | |
virtual void | disconnect (int timeoutMS) |
Disconnects from the server. More... | |
template<class Rep , class Period > | |
void | disconnect (const std::chrono::duration< Rep, Period > &to) |
Disconnects from the server. More... | |
virtual string | get_client_id () const |
Gets the client ID used by this client. More... | |
virtual string | get_server_uri () const |
Gets the address of the server used by this client. More... | |
virtual std::chrono::milliseconds | get_timeout () const |
Return the maximum time to wait for an action to complete. More... | |
virtual topic | get_topic (const string &top) |
Get a topic object which can be used to publish messages on this client. More... | |
virtual bool | is_connected () const |
Determines if this client is currently connected to the server. More... | |
virtual void | publish (string_ref top, const void *payload, size_t n, int qos, bool retained) |
Publishes a message to a topic on the server and return once it is delivered. More... | |
virtual void | publish (string_ref top, const void *payload, size_t n) |
Publishes a message to a topic on the server and return once it is delivered. More... | |
virtual void | publish (const_message_ptr msg) |
Publishes a message to a topic on the server. More... | |
virtual void | publish (const message &msg) |
Publishes a message to a topic on the server. More... | |
virtual void | set_callback (callback &cb) |
Sets the callback listener to use for events that happen asynchronously. More... | |
virtual void | set_timeout (int timeoutMS) |
Set the maximum time to wait for an action to complete. More... | |
template<class Rep , class Period > | |
void | set_timeout (const std::chrono::duration< Rep, Period > &to) |
Set the maximum time to wait for an action to complete. More... | |
virtual void | subscribe (const string &topicFilter) |
Subscribe to a topic, which may include wildcards using a QoS of 1. More... | |
virtual void | subscribe (const string &topicFilter, int qos) |
Subscribe to a topic, which may include wildcards. More... | |
virtual void | subscribe (const string_collection &topicFilters) |
Subscribes to a one or more topics, which may include wildcards using a QoS of 1. More... | |
virtual void | subscribe (const string_collection &topicFilters, const qos_collection &qos) |
Subscribes to multiple topics, each of which may include wildcards. More... | |
virtual void | unsubscribe (const string &topicFilter) |
Requests the server unsubscribe the client from a topic. More... | |
virtual void | unsubscribe (const string_collection &topicFilters) |
Requests the server unsubscribe the client from one or more topics. More... | |
void | start_consuming () |
Start consuming messages. More... | |
void | stop_consuming () |
Stop consuming messages. More... | |
const_message_ptr | consume_message () |
Read the next message from the queue. More... | |
bool | try_consume_message (const_message_ptr *msg) |
Try to read the next message from the queue without blocking. More... | |
template<typename Rep , class Period > | |
bool | try_consume_message_for (const_message_ptr *msg, const std::chrono::duration< Rep, Period > &relTime) |
Waits a limited time for a message to arrive. More... | |
template<class Clock , class Duration > | |
bool | try_consume_message_until (const_message_ptr *msg, const std::chrono::time_point< Clock, Duration > &absTime) |
Waits until a specific time for a message to occur. More... | |
Lightweight client for talking to an MQTT server using methods that block until an operation completes.
mqtt::client::client | ( | const string & | serverURI, |
const string & | clientId, | ||
iclient_persistence * | persistence = nullptr |
||
) |
Create a client that can be used to communicate with an MQTT server.
This allows the caller to specify a user-defined persistence object, or use no persistence.
serverURI | the address of the server to connect to, specified as a URI. |
clientId | a client identifier that is unique on the server being connected to |
persistence | The user persistence structure. If this is null, then no persistence is used. |
mqtt::client::client | ( | const string & | serverURI, |
const string & | clientId, | ||
const string & | persistDir | ||
) |
Create an async_client that can be used to communicate with an MQTT server.
This uses file-based persistence in the specified directory.
serverURI | the address of the server to connect to, specified as a URI. |
clientId | a client identifier that is unique on the server being connected to |
persistDir | The directory to use for persistence data |
mqtt::client::client | ( | const string & | serverURI, |
const string & | clientId, | ||
int | maxBufferedMessages, | ||
iclient_persistence * | persistence = nullptr |
||
) |
Create a client that can be used to communicate with an MQTT server, which allows for off-line message buffering.
This allows the caller to specify a user-defined persistence object, or use no persistence.
serverURI | the address of the server to connect to, specified as a URI. |
clientId | a client identifier that is unique on the server being connected to |
maxBufferedMessages | the maximum number of messages allowed to be buffered while not connected |
persistence | The user persistence structure. If this is null, then no persistence is used. |
mqtt::client::client | ( | const string & | serverURI, |
const string & | clientId, | ||
int | maxBufferedMessages, | ||
const string & | persistDir | ||
) |
Create a client that can be used to communicate with an MQTT server, which allows for off-line message buffering.
This uses file-based persistence in the specified directory.
serverURI | the address of the server to connect to, specified as a URI. |
clientId | a client identifier that is unique on the server being connected to |
maxBufferedMessages | the maximum number of messages allowed to be buffered while not connected |
persistDir | The directory to use for persistence data |
|
inlinevirtual |
Connects to an MQTT server using the specified options.
opts |
|
inline |
Read the next message from the queue.
This blocks until a new message arrives.
|
inlinevirtual |
Disconnects from the server.
timeoutMS | the amount of time in milliseconds to allow for existing work to finish before disconnecting. A value of zero or less means the client will not quiesce. |
|
inline |
Disconnects from the server.
to | the amount of time in milliseconds to allow for existing work to finish before disconnecting. A value of zero or less means the client will not quiesce. |
|
inlinevirtual |
Gets the client ID used by this client.
|
inlinevirtual |
Gets the address of the server used by this client.
|
inlinevirtual |
Return the maximum time to wait for an action to complete.
|
inlinevirtual |
Get a topic object which can be used to publish messages on this client.
top | The topic name |
|
inlinevirtual |
Determines if this client is currently connected to the server.
|
inlinevirtual |
Publishes a message to a topic on the server and return once it is delivered.
top | The topic to publish |
payload | The data to publish |
n | The size in bytes of the data |
qos | The QoS for message delivery |
retained | Whether the broker should retain the message |
|
inlinevirtual |
Publishes a message to a topic on the server and return once it is delivered.
top | The topic to publish |
payload | The data to publish |
n | The size in bytes of the data |
|
inlinevirtual |
Publishes a message to a topic on the server.
msg | The message |
|
inlinevirtual |
Publishes a message to a topic on the server.
This version will not timeout since that could leave the library with a reference to memory that could disappear while the library is still using it.
msg | The message |
|
inlinevirtual |
Reconnects the client using options from the previous connect.
The client must have previously called connect() for this to work.
|
virtual |
Sets the callback listener to use for events that happen asynchronously.
cb | The callback functions |
|
inlinevirtual |
Set the maximum time to wait for an action to complete.
timeoutMS | The timeout in milliseconds |
|
inline |
Set the maximum time to wait for an action to complete.
to | The timeout as a std::chrono duration. |
|
inline |
Start consuming messages.
This initializes the client to receive messages through a queue that can be read synchronously.
|
inline |
Stop consuming messages.
This shuts down the internal callback and discards any unread messages.
|
inlinevirtual |
Subscribe to a topic, which may include wildcards using a QoS of 1.
topicFilter |
|
inlinevirtual |
Subscribe to a topic, which may include wildcards.
topicFilter | A single topic to subscribe |
qos | The QoS of the subscription |
|
virtual |
Subscribes to a one or more topics, which may include wildcards using a QoS of 1.
topicFilters | A set of topics to subscribe |
|
inlinevirtual |
Subscribes to multiple topics, each of which may include wildcards.
topicFilters | A collection of topics to subscribe |
qos | A collection of QoS for each topic |
|
inline |
Try to read the next message from the queue without blocking.
msg | Pointer to the value to receive the message |
|
inline |
Waits a limited time for a message to arrive.
msg | Pointer to the value to receive the message |
relTime | The maximum amount of time to wait for a message. |
|
inline |
Waits until a specific time for a message to occur.
msg | Pointer to the value to receive the message |
absTime | The time point to wait until, before timing out. |
|
inlinevirtual |
Requests the server unsubscribe the client from a topic.
topicFilter | A single topic to unsubscribe. |
|
inlinevirtual |
Requests the server unsubscribe the client from one or more topics.
topicFilters | A collection of topics to unsubscribe. |