![]() |
PahoMqttCpp
MQTT C++ Client for POSIX and Windows
|
#include <connect_options.h>
Public Types | |
using | ptr_t = std::shared_ptr<connect_options> |
using | const_ptr_t = std::shared_ptr<const connect_options> |
Public Member Functions | |
connect_options (int ver=MQTTVERSION_DEFAULT) | |
connect_options (string_ref userName, binary_ref password, int ver=MQTTVERSION_DEFAULT) | |
connect_options (const connect_options &opt) | |
connect_options (connect_options &&opt) | |
connect_options & | operator= (const connect_options &opt) |
connect_options & | operator= (connect_options &&opt) |
std::chrono::seconds | get_keep_alive_interval () const |
std::chrono::seconds | get_connect_timeout () const |
string | get_user_name () const |
binary_ref | get_password () const |
string | get_password_str () const |
int | get_max_inflight () const |
string | get_will_topic () const |
const_message_ptr | get_will_message () const |
const will_options & | get_will_options () const |
const ssl_options & | get_ssl_options () const |
void | set_ssl (const ssl_options &ssl) |
void | set_ssl (ssl_options &&ssl) |
bool | is_clean_session () const |
bool | is_clean_start () const |
token_ptr | get_token () const |
const_string_collection_ptr | get_servers () const |
int | get_mqtt_version () const |
bool | get_automatic_reconnect () const |
std::chrono::seconds | get_min_retry_interval () const |
std::chrono::seconds | get_max_retry_interval () const |
void | set_clean_session (bool cleanSession) |
void | set_clean_start (bool cleanStart) |
void | set_keep_alive_interval (int keepAliveInterval) |
template<class Rep, class Period> | |
void | set_keep_alive_interval (const std::chrono::duration< Rep, Period > &interval) |
void | set_connect_timeout (int timeout) |
template<class Rep, class Period> | |
void | set_connect_timeout (const std::chrono::duration< Rep, Period > &timeout) |
void | set_user_name (string_ref userName) |
void | set_password (binary_ref password) |
void | set_max_inflight (int n) |
void | set_will (const will_options &will) |
void | set_will (will_options &&will) |
void | set_will_message (const message &msg) |
void | set_will_message (const_message_ptr msg) |
void | set_token (const token_ptr &tok) |
void | set_servers (const_string_collection_ptr serverURIs) |
void | set_mqtt_version (int mqttVersion) |
void | set_automatic_reconnect (bool on) |
void | set_automatic_reconnect (int minRetryInterval, int maxRetryInterval) |
template<class Rep1, class Period1, class Rep2, class Period2> | |
void | set_automatic_reconnect (const std::chrono::duration< Rep1, Period1 > &minRetryInterval, const std::chrono::duration< Rep2, Period2 > &maxRetryInterval) |
const properties & | get_properties () const |
properties & | get_properties () |
void | set_properties (const properties &props) |
void | set_properties (properties &&props) |
const name_value_collection & | get_http_headers () const |
void | set_http_headers (const name_value_collection &httpHeaders) |
void | set_http_headers (name_value_collection &&httpHeaders) |
string | get_http_proxy () const |
void | set_http_proxy (const string &httpProxy) |
string | get_https_proxy () const |
void | set_https_proxy (const string &httpsProxy) |
Static Public Member Functions | |
static connect_options | v3 () |
static connect_options | v5 () |
static connect_options | ws () |
static connect_options | v5_ws () |
Friends | |
class | async_client |
Holds the set of options that control how the client connects to a server.
using mqtt::connect_options::ptr_t = std::shared_ptr<connect_options> |
Smart/shared pointer to an object of this class.
using mqtt::connect_options::const_ptr_t = std::shared_ptr<const connect_options> |
Smart/shared pointer to a const object of this class.
|
explicit |
Constructs a new object using the default values.
ver | The MQTT protocol version. |
mqtt::connect_options::connect_options | ( | string_ref | userName, |
binary_ref | password, | ||
int | ver = MQTTVERSION_DEFAULT ) |
Constructs a new object using the specified user name and password.
userName | The name of the user for connecting to the server |
password | The password for connecting to the server |
ver | The MQTT protocol version. |
mqtt::connect_options::connect_options | ( | const connect_options & | opt | ) |
Copy constructor.
opt | Another object to copy. |
mqtt::connect_options::connect_options | ( | connect_options && | opt | ) |
Move constructor.
opt | Another object to move into this new one. |
|
inlinestatic |
Creates default options for an MQTT v3.x connection.
|
inlinestatic |
Creates default options for an MQTT v5 connection.
|
inlinestatic |
Creates default options for an MQTT v3.x connection using WebSockets.
The keepalive interval is set to 45 seconds to avoid webserver 60 second inactivity timeouts.
|
inlinestatic |
Creates default options for an MQTT v5 connection using WebSockets.
The keepalive interval is set to 45 seconds to avoid webserver 60 second inactivity timeouts.
connect_options & mqtt::connect_options::operator= | ( | const connect_options & | opt | ) |
Copy assignment.
opt | Another object to copy. |
connect_options & mqtt::connect_options::operator= | ( | connect_options && | opt | ) |
Move assignment.
opt | Another object to move into this new one. |
|
inline |
Expose the underlying C struct for the unit tests. Gets the "keep alive" interval.
|
inline |
Gets the connection timeout. This is the amount of time the underlying library will wait for a timeout before failing.
|
inline |
Gets the user name to use for the connection.
|
inline |
Gets the password to use for the connection.
|
inline |
Gets the password to use for the connection.
|
inline |
Gets the maximum number of messages that can be in-flight simultaneously.
|
inline |
Gets the topic to be used for last will and testament (LWT).
|
inline |
Gets the message to be sent as last will and testament (LWT).
|
inline |
Get the LWT options to use for the connection.
|
inline |
Get the SSL options to use for the connection.
void mqtt::connect_options::set_ssl | ( | const ssl_options & | ssl | ) |
Sets the SSL for the connection. These will only have an effect if compiled against the SSL version of the Paho C library, and using a secure connection, "ssl://" or "wss://".
ssl | The SSL options. |
void mqtt::connect_options::set_ssl | ( | ssl_options && | ssl | ) |
Sets the SSL for the connection. These will only have an effect if compiled against the SSL version of the Paho C library, and using a secure connection, "ssl://" or "wss://".
ssl | The SSL options. |
|
inline |
Returns whether the server should remember state for the client across reconnects. This only applies to MQTT v3.x connections.
|
inline |
Returns whether the server should remember state for the client across reconnects. This only applies to MQTT v5 connections.
|
inline |
Gets the token used as the callback context.
|
inline |
Gets the list of servers to which the client will connect.
|
inline |
Gets the version of MQTT to be used for the connection.
|
inline |
Determines if the options have been configured for automatic reconnect.
|
inline |
Gets the minimum retry interval for automatic reconnect.
|
inline |
Gets the maximum retry interval for automatic reconnect.
void mqtt::connect_options::set_clean_session | ( | bool | cleanSession | ) |
Sets whether the server should remember state for the client across reconnects. (MQTT v3.x only)
This will only take effect if the version is already set to v3.x (not v5).
cleanSession | true if the server should NOT remember state for the client across reconnects, false otherwise. |
void mqtt::connect_options::set_clean_start | ( | bool | cleanStart | ) |
Sets whether the server should remember state for the client across reconnects. (MQTT v5 only)
If a persistent session is desired (turning this off), then the app should also set the Session Expiry Interval
property, and add that to the connect options.
This will only take effect if the MQTT version is set to v5
cleanStart | true if the server should NOT remember state for the client across reconnects, false otherwise. |
|
inline |
Sets the "keep alive" interval. This is the maximum time that should pass without communications between client and server. If no messages pass in this time, the client will ping the broker.
keepAliveInterval | The keep alive interval in seconds. |
|
inline |
Sets the "keep alive" interval with a chrono duration. This is the maximum time that should pass without communications between client and server. If no messages pass in this time, the client will ping the broker.
interval | The keep alive interval. |
|
inline |
Sets the connect timeout in seconds. This is the maximum time that the underlying library will wait for a connection before failing.
timeout | The connect timeout in seconds. |
|
inline |
Sets the connect timeout with a chrono duration. This is the maximum time that the underlying library will wait for a connection before failing.
timeout | The connect timeout in seconds. |
void mqtt::connect_options::set_user_name | ( | string_ref | userName | ) |
Sets the user name to use for the connection.
userName | The user name for connecting to the MQTT broker. |
void mqtt::connect_options::set_password | ( | binary_ref | password | ) |
Sets the password to use for the connection.
password | The password for connecting to the MQTT broker. |
|
inline |
Sets the maximum number of messages that can be in-flight simultaneously.
n | The maximum number of inflight messages. |
void mqtt::connect_options::set_will | ( | const will_options & | will | ) |
Sets the "Last Will and Testament" (LWT) for the connection.
will | The LWT options. |
void mqtt::connect_options::set_will | ( | will_options && | will | ) |
Sets the "Last Will and Testament" (LWT) for the connection.
will | The LWT options. |
|
inline |
Sets the "Last Will and Testament" (LWT) as a message
msg | The LWT message |
|
inline |
Sets the "Last Will and Testament" (LWT) as a message
msg | Pointer to a LWT message |
void mqtt::connect_options::set_token | ( | const token_ptr & | tok | ) |
Sets the callback context to a delivery token.
tok | The delivery token to be used as the callback context. |
void mqtt::connect_options::set_servers | ( | const_string_collection_ptr | serverURIs | ) |
Sets the list of servers to which the client will connect.
serverURIs | A pointer to a collection of server URI's. Each entry should be of the form protocol://host:port where protocol must be tcp or ssl. For host, you can specify either an IP address or a domain name. |
void mqtt::connect_options::set_mqtt_version | ( | int | mqttVersion | ) |
Sets the version of MQTT to be used on the connect.
This will also set other connect options to legal values dependent on the selected version.
mqttVersion | The MQTT version to use for the connection:
|
|
inline |
Enable or disable automatic reconnects. The retry intervals are not affected.
on | Whether to turn reconnects on or off |
void mqtt::connect_options::set_automatic_reconnect | ( | int | minRetryInterval, |
int | maxRetryInterval ) |
Enable or disable automatic reconnects.
minRetryInterval | Minimum retry interval in seconds. Doubled on each failed retry. |
maxRetryInterval | Maximum retry interval in seconds. The doubling stops here on failed retries. |
|
inline |
Enable or disable automatic reconnects.
minRetryInterval | Minimum retry interval. Doubled on each failed retry. |
maxRetryInterval | Maximum retry interval. The doubling stops here on failed retries. |
|
inline |
Gets the connect properties.
|
inline |
Gets a mutable reference to the connect properties.
void mqtt::connect_options::set_properties | ( | const properties & | props | ) |
Sets the properties for the connect.
props | The properties to place into the message. |
void mqtt::connect_options::set_properties | ( | properties && | props | ) |
Moves the properties for the connect.
props | The properties to move into the connect object. |
|
inline |
Gets the HTTP headers
|
inline |
Sets the HTTP headers for the connection.
httpHeaders | The header nam/value collection. |
|
inline |
Sets the HTTP headers for the connection.
httpHeaders | The header nam/value collection. |
|
inline |
Gets the HTTP proxy setting.
void mqtt::connect_options::set_http_proxy | ( | const string & | httpProxy | ) |
Sets the HTTP proxy setting.
httpProxy | The HTTP proxy setting. An empty string means no proxy. |
|
inline |
Gets the secure HTTPS proxy setting.
void mqtt::connect_options::set_https_proxy | ( | const string & | httpsProxy | ) |
Sets the secure HTTPS proxy setting.
httpsProxy | The HTTPS proxy setting. An empty string means no proxy. |
|
friend |
The client has special access