paho-mqtt-cpp
MQTT C++ Client for POSIX and Windows
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions
mqtt::topic Class Reference

#include <topic.h>

Public Types

using ptr_t = std::shared_ptr< topic >
 
using const_ptr_t = std::shared_ptr< const topic >
 

Public Member Functions

 topic (iasync_client &cli, const string &name, int qos=message::DFLT_QOS, bool retained=message::DFLT_RETAINED)
 
iasync_clientget_client ()
 
const stringget_name () const
 
int get_qos () const
 
bool get_retained () const
 
void set_qos (int qos)
 
void set_retained (bool retained)
 
delivery_token_ptr publish (const void *payload, size_t n)
 
delivery_token_ptr publish (const void *payload, size_t n, int qos, bool retained)
 
delivery_token_ptr publish (binary_ref payload)
 
delivery_token_ptr publish (binary_ref payload, int qos, bool retained)
 
token_ptr subscribe (const subscribe_options &opts=subscribe_options())
 
string to_string () const
 

Static Public Member Functions

static ptr_t create (iasync_client &cli, const string &name, int qos=message::DFLT_QOS, bool retained=message::DFLT_RETAINED)
 
static std::vector< std::string > split (const std::string &topic)
 

Detailed Description

Represents a topic destination, used for publish/subscribe messaging.

Member Typedef Documentation

◆ ptr_t

using mqtt::topic::ptr_t = std::shared_ptr<topic>

A smart/shared pointer to this class.

◆ const_ptr_t

using mqtt::topic::const_ptr_t = std::shared_ptr<const topic>

A smart/shared pointer to this class.

Constructor & Destructor Documentation

◆ topic()

mqtt::topic::topic ( iasync_client cli,
const string name,
int  qos = message::DFLT_QOS,
bool  retained = message::DFLT_RETAINED 
)
inline

Construct an MQTT topic destination for messages.

Parameters
cliClient to which the topic is attached
nameThe topic string
qosThe default QoS for publishing.
retainedThe default retained flag for the topic.

Member Function Documentation

◆ create()

static ptr_t mqtt::topic::create ( iasync_client cli,
const string name,
int  qos = message::DFLT_QOS,
bool  retained = message::DFLT_RETAINED 
)
inlinestatic

Creates a new topic

Parameters
cliClient to which the topic is attached
nameThe topic string
qosThe default QoS for publishing.
retainedThe default retained flag for the topic.
Returns
A shared pointer to the topic.

◆ get_client()

iasync_client & mqtt::topic::get_client ( )
inline

Gets a reference to the MQTT client used by this topic

Returns
The MQTT client used by this topic

◆ get_name()

const string & mqtt::topic::get_name ( ) const
inline

Gets the name of the topic.

Returns
The name of the topic.

◆ split()

static std::vector< std::string > mqtt::topic::split ( const std::string &  topic)
static

Splits a topic string into individual fields.

Parameters
topicA slash-delimited MQTT topic string.
Returns
A vector containing the fields of the topic.

◆ get_qos()

int mqtt::topic::get_qos ( ) const
inline

Gets the default quality of service for this topic.

Returns
The default quality of service for this topic.

◆ get_retained()

bool mqtt::topic::get_retained ( ) const
inline

Gets the default retained flag used for this topic.

Returns
The default retained flag used for this topic.

◆ set_qos()

void mqtt::topic::set_qos ( int  qos)
inline

Sets the default quality of service for this topic.

Parameters
qosThe default quality of service for this topic.

◆ set_retained()

void mqtt::topic::set_retained ( bool  retained)
inline

Sets the default retained flag used for this topic.

Parameters
retainedThe default retained flag used for this topic.

◆ publish() [1/4]

delivery_token_ptr mqtt::topic::publish ( const void *  payload,
size_t  n 
)

Publishes a message on the topic using the default QoS and retained flag.

Parameters
payloadthe bytes to use as the message payload
nthe number of bytes in the payload
Returns
The delivery token used to track and wait for the publish to complete.

◆ publish() [2/4]

delivery_token_ptr mqtt::topic::publish ( const void *  payload,
size_t  n,
int  qos,
bool  retained 
)

Publishes a message on the topic.

Parameters
payloadthe bytes to use as the message payload
nthe number of bytes in the payload
qosthe Quality of Service to deliver the message at. Valid values are 0, 1 or 2.
retainedwhether or not this message should be retained by the server.
Returns
The delivery token used to track and wait for the publish to complete.

◆ publish() [3/4]

delivery_token_ptr mqtt::topic::publish ( binary_ref  payload)

Publishes a message on the topic using the default QoS and retained flag.

Parameters
payloadthe bytes to use as the message payload
Returns
The delivery token used to track and wait for the publish to complete.

◆ publish() [4/4]

delivery_token_ptr mqtt::topic::publish ( binary_ref  payload,
int  qos,
bool  retained 
)

Publishes a message on the topic.

Parameters
payloadthe bytes to use as the message payload
qosthe Quality of Service to deliver the message at. Valid values are 0, 1 or 2.
retainedwhether or not this message should be retained by the server.
Returns
The delivery token used to track and wait for the publish to complete.

◆ subscribe()

token_ptr mqtt::topic::subscribe ( const subscribe_options opts = subscribe_options())

Subscribe to the topic.

Returns
A token used to track the progress of the operation.

◆ to_string()

string mqtt::topic::to_string ( ) const
inline

Returns a string representation of this topic.

Returns
The name of the topic

The documentation for this class was generated from the following file: