PahoMqttCpp
MQTT C++ Client for POSIX and Windows
Loading...
Searching...
No Matches
Data Structures | Typedefs | Enumerations | Functions | Variables
mqtt Namespace Reference

Data Structures

class  async_client
 
class  buffer_ref
 
class  buffer_view
 
class  callback
 
class  client
 
class  connect_data
 
class  connect_options
 
class  connect_options_builder
 
class  connect_response
 
struct  connected_event
 
struct  connection_lost_event
 
class  create_options
 
class  create_options_builder
 
class  delivery_response_options
 
class  delivery_token
 
class  disconnect_options
 
class  disconnect_options_builder
 
struct  disconnected_event
 
class  event
 
class  exception
 
class  iaction_listener
 
class  iasync_client
 
class  iclient_persistence
 
class  message
 
class  message_ptr_builder
 
class  missing_response
 
class  name_value_collection
 
struct  no_persistence
 
class  persistence_exception
 
class  properties
 
class  property
 
class  queue_closed
 
class  response_options
 
class  response_options_builder
 
class  security_exception
 
class  server_response
 
struct  shutdown_event
 
class  ssl_options
 
class  ssl_options_builder
 
class  string_collection
 
class  subscribe_options
 
struct  subscribe_response
 
class  thread_queue
 
class  timeout_error
 
class  token
 
class  topic
 
class  topic_filter
 
class  topic_matcher
 
class  unsubscribe_response
 
class  will_options
 

Typedefs

using async_client_ptr = async_client::ptr_t
 
using string_ref = buffer_ref< char >
 
using binary_ref = buffer_ref< char >
 
using string_view = buffer_view< char >
 
using binary_view = buffer_view< char >
 
using callback_ptr = callback::ptr_t
 
using const_callback_ptr = callback::const_ptr_t
 
using client_ptr = client::ptr_t
 
using connect_options_ptr = connect_options::ptr_t
 
using persistence_type = std::variant< no_persistence, string, iclient_persistence * >
 
using create_options_ptr = create_options::ptr_t
 
using delivery_token_ptr = delivery_token::ptr_t
 
using const_delivery_token_ptr = delivery_token::const_ptr_t
 
using bad_cast = std::bad_cast
 
using iaction_listener_ptr = iaction_listener::ptr_t
 
using const_iaction_listener_ptr = iaction_listener::const_ptr_t
 
using iclient_persistence_ptr = iclient_persistence::ptr_t
 
using const_iclient_persistence_ptr = iclient_persistence::const_ptr_t
 
using message_ptr = message::ptr_t
 
using const_message_ptr = message::const_ptr_t
 
using string_pair = std::tuple< string, string >
 
using ssl_options_ptr = ssl_options::ptr_t
 
using ssl_options_unique_ptr = ssl_options::unique_ptr_t
 
using string_collection_ptr = string_collection::ptr_t
 
using const_string_collection_ptr = string_collection::const_ptr_t
 
using subscribe_options_ptr = subscribe_options::ptr_t
 
using token_ptr = token::ptr_t
 
using const_token_ptr = token::const_ptr_t
 
using topic_ptr = topic::ptr_t
 
using const_topic_ptr = topic::const_ptr_t
 
using byte = uint8_t
 
using string = std::string
 
using binary = std::string
 
using string_ptr = std::shared_ptr< const string >
 
using binary_ptr = std::shared_ptr< const binary >
 
using will_options_ptr = will_options::ptr_t
 
using const_will_options_ptr = will_options::const_ptr_t
 
using will_options_unique_ptr = will_options::unique_ptr_t
 

Enumerations

enum  ReasonCode {
  SUCCESS = 0 , NORMAL_DISCONNECTION = 0 , GRANTED_QOS_0 = 0 , GRANTED_QOS_1 = 1 ,
  GRANTED_QOS_2 = 2 , DISCONNECT_WITH_WILL_MESSAGE = 4 , NO_MATCHING_SUBSCRIBERS = 16 , NO_SUBSCRIPTION_FOUND = 17 ,
  CONTINUE_AUTHENTICATION = 24 , RE_AUTHENTICATE = 25 , UNSPECIFIED_ERROR = 128 , MALFORMED_PACKET = 129 ,
  PROTOCOL_ERROR = 130 , IMPLEMENTATION_SPECIFIC_ERROR = 131 , UNSUPPORTED_PROTOCOL_VERSION = 132 , CLIENT_IDENTIFIER_NOT_VALID = 133 ,
  BAD_USER_NAME_OR_PASSWORD = 134 , NOT_AUTHORIZED = 135 , SERVER_UNAVAILABLE = 136 , SERVER_BUSY = 137 ,
  BANNED = 138 , SERVER_SHUTTING_DOWN = 139 , BAD_AUTHENTICATION_METHOD = 140 , KEEP_ALIVE_TIMEOUT = 141 ,
  SESSION_TAKEN_OVER = 142 , TOPIC_FILTER_INVALID = 143 , TOPIC_NAME_INVALID = 144 , PACKET_IDENTIFIER_IN_USE = 145 ,
  PACKET_IDENTIFIER_NOT_FOUND = 146 , RECEIVE_MAXIMUM_EXCEEDED = 147 , TOPIC_ALIAS_INVALID = 148 , PACKET_TOO_LARGE = 149 ,
  MESSAGE_RATE_TOO_HIGH = 150 , QUOTA_EXCEEDED = 151 , ADMINISTRATIVE_ACTION = 152 , PAYLOAD_FORMAT_INVALID = 153 ,
  RETAIN_NOT_SUPPORTED = 154 , QOS_NOT_SUPPORTED = 155 , USE_ANOTHER_SERVER = 156 , SERVER_MOVED = 157 ,
  SHARED_SUBSCRIPTIONS_NOT_SUPPORTED = 158 , CONNECTION_RATE_EXCEEDED = 159 , MAXIMUM_CONNECT_TIME = 160 , SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED = 161 ,
  WILDCARD_SUBSCRIPTIONS_NOT_SUPPORTED = 162 , MQTTPP_V3_CODE = 0
}
 

Functions

const string VERSION_STR ("Paho MQTT C++ (mqttpp) v. 1.5.2")
 
const string COPYRIGHT ("Copyright (c) 2013-2025 Frank Pagliughi")
 
template<typename T >
std::ostream & operator<< (std::ostream &os, const buffer_ref< T > &buf)
 
template<typename T >
std::ostream & operator<< (std::ostream &os, const buffer_view< T > &buf)
 
std::ostream & operator<< (std::ostream &os, const exception &exc)
 
void * persistence_malloc (size_t n)
 
void persistence_free (void *p)
 
message_ptr make_message (string_ref topic, const void *payload, size_t len, int qos, bool retained, const properties &props=properties())
 
message_ptr make_message (string_ref topic, const void *payload, size_t len)
 
message_ptr make_message (string_ref topic, binary_ref payload, int qos, bool retained, const properties &props=properties())
 
message_ptr make_message (string_ref topic, binary_ref payload)
 
std::ostream & operator<< (std::ostream &os, const property &prop)
 
template<typename T >
get (const property &)
 
template<>
uint8_t get< uint8_t > (const property &prop)
 
template<>
uint16_t get< uint16_t > (const property &prop)
 
template<>
int16_t get< int16_t > (const property &prop)
 
template<>
uint32_t get< uint32_t > (const property &prop)
 
template<>
int32_t get< int32_t > (const property &prop)
 
template<>
string get< string > (const property &prop)
 
template<>
string_pair get< string_pair > (const property &prop)
 
template<typename T >
get (const properties &props, property::code propid, size_t idx)
 
template<typename T >
get (const properties &props, property::code propid)
 
std::string to_string (ReasonCode reasonCode)
 
std::ostream & operator<< (std::ostream &os, ReasonCode reasonCode)
 
template<class Rep , class Period >
std::chrono::seconds to_seconds (const std::chrono::duration< Rep, Period > &dur)
 
template<class Rep , class Period >
long to_seconds_count (const std::chrono::duration< Rep, Period > &dur)
 
template<class Rep , class Period >
std::chrono::milliseconds to_milliseconds (const std::chrono::duration< Rep, Period > &dur)
 
template<class Rep , class Period >
long to_milliseconds_count (const std::chrono::duration< Rep, Period > &dur)
 
bool to_bool (int n)
 
int to_int (bool b)
 
string to_string (const char *cstr)
 

Variables

const uint32_t VERSION = 0x01050002
 
constexpr no_persistence NO_PERSISTENCE {}
 

Typedef Documentation

◆ async_client_ptr

Smart/shared pointer to an asynchronous MQTT client object

◆ string_ref

using mqtt::string_ref = typedef buffer_ref<char>

A reference to a text buffer.

◆ binary_ref

using mqtt::binary_ref = typedef buffer_ref<char>

A reference to a binary buffer. Note that we're using char for the underlying data type to allow efficient moves to and from std::string's. Using a separate type indicates that the data may be arbitrary binary.

◆ string_view

using mqtt::string_view = typedef buffer_view<char>

A buffer view for character string data.

◆ binary_view

using mqtt::binary_view = typedef buffer_view<char>

A buffer view for binary data

◆ callback_ptr

Smart/shared pointer to a callback object

◆ const_callback_ptr

Smart/shared pointer to a const callback object

◆ client_ptr

Smart/shared pointer to an MQTT synchronous client object

◆ connect_options_ptr

Smart/shared pointer to a connection options object.

◆ persistence_type

A variant for the different type of persistence:

  • no_persistence: Any object of this type indicates no persistence is desired.
  • string: Indicates file persistence. The string specifies the directory for the persistence store.
  • iclient_persistence*: User-defined persistence

◆ create_options_ptr

Smart/shared pointer to a connection options object.

◆ delivery_token_ptr

Smart/shared pointer to a delivery_token

◆ const_delivery_token_ptr

Smart/shared pointer to a const delivery_token

◆ bad_cast

using mqtt::bad_cast = typedef std::bad_cast

Bring std::bad_cast into the mqtt namespace

◆ iaction_listener_ptr

Smart/shared pointer to an action listener

◆ const_iaction_listener_ptr

Smart/shared pointer to a const action listener

◆ iclient_persistence_ptr

Smart/shared pointer to a persistence client

◆ const_iclient_persistence_ptr

Smart/shared pointer to a persistence client

◆ message_ptr

Smart/shared pointer to a message

◆ const_message_ptr

Smart/shared pointer to a const message

◆ string_pair

using mqtt::string_pair = typedef std::tuple<string, string>

A pair of strings as a tuple.

◆ ssl_options_ptr

Shared pointer to the ssl options class.

◆ ssl_options_unique_ptr

Unique pointer to the ssl options class.

◆ string_collection_ptr

Smart/shared pointer to a string collection

◆ const_string_collection_ptr

Smart/shared pointer to a const string_collection

◆ subscribe_options_ptr

Smart/shared pointer to a subscribe options object.

◆ token_ptr

using mqtt::token_ptr = typedef token::ptr_t

Smart/shared pointer to a token object

◆ const_token_ptr

Smart/shared pointer to a const token object

◆ topic_ptr

using mqtt::topic_ptr = typedef topic::ptr_t

A smart/shared pointer to a topic object.

◆ const_topic_ptr

A smart/shared pointer to a const topic object.

◆ byte

using mqtt::byte = typedef uint8_t

A 'byte' is an 8-bit, unsigned int

◆ string

using mqtt::string = typedef std::string

An mqtt string is just a std::string

◆ binary

using mqtt::binary = typedef std::string

A binary blob of data is, umm, just a string too!

◆ string_ptr

using mqtt::string_ptr = typedef std::shared_ptr<const string>

Smart/shared pointer to a const string

◆ binary_ptr

using mqtt::binary_ptr = typedef std::shared_ptr<const binary>

Smart/shared pointer to a const binary blob

◆ will_options_ptr

Shared pointer to a will options object.

◆ const_will_options_ptr

Shared pointer to a const will options object.

◆ will_options_unique_ptr

Unique pointer to a will options object.

Enumeration Type Documentation

◆ ReasonCode

The MQTT v5 Reason Codes.

Enumerator
SUCCESS 
NORMAL_DISCONNECTION 
GRANTED_QOS_0 
GRANTED_QOS_1 
GRANTED_QOS_2 
DISCONNECT_WITH_WILL_MESSAGE 
NO_MATCHING_SUBSCRIBERS 
NO_SUBSCRIPTION_FOUND 
CONTINUE_AUTHENTICATION 
RE_AUTHENTICATE 
UNSPECIFIED_ERROR 
MALFORMED_PACKET 
PROTOCOL_ERROR 
IMPLEMENTATION_SPECIFIC_ERROR 
UNSUPPORTED_PROTOCOL_VERSION 
CLIENT_IDENTIFIER_NOT_VALID 
BAD_USER_NAME_OR_PASSWORD 
NOT_AUTHORIZED 
SERVER_UNAVAILABLE 
SERVER_BUSY 
BANNED 
SERVER_SHUTTING_DOWN 
BAD_AUTHENTICATION_METHOD 
KEEP_ALIVE_TIMEOUT 
SESSION_TAKEN_OVER 
TOPIC_FILTER_INVALID 
TOPIC_NAME_INVALID 
PACKET_IDENTIFIER_IN_USE 
PACKET_IDENTIFIER_NOT_FOUND 
RECEIVE_MAXIMUM_EXCEEDED 
TOPIC_ALIAS_INVALID 
PACKET_TOO_LARGE 
MESSAGE_RATE_TOO_HIGH 
QUOTA_EXCEEDED 
ADMINISTRATIVE_ACTION 
PAYLOAD_FORMAT_INVALID 
RETAIN_NOT_SUPPORTED 
QOS_NOT_SUPPORTED 
USE_ANOTHER_SERVER 
SERVER_MOVED 
SHARED_SUBSCRIPTIONS_NOT_SUPPORTED 
CONNECTION_RATE_EXCEEDED 
MAXIMUM_CONNECT_TIME 
SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED 
WILDCARD_SUBSCRIPTIONS_NOT_SUPPORTED 
MQTTPP_V3_CODE 

Function Documentation

◆ VERSION_STR()

const string mqtt::VERSION_STR ( "Paho MQTT C++ (mqttpp) v. 1.5.2"  )

The version string for the client library

◆ COPYRIGHT()

const string mqtt::COPYRIGHT ( "Copyright (c) 2013-2025 Frank Pagliughi"  )

Copyright notice for the client library

◆ operator<<() [1/5]

template<typename T >
std::ostream & mqtt::operator<< ( std::ostream &  os,
const buffer_ref< T > &  buf 
)

Stream inserter for a buffer reference. This does a binary write of the data in the buffer.

Parameters
osThe output stream.
bufThe buffer reference to write.
Returns
A reference to the output stream.

◆ operator<<() [2/5]

template<typename T >
std::ostream & mqtt::operator<< ( std::ostream &  os,
const buffer_view< T > &  buf 
)

Stream inserter for a buffer view. This does a binary write of the data in the buffer.

Parameters
osThe output stream.
bufThe buffer reference to write.
Returns
A reference to the output stream.

◆ operator<<() [3/5]

std::ostream & mqtt::operator<< ( std::ostream &  os,
const exception exc 
)
inline

Stream inserter writes a fairly verbose message

Parameters
osThe stream.
excThe exception to write.
Returns
A reference to the stream.

◆ persistence_malloc()

void * mqtt::persistence_malloc ( size_t  n)
inline

Allocate memory for use with user persistence.

Parameters
nThe number of bytes for the buffer.
Returns
A pointer to the allocated memory

◆ persistence_free()

void mqtt::persistence_free ( void *  p)
inline

Frees memory allocated with persistence_malloc().

Parameters
pPointer to a buffer obtained by persistence_malloc.

◆ make_message() [1/4]

message_ptr mqtt::make_message ( string_ref  topic,
const void *  payload,
size_t  len,
int  qos,
bool  retained,
const properties props = properties() 
)
inline

Constructs a message with the specified array as a payload, and all other values set to defaults.

Parameters
topicThe message topic
payloadthe bytes to use as the message payload
lenthe number of bytes in the payload
qosThe quality of service for the message.
retainedWhether the message should be retained by the broker.
propsThe MQTT v5 properties for the message.

◆ make_message() [2/4]

message_ptr mqtt::make_message ( string_ref  topic,
const void *  payload,
size_t  len 
)
inline

Constructs a message with the specified array as a payload, and all other values set to defaults.

Parameters
topicThe message topic
payloadthe bytes to use as the message payload
lenthe number of bytes in the payload

◆ make_message() [3/4]

message_ptr mqtt::make_message ( string_ref  topic,
binary_ref  payload,
int  qos,
bool  retained,
const properties props = properties() 
)
inline

Constructs a message with the specified values.

Parameters
topicThe message topic
payloadA buffer to use as the message payload.
qosThe quality of service for the message.
retainedWhether the message should be retained by the broker.

◆ make_message() [4/4]

message_ptr mqtt::make_message ( string_ref  topic,
binary_ref  payload 
)
inline

Constructs a message with the specified buffer as a payload, and all other values set to defaults.

Parameters
topicThe message topic
payloadA string to use as the message payload.

◆ operator<<() [4/5]

std::ostream & mqtt::operator<< ( std::ostream &  os,
const property prop 
)

◆ get() [1/3]

template<typename T >
T mqtt::get ( const property )
inline

Extracts the value from the property as the specified type.

Returns
The value from the property as the specified type.

◆ get< uint8_t >()

template<>
uint8_t mqtt::get< uint8_t > ( const property prop)
inline

Extracts the value from the property as an unsigned 8-bit integer.

Returns
The value from the property as an unsigned 8-bit integer.

◆ get< uint16_t >()

template<>
uint16_t mqtt::get< uint16_t > ( const property prop)
inline

Extracts the value from the property as an unsigned 16-bit integer.

Returns
The value from the property as an unsigned 16-bit integer.

◆ get< int16_t >()

template<>
int16_t mqtt::get< int16_t > ( const property prop)
inline

Extracts the value from the property as a signed 16-bit integer.

Returns
The value from the property as a signed 16-bit integer.
Deprecated:
All integer properties are unsigned. Use get<uint16_t>()

◆ get< uint32_t >()

template<>
uint32_t mqtt::get< uint32_t > ( const property prop)
inline

Extracts the value from the property as an unsigned 32-bit integer.

Returns
The value from the property as an unsigned 32-bit integer.

◆ get< int32_t >()

template<>
int32_t mqtt::get< int32_t > ( const property prop)
inline

Extracts the value from the property as a signed 32-bit integer.

Returns
The value from the property as a signed 32-bit integer.
Deprecated:
All integer properties are unsigned. Use get<uint32_t>()

◆ get< string >()

template<>
string mqtt::get< string > ( const property prop)
inline

Extracts the value from the property as a string.

Returns
The value from the property as a string.

◆ get< string_pair >()

template<>
string_pair mqtt::get< string_pair > ( const property prop)
inline

Extracts the value from the property as a pair of strings.

Returns
The value from the property as a pair of strings.

◆ get() [2/3]

template<typename T >
T mqtt::get ( const properties props,
property::code  propid,
size_t  idx 
)
inline

Retrieves a single value from a property list for when there may be multiple identical property ID's.

Template Parameters
TThe type of the value to retrieve
Parameters
propsThe property list
propidThe property ID code for the desired value.
idxIndex of the desired property ID
Returns
The requested value of type T

◆ get() [3/3]

template<typename T >
T mqtt::get ( const properties props,
property::code  propid 
)
inline

Retrieves a single value from a property list.

Template Parameters
TThe type of the value to retrieve
Parameters
propsThe property list
propidThe property ID code for the desired value.
Returns
The requested value of type T

◆ to_string() [1/2]

std::string mqtt::to_string ( ReasonCode  reasonCode)

Get the string representation of the reason code.

Parameters
reasonCodeAn MQTT v5 reason code.
Returns
The string representation of the reason code.

◆ operator<<() [5/5]

std::ostream & mqtt::operator<< ( std::ostream &  os,
ReasonCode  reasonCode 
)

ostream inserter for reason codes

Parameters
osThe output stream
reasonCodeThe reason code.
Returns
Reference to the output stream

◆ to_seconds()

template<class Rep , class Period >
std::chrono::seconds mqtt::to_seconds ( const std::chrono::duration< Rep, Period > &  dur)

Convert a chrono duration to seconds. This casts away precision to get integer seconds.

Parameters
durA chrono duration type
Returns
The duration as a chrono seconds value

◆ to_seconds_count()

template<class Rep , class Period >
long mqtt::to_seconds_count ( const std::chrono::duration< Rep, Period > &  dur)

Convert a chrono duration to a number of seconds. This casts away precision to get integer seconds.

Parameters
durA chrono duration type
Returns
The duration as a number of seconds

◆ to_milliseconds()

template<class Rep , class Period >
std::chrono::milliseconds mqtt::to_milliseconds ( const std::chrono::duration< Rep, Period > &  dur)

Convert a chrono duration to milliseconds. This casts away precision to get integer milliseconds.

Parameters
durA chrono duration type
Returns
The duration as a chrono milliseconds value

◆ to_milliseconds_count()

template<class Rep , class Period >
long mqtt::to_milliseconds_count ( const std::chrono::duration< Rep, Period > &  dur)

Convert a chrono duration to a number of milliseconds. This casts away precision to get integer milliseconds.

Parameters
durA chrono duration type
Returns
The duration as a number of milliseconds

◆ to_bool()

bool mqtt::to_bool ( int  n)
inline

Converts an into to a bool.

Parameters
nAn integer.
Returns
true if n not equal to zero, false otherwise

◆ to_int()

int mqtt::to_int ( bool  b)
inline

Converts the boolean into a C integer true/false value.

Parameters
bA boolean
Returns
Zero if b is false, non-zero if b is true.

◆ to_string() [2/2]

string mqtt::to_string ( const char *  cstr)
inline

Gets a valid string for the char pointer, returning an empty string if the pointer is NULL.

Parameters
cstrA C-string pointer
Returns
A string copy of the C array. If cstr is NULL, this returns an empty string.

Variable Documentation

◆ VERSION

const uint32_t mqtt::VERSION = 0x01050002

The version number for the client library.

◆ NO_PERSISTENCE

constexpr no_persistence mqtt::NO_PERSISTENCE {}
constexpr

A constant used to indicate that no persistence is desired