Paho C++  1.0
The Paho MQTT C++ Client Library
 All Classes Files Functions Variables Typedefs Friends
mqtt::token Class Reference

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

#include <token.h>

Inheritance diagram for mqtt::token:
mqtt::delivery_token

Public Types

using ptr_t = std::shared_ptr< token >
 Smart/shared pointer to an object of this class.
 
using const_ptr_t = std::shared_ptr< const token >
 Smart/shared pointer to an object of this class.
 
using weak_ptr_t = std::weak_ptr< token >
 Weak pointer to an object of this class.
 

Public Member Functions

 token (iasync_client &cli)
 Constructs a token object. More...
 
 token (iasync_client &cli, void *userContext, iaction_listener &cb)
 Constructs a token object. More...
 
 token (iasync_client &cli, const string &topic)
 Constructs a token object. More...
 
 token (iasync_client &cli, const string &topic, void *userContext, iaction_listener &cb)
 Constructs a token object. More...
 
 token (iasync_client &cli, const_string_collection_ptr topics)
 Constructs a token object. More...
 
 token (iasync_client &cli, const_string_collection_ptr topics, void *userContext, iaction_listener &cb)
 Constructs a token object. More...
 
 token (iasync_client &cli, MQTTAsync_token tok)
 Constructs a token object. More...
 
virtual ~token ()
 Virtual destructor.
 
virtual iaction_listenerget_action_callback () const
 Gets the action listener for this token. More...
 
virtual iasync_clientget_client () const
 Returns the MQTT client that is responsible for processing the asynchronous action. More...
 
virtual int get_message_id () const
 Returns the ID of the message that is associated with the token. More...
 
virtual const_string_collection_ptr get_topics () const
 Gets the topic string(s) for the action being tracked by this token. More...
 
virtual void * get_user_context () const
 Retrieve the context associated with an action. More...
 
virtual bool is_complete () const
 Returns whether or not the action has finished. More...
 
virtual int get_return_code () const
 Gets the return code from the action. More...
 
virtual void set_action_callback (iaction_listener &listener)
 Register a listener to be notified when an action completes. More...
 
virtual void set_user_context (void *userContext)
 Store some context associated with an action. More...
 
virtual void wait ()
 Blocks the current thread until the action this token is associated with has completed.
 
virtual bool try_wait ()
 Non-blocking check to see if the action has completed. More...
 
virtual bool wait_for (long timeout)
 Blocks the current thread until the action this token is associated with has completed. More...
 
template<class Rep , class Period >
bool wait_for (const std::chrono::duration< Rep, Period > &relTime)
 Waits a relative amount of time for the action to complete. More...
 
template<class Clock , class Duration >
bool wait_until (const std::chrono::time_point< Clock, Duration > &absTime)
 Waits until an absolute time for the action to complete. More...
 

Static Public Member Functions

static ptr_t create (iasync_client &cli)
 Constructs a token object. More...
 
static ptr_t create (iasync_client &cli, void *userContext, iaction_listener &cb)
 Constructs a token object. More...
 
static ptr_t create (iasync_client &cli, const string &topic)
 Constructs a token object. More...
 
static ptr_t create (iasync_client &cli, const string &topic, void *userContext, iaction_listener &cb)
 Constructs a token object. More...
 
static ptr_t create (iasync_client &cli, const_string_collection_ptr topics)
 Constructs a token object. More...
 
static ptr_t create (iasync_client &cli, const_string_collection_ptr topics, void *userContext, iaction_listener &cb)
 Constructs a token object. More...
 

Friends

class async_client
 Client and token-related options have special access.
 
class token_test
 
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.

Constructor & Destructor Documentation

mqtt::token::token ( iasync_client cli)

Constructs a token object.

Parameters
cliThe client that created the token.
mqtt::token::token ( iasync_client cli,
void *  userContext,
iaction_listener cb 
)

Constructs a token object.

Parameters
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
mqtt::token::token ( iasync_client cli,
const string &  topic 
)

Constructs a token object.

Parameters
cliThe client that created the token.
topicThe topic assiciated with the token
mqtt::token::token ( iasync_client cli,
const string &  topic,
void *  userContext,
iaction_listener cb 
)

Constructs a token object.

Parameters
cliThe client that created the token.
topicThe topic assiciated 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
mqtt::token::token ( iasync_client cli,
const_string_collection_ptr  topics 
)

Constructs a token object.

Parameters
cliThe client that created the token.
topicsThe topics associated with the token
mqtt::token::token ( iasync_client cli,
const_string_collection_ptr  topics,
void *  userContext,
iaction_listener cb 
)

Constructs a token object.

Parameters
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
mqtt::token::token ( iasync_client cli,
MQTTAsync_token  tok 
)

Constructs a token object.

Parameters
cliThe client that created the token.
tokThe message ID

Member Function Documentation

static ptr_t mqtt::token::create ( iasync_client cli)
inlinestatic

Constructs a token object.

Parameters
cliThe client that created the token.
Returns
A smart/shared pointer to a token.
static ptr_t mqtt::token::create ( iasync_client cli,
void *  userContext,
iaction_listener cb 
)
inlinestatic

Constructs a token object.

Parameters
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
static ptr_t mqtt::token::create ( iasync_client cli,
const string &  topic 
)
inlinestatic

Constructs a token object.

Parameters
cliThe client that created the token.
topicThe topic assiciated with the token
static ptr_t mqtt::token::create ( iasync_client cli,
const string &  topic,
void *  userContext,
iaction_listener cb 
)
inlinestatic

Constructs a token object.

Parameters
cliThe client that created the token.
topicThe topic assiciated 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
static ptr_t mqtt::token::create ( iasync_client cli,
const_string_collection_ptr  topics 
)
inlinestatic

Constructs a token object.

Parameters
cliThe client that created the token.
topicsThe topics associated with the token
static ptr_t mqtt::token::create ( iasync_client cli,
const_string_collection_ptr  topics,
void *  userContext,
iaction_listener cb 
)
inlinestatic

Constructs a token object.

Parameters
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
virtual iaction_listener* mqtt::token::get_action_callback ( ) const
inlinevirtual

Gets the action listener for this token.

Returns
The action listener for this token.
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.
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.
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.
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.
virtual void* mqtt::token::get_user_context ( ) const
inlinevirtual

Retrieve the context associated with an action.

Returns
The context associated with an action.
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.
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.
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.
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.
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.
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.
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.

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