AWS IoT C++ SDK
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Data Fields | Protected Attributes
awsiotsdk::mqtt::Subscription Class Reference

MQTT Subscription Definition. More...

#include <Common.hpp>

Public Types

typedef std::function< ResponseCode(util::String topic_name, util::String payload, std::shared_ptr< SubscriptionHandlerContextData > p_app_handler_data)> ApplicationCallbackHandlerPtr
 Define handler for Application Callbacks. More...
 

Public Member Functions

 Subscription (const Subscription &)=default
 
 Subscription (Subscription &&)=default
 
Subscriptionoperator= (const Subscription &) &=default
 
Subscriptionoperator= (Subscription &&) &=default
 
 Subscription (std::unique_ptr< Utf8String > p_topic_name, QoS max_qos, ApplicationCallbackHandlerPtr p_app_handler, std::shared_ptr< SubscriptionHandlerContextData > p_app_handler_data)
 Constructor. More...
 
bool IsActive ()
 Is Subscription Active? More...
 
void SetActive (bool value)
 Set Subscription status. More...
 
uint16_t GetPacketId ()
 Get Packet ID for this subscription's Subscribe request. More...
 
void SetAckIndex (uint16_t packet_id, uint8_t index_in_packet)
 Set expected index of Ack for this Subscription in the SUBACK packet. More...
 
QoS GetMaxQos ()
 Get Max QoS for this subscription. More...
 
void SetMaxQos (mqtt::QoS max_qos)
 Set Max QoS for this subscription. More...
 
size_t GetTopicNameLength ()
 Get Length of topic name for this subscription. More...
 
std::shared_ptr< Utf8StringGetTopicName ()
 Get Topic Name. More...
 
bool IsInSuback (uint16_t packet_id, uint8_t index_in_packet)
 Is this subscription in the Suback with given packet ID and index. More...
 

Static Public Member Functions

static std::shared_ptr< SubscriptionCreate (std::unique_ptr< Utf8String > p_topic_name, QoS max_qos, ApplicationCallbackHandlerPtr p_app_handler, std::shared_ptr< SubscriptionHandlerContextData > p_app_handler_data)
 Factory method to create a Subscription instance. More...
 
static bool IsValidTopicName (util::String p_topic_name)
 Is the Topic Name Valid? More...
 

Data Fields

ApplicationCallbackHandlerPtr p_app_handler_
 Pointer to the Application Handler.
 
std::shared_ptr< SubscriptionHandlerContextDatap_app_handler_data_
 Data to be passed to the Application Handler.
 
util::String p_topic_regex_
 Topic regex string which is used if the topic is a wildcard topic.
 

Protected Attributes

bool is_active_
 Boolean indicating weather the subscription is active or not.
 
uint16_t packet_id_
 Packet Id of the Subscribe/Unsubscribe Packet.
 
uint8_t index_in_packet_
 Index of the subscription in the Subscribe/Unsubscribe Packet.
 
QoS max_qos_
 Max QoS for messages on this subscription.
 
std::shared_ptr< Utf8Stringp_topic_name_
 Topic Name for this subscription.
 

Detailed Description

Defining a type for the MQTT Subscriptions Contains all information required to process a subscription including callback handler

Note
Also defines a type for the Application callback handler - Subscription::ApplicationCallbackHandlerPtr

Member Typedef Documentation

◆ ApplicationCallbackHandlerPtr

typedef std::function<ResponseCode(util::String topic_name, util::String payload, std::shared_ptr<SubscriptionHandlerContextData> p_app_handler_data)> awsiotsdk::mqtt::Subscription::ApplicationCallbackHandlerPtr

This handler is used to provide notification to the application when a message is received on a subscribed topic

Constructor & Destructor Documentation

◆ Subscription()

awsiotsdk::mqtt::Subscription::Subscription ( std::unique_ptr< Utf8String p_topic_name,
QoS  max_qos,
ApplicationCallbackHandlerPtr  p_app_handler,
std::shared_ptr< SubscriptionHandlerContextData p_app_handler_data 
)
Parameters
p_topic_name- Topic name for this subscription
max_qos- Max QoS
p_app_handler- Application Handler instance
p_app_handler_data- Data to be passed to application handler. Can be nullptr

Member Function Documentation

◆ Create()

std::shared_ptr< Subscription > awsiotsdk::mqtt::Subscription::Create ( std::unique_ptr< Utf8String p_topic_name,
QoS  max_qos,
ApplicationCallbackHandlerPtr  p_app_handler,
std::shared_ptr< SubscriptionHandlerContextData p_app_handler_data 
)
static
Parameters
p_topic_name- Topic name for this subscription
max_qos- Max QoS
p_app_handler- Application Handler instance
p_app_handler_data- Data to be passed to application handler. Can be nullptr
Returns
shared_ptr Subscription instance

◆ GetMaxQos()

QoS awsiotsdk::mqtt::Subscription::GetMaxQos ( )
inline
Returns
QoS value

◆ GetPacketId()

uint16_t awsiotsdk::mqtt::Subscription::GetPacketId ( )
inline
Returns
uint16_t ID of the packet

◆ GetTopicName()

std::shared_ptr< Utf8String > awsiotsdk::mqtt::Subscription::GetTopicName ( )
inline
Returns
shared_ptr to a Utf8String containing topic name

◆ GetTopicNameLength()

size_t awsiotsdk::mqtt::Subscription::GetTopicNameLength ( )
inline
Returns
size_t Length

◆ IsActive()

bool awsiotsdk::mqtt::Subscription::IsActive ( )
inline
Returns
boolean indicating whether the subscription is active

◆ IsInSuback()

bool awsiotsdk::mqtt::Subscription::IsInSuback ( uint16_t  packet_id,
uint8_t  index_in_packet 
)
inline
Parameters
packet_id- Packet ID of received SUBACK
index_in_packet- Index in SUBACK
Returns
boolean indicating whether this Subscription was the target for the received SUBACK

◆ IsValidTopicName()

bool awsiotsdk::mqtt::Subscription::IsValidTopicName ( util::String  p_topic_name)
static
Returns
boolean indicating whether the topic is a valid topic

◆ SetAckIndex()

void awsiotsdk::mqtt::Subscription::SetAckIndex ( uint16_t  packet_id,
uint8_t  index_in_packet 
)
inline
Parameters
packet_id- Expected packet id
index_in_packet- Expected Index in packet

◆ SetActive()

void awsiotsdk::mqtt::Subscription::SetActive ( bool  value)
inline
Parameters
value- boolean value indicating target status

◆ SetMaxQos()

void awsiotsdk::mqtt::Subscription::SetMaxQos ( mqtt::QoS  max_qos)
inline
Parameters
max_qosTarget QoS value