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

#include <token.h>

Inheritance diagram for mqtt::token:
mqtt::delivery_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_listenerget_action_callback () const
 
virtual iasync_clientget_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
 
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
 
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

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
typThe type of request that the token is tracking.
cliThe 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
typThe type of request that the token is tracking.
cliThe client that created the token.
userContextoptional object used to pass context to the callback. Use nullptr if not required.
cbcallback 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
typThe type of request that the token is tracking.
cliThe client that created the token.
topicThe 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
typThe type of request that the token is tracking.
cliThe client that created the token.
topicThe topic associated with the token
userContextoptional object used to pass context to the callback. Use nullptr if not required.
cbcallback 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
typThe type of request that the token is tracking.
cliThe client that created the token.
topicsThe 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
typThe type of request that the token is tracking.
cliThe client that created the token.
topicsThe topics associated with the token
userContextoptional object used to pass context to the callback. Use nullptr if not required.
cbcallback 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
typThe type of request that the token is tracking.
cliThe client that created the token.
tokThe message ID

◆ ~token()

virtual mqtt::token::~token ( )
inlinevirtual

Virtual destructor.

Member Function Documentation

◆ create() [1/6]

static ptr_t mqtt::token::create ( Type  typ,
iasync_client cli 
)
inlinestatic

Constructs a token object.

Parameters
typThe type of request that the token is tracking.
cliThe client that created the token.
Returns
A smart/shared pointer to a token.

◆ create() [2/6]

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

Constructs a token object.

Parameters
typThe type of request that the token is tracking.
cliThe client that created the token.
userContextoptional object used to pass context to the callback. Use nullptr if not required.
cbcallback listener that will be notified when subscribe has completed

◆ create() [3/6]

static ptr_t mqtt::token::create ( Type  typ,
iasync_client cli,
const string topic 
)
inlinestatic

Constructs a token object.

Parameters
typThe type of request that the token is tracking.
cliThe client that created the token.
topicThe topic associated with the token

◆ create() [4/6]

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

Constructs a token object.

Parameters
typThe type of request that the token is tracking.
cliThe client that created the token.
topicThe topic associated with the token
userContextoptional object used to pass context to the callback. Use nullptr if not required.
cbcallback listener that will be notified when subscribe has completed

◆ create() [5/6]

static ptr_t mqtt::token::create ( Type  typ,
iasync_client cli,
const_string_collection_ptr  topics 
)
inlinestatic

Constructs a token object.

Parameters
typThe type of request that the token is tracking.
cliThe client that created the token.
topicsThe topics associated with the token

◆ create() [6/6]

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

Constructs a token object.

Parameters
typThe type of request that the token is tracking.
cliThe client that created the token.
topicsThe topics associated with the token
userContextoptional object used to pass context to the callback. Use nullptr if not required.
cbcallback 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
inlinevirtual

Gets the action listener for this token.

Returns
The action listener for this token.

◆ get_client()

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

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
inlinevirtual

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
inlinevirtual

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
inlinevirtual

Retrieve the context associated with an action.

Returns
The context associated with an action.

◆ is_complete()

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

Returns whether or not the action has finished.

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

◆ get_return_code()

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

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)
inlinevirtual

Register a listener to be notified when an action completes.

Parameters
listenerThe callback to be notified when actions complete.

◆ set_user_context()

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

Store some context associated with an action.

Parameters
userContextoptional 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
nThe number of results expected.

◆ get_reason_code()

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

Gets the properties for the operation.

Returns
A const reference to the properties for the operation Gets the reason code for the operation.
The reason code 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 ( )
inlinevirtual

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)
inlinevirtual

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

Parameters
timeoutThe 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
relTimeThe 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
absTimeThe 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 Function 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: