Loading...
Searching...
No Matches
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_client & | get_client ()
const string & | get_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.

This is primarily a convenience class for publishing multiple messages to the same topic. It holds all the parameters for publishing the message other than the payload: topic, QoS, and retain flag. Each publish operation then only needs to supply the payload.

It can also be used to subscribe to the specific topic, but this is not the normal use case.

## 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

  cli | Client to which the topic is attached
  name | The topic string
  qos | The default QoS for publishing.
  retained | The default retained flag for the topic.

## Member Function Documentation

## create()

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

inline static

Creates a new topic.

Parameters

  cli | Client to which the topic is attached
  name | The topic string
  qos | The default QoS for publishing.
  retained | The 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()

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

static

Splits a topic string into individual fields.

Parameters

  topic | A 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

  qos | The 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

  retained | The 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

  payload | the bytes to use as the message payload
  n | the 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

  payload | the bytes to use as the message payload
  n | the number of bytes in the payload
  qos | the Quality of Service to deliver the message at. Valid values are 0, 1 or 2.
  retained | whether 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

  payload | the 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

  payload | the bytes to use as the message payload
  qos | the Quality of Service to deliver the message at. Valid values are 0, 1 or 2.
  retained | whether 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:

- topic.h