Loading...
Searching...
No Matches
mqtt::token Class Reference

`#include <token.h>`

Inheritance diagram for mqtt::token:

## Public Types

enum | Type { CONNECT , SUBSCRIBE , PUBLISH , UNSUBSCRIBE , DISCONNECT }
using | ptr_t = std::shared_ptr<token>
using | const_ptr_t = std::shared_ptr<const token>
using | weak_ptr_t = std::weak_ptr<token>

## Public Member Functions

| token (Type typ, iasync_client &cli)
| token (Type typ, iasync_client &cli, void *userContext, iaction_listener &cb)
| token (Type typ, iasync_client &cli, const string &topic)
| token (Type typ, iasync_client &cli, const string &topic, void *userContext, iaction_listener &cb)
| token (Type typ, iasync_client &cli, const_string_collection_ptr topics)
| token (Type typ, iasync_client &cli, const_string_collection_ptr topics, void *userContext, iaction_listener &cb)
| token (Type typ, iasync_client &cli, MQTTAsync_token tok)
virtual | ~token ()
Type | get_type () const
virtual iaction_listener * | get_action_callback () const
virtual iasync_client * | get_client () const
virtual int | get_message_id () const
virtual const_string_collection_ptr | get_topics () const
virtual void * | get_user_context () const
virtual bool | is_complete () const
| operator bool () const
virtual int | get_return_code () const
virtual void | set_action_callback (iaction_listener &listener)
virtual void | set_user_context (void *userContext)
void | set_num_expected (size_t n)
ReasonCode | get_reason_code () const
string | get_error_message () const
virtual void | wait ()
virtual bool | try_wait ()
virtual bool | wait_for (long timeout)
template<class Rep, class Period>
bool | wait_for (const std::chrono::duration< Rep, Period > &relTime)
template<class Clock, class Duration>
bool | wait_until (const std::chrono::time_point< Clock, Duration > &absTime)
connect_response | get_connect_response () const
subscribe_response | get_subscribe_response () const
unsubscribe_response | get_unsubscribe_response () const

## Static Public Member Functions

static ptr_t | create (Type typ, iasync_client &cli)
static ptr_t | create (Type typ, iasync_client &cli, void *userContext, iaction_listener &cb)
static ptr_t | create (Type typ, iasync_client &cli, const string &topic)
static ptr_t | create (Type typ, iasync_client &cli, const string &topic, void *userContext, iaction_listener &cb)
static ptr_t | create (Type typ, iasync_client &cli, const_string_collection_ptr topics)
static ptr_t | create (Type typ, iasync_client &cli, const_string_collection_ptr topics, void *userContext, iaction_listener &cb)

## Friends

class | async_client
class | mock_async_client
class | connect_options
class | response_options
class | delivery_response_options
class | disconnect_options

## Detailed Description

Provides a mechanism for tracking the completion of an asynchronous action.

## Member Typedef Documentation

## ptr_t

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

Smart/shared pointer to an object of this class

## const_ptr_t

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

Smart/shared pointer to an object of this class

## weak_ptr_t

using mqtt::token::weak_ptr_t = std::weak_ptr<token>

Weak pointer to an object of this class

## Member Enumeration Documentation

## Type

enum mqtt::token::Type

The type of request that the token is tracking

Enumerator
CONNECT |
SUBSCRIBE |
PUBLISH |
UNSUBSCRIBE |
DISCONNECT |

## Constructor & Destructor Documentation

## token() [1/7]

mqtt::token::token | ( | Type | typ,
|  | iasync_client & | cli )

inline

Constructs a token object.

Parameters

  typ | The type of request that the token is tracking.
  cli | The client that created the token.

## token() [2/7]

mqtt::token::token | ( | Type | typ,
|  | iasync_client & | cli,
|  | void * | userContext,
|  | iaction_listener & | cb )

inline

Constructs a token object.

Parameters

  typ | The type of request that the token is tracking.
  cli | The client that created the token.
  userContext | optional object used to pass context to the callback. Use nullptr if not required.
  cb | callback listener that will be notified when subscribe has completed

## token() [3/7]

mqtt::token::token | ( | Type | typ,
|  | iasync_client & | cli,
|  | const string & | topic )

inline

Constructs a token object.

Parameters

  typ | The type of request that the token is tracking.
  cli | The client that created the token.
  topic | The topic associated with the token

## token() [4/7]

mqtt::token::token | ( | Type | typ,
|  | iasync_client & | cli,
|  | const string & | topic,
|  | void * | userContext,
|  | iaction_listener & | cb )

inline

Constructs a token object.

Parameters

  typ | The type of request that the token is tracking.
  cli | The client that created the token.
  topic | The topic associated with the token
  userContext | optional object used to pass context to the callback. Use nullptr if not required.
  cb | callback listener that will be notified when subscribe has completed

## token() [5/7]

mqtt::token::token | ( | Type | typ,
|  | iasync_client & | cli,
|  | const_string_collection_ptr | topics )

Constructs a token object.

Parameters

  typ | The type of request that the token is tracking.
  cli | The client that created the token.
  topics | The topics associated with the token

## token() [6/7]

mqtt::token::token | ( | Type | typ,
|  | iasync_client & | cli,
|  | const_string_collection_ptr | topics,
|  | void * | userContext,
|  | iaction_listener & | cb )

Constructs a token object.

Parameters

  typ | The type of request that the token is tracking.
  cli | The client that created the token.
  topics | The topics associated with the token
  userContext | optional object used to pass context to the callback. Use nullptr if not required.
  cb | callback listener that will be notified when subscribe has completed

## token() [7/7]

mqtt::token::token | ( | Type | typ,
|  | iasync_client & | cli,
|  | MQTTAsync_token | tok )

Constructs a token object.

Parameters

  typ | The type of request that the token is tracking.
  cli | The client that created the token.
  tok | The message ID

## ~token()

virtual mqtt::token::~token | ( |  | ) |

inline virtual

Virtual destructor.

## Member Function Documentation

## create() [1/6]

ptr_t mqtt::token::create | ( | Type | typ,
|  | iasync_client & | cli )

inline static

Constructs a token object.

Parameters

  typ | The type of request that the token is tracking.
  cli | The client that created the token.

Returns
  A smart/shared pointer to a token.

## create() [2/6]

ptr_t mqtt::token::create | ( | Type | typ,
|  | iasync_client & | cli,
|  | void * | userContext,
|  | iaction_listener & | cb )

inline static

Constructs a token object.

Parameters

  typ | The type of request that the token is tracking.
  cli | The client that created the token.
  userContext | optional object used to pass context to the callback. Use nullptr if not required.
  cb | callback listener that will be notified when subscribe has completed

## create() [3/6]

ptr_t mqtt::token::create | ( | Type | typ,
|  | iasync_client & | cli,
|  | const string & | topic )

inline static

Constructs a token object.

Parameters

  typ | The type of request that the token is tracking.
  cli | The client that created the token.
  topic | The topic associated with the token

## create() [4/6]

ptr_t mqtt::token::create | ( | Type | typ,
|  | iasync_client & | cli,
|  | const string & | topic,
|  | void * | userContext,
|  | iaction_listener & | cb )

inline static

Constructs a token object.

Parameters

  typ | The type of request that the token is tracking.
  cli | The client that created the token.
  topic | The topic associated with the token
  userContext | optional object used to pass context to the callback. Use nullptr if not required.
  cb | callback listener that will be notified when subscribe has completed

## create() [5/6]

ptr_t mqtt::token::create | ( | Type | typ,
|  | iasync_client & | cli,
|  | const_string_collection_ptr | topics )

inline static

Constructs a token object.

Parameters

  typ | The type of request that the token is tracking.
  cli | The client that created the token.
  topics | The topics associated with the token

## create() [6/6]

ptr_t mqtt::token::create | ( | Type | typ,
|  | iasync_client & | cli,
|  | const_string_collection_ptr | topics,
|  | void * | userContext,
|  | iaction_listener & | cb )

inline static

Constructs a token object.

Parameters

  typ | The type of request that the token is tracking.
  cli | The client that created the token.
  topics | The topics associated with the token
  userContext | optional object used to pass context to the callback. Use nullptr if not required.
  cb | callback listener that will be notified when subscribe has

## get_type()

Type mqtt::token::get_type | ( |  | ) | const

inline

Gets the type of request the token is tracking, like CONNECT, PUBLISH, etc.

Returns
  The type of request that the token is tracking.

## get_action_callback()

virtual iaction_listener * mqtt::token::get_action_callback | ( |  | ) | const

inline virtual

Gets the action listener for this token.

Returns
  The action listener for this token.

## get_client()

virtual iasync_client * mqtt::token::get_client | ( |  | ) | const

inline virtual

Returns the MQTT client that is responsible for processing the asynchronous action.

Returns
  The client to which this token is connected.

## get_message_id()

virtual int mqtt::token::get_message_id | ( |  | ) | const

inline virtual

Returns the ID of the message that is associated with the token.

Returns
  The message ID of the transaction being tracked.

## get_topics()

virtual const_string_collection_ptr mqtt::token::get_topics | ( |  | ) | const

inline virtual

Gets the topic string(s) for the action being tracked by this token.

Returns
  A const pointer to the collection of topics being tracked by the token.

## get_user_context()

virtual void * mqtt::token::get_user_context | ( |  | ) | const

inline virtual

Retrieve the context associated with an action.

Returns
  The context associated with an action.

## is_complete()

virtual bool mqtt::token::is_complete | ( |  | ) | const

inline virtual

Returns whether or not the action has finished.

Returns
  true if the transaction has completed, false if not.

## operator bool()

mqtt::token::operator bool | ( |  | ) | const

inline explicit

Determines if the reference is valid. If the reference is invalid then it is not safe to call any member functions other than is_null() and empty()

Returns
  true if referring to a valid buffer, false if the reference (pointer) is null.

## get_return_code()

virtual int mqtt::token::get_return_code | ( |  | ) | const

inline virtual

Gets the return code from the action. This is only valid after the action has completed (i.e. if is_complete() returns true).

Returns
  The return code from the action.

## set_action_callback()

virtual void mqtt::token::set_action_callback | ( | iaction_listener & | listener | ) |

virtual

Register a listener to be notified when an action completes.

Parameters

  listener | The callback to be notified when actions complete.

## set_user_context()

virtual void mqtt::token::set_user_context | ( | void * | userContext | ) |

inline virtual

Store some context associated with an action.

Parameters

  userContext | optional object used to pass context to the callback. Use nullptr if not required.

## set_num_expected()

void mqtt::token::set_num_expected | ( | size_t | n | ) |

inline

Sets the number of results expected. This is only required for subscribe many() with < MQTTv5

Parameters

  n | The number of results expected.

## get_reason_code()

ReasonCode mqtt::token::get_reason_code | ( |  | ) | const

inline

Gets the reason code for the operation.

Returns
  The reason code for the operation.

## get_error_message()

string mqtt::token::get_error_message | ( |  | ) | const

inline

Get the error message from the C library

Returns
  Error message for the operation

## wait()

virtual void mqtt::token::wait | ( |  | ) |

virtual

Blocks the current thread until the action this token is associated with has completed.

## try_wait()

virtual bool mqtt::token::try_wait | ( |  | ) |

inline virtual

Non-blocking check to see if the action has completed.

Returns
  true if the wait finished successfully, false if the action has not completed yet.

## wait_for() [1/2]

virtual bool mqtt::token::wait_for | ( | long | timeout | ) |

inline virtual

Blocks the current thread until the action this token is associated with has completed.

Parameters

  timeout | The timeout (in milliseconds)

Returns
  true if the wait finished successfully, false if a timeout occurred.

## wait_for() [2/2]

template<class Rep, class Period>

bool mqtt::token::wait_for | ( | const std::chrono::duration< Rep, Period > & | relTime | ) |

inline

Waits a relative amount of time for the action to complete.

Parameters

  relTime | The amount of time to wait for the event.

Returns
  true if the event gets signaled in the specified time, false on a timeout.

## wait_until()

template<class Clock, class Duration>

bool mqtt::token::wait_until | ( | const std::chrono::time_point< Clock, Duration > & | absTime | ) |

inline

Waits until an absolute time for the action to complete.

Parameters

  absTime | The absolute time to wait for the event.

Returns
  true if the event gets signaled in the specified time, false on a timeout.

## get_connect_response()

connect_response mqtt::token::get_connect_response | ( |  | ) | const

Gets the response from a connect operation. This returns the result of the completed operation. If the operation is not yet complete this will block until the result is available.

Returns
  The result of the operation.

## get_subscribe_response()

subscribe_response mqtt::token::get_subscribe_response | ( |  | ) | const

Gets the response from a connect operation. This returns the result of the completed operation. If the operation is not yet complete this will block until the result is available.

Returns
  The result of the operation.

## get_unsubscribe_response()

unsubscribe_response mqtt::token::get_unsubscribe_response | ( |  | ) | const

Gets the response from a connect operation. This returns the result of the completed operation. If the operation is not yet complete this will block until the result is available.

Returns
  The result of the operation.

## Friends And Related Symbol Documentation

## async_client

friend class async_client

friend

Client and token-related options have special access

## mock_async_client

friend class mock_async_client

friend

## connect_options

friend class connect_options

friend

## response_options

friend class response_options

friend

## delivery_response_options

friend class delivery_response_options

friend

## disconnect_options

friend class disconnect_options

friend

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

- token.h