aws-crt-cpp
C++ wrapper around the aws-c-* libraries. Provides Cross-Platform Transport Protocols and SSL/TLS implementations for C++.
Public Member Functions | Public Attributes | Friends | List of all members
Aws::Crt::Mqtt::MqttConnection Class Referencefinal

#include <MqttClient.h>

Public Member Functions

 ~MqttConnection ()
 
 MqttConnection (const MqttConnection &)=delete
 
 MqttConnection (MqttConnection &&)=delete
 
MqttConnectionoperator= (const MqttConnection &)=delete
 
MqttConnectionoperator= (MqttConnection &&)=delete
 
 operator bool () const noexcept
 
int LastError () const noexcept
 
bool SetWill (const char *topic, QOS qos, bool retain, const ByteBuf &payload) noexcept
 
bool SetLogin (const char *userName, const char *password) noexcept
 
bool SetWebsocketProxyOptions (const Http::HttpClientConnectionProxyOptions &proxyOptions) noexcept
 
bool SetHttpProxyOptions (const Http::HttpClientConnectionProxyOptions &proxyOptions) noexcept
 
bool SetReconnectTimeout (uint64_t min_seconds, uint64_t max_seconds) noexcept
 
bool Connect (const char *clientId, bool cleanSession, uint16_t keepAliveTimeSecs=0, uint32_t pingTimeoutMs=0, uint32_t protocolOperationTimeoutMs=0) noexcept
 
bool Disconnect () noexcept
 
aws_mqtt_client_connection * GetUnderlyingConnection () noexcept
 
uint16_t Subscribe (const char *topicFilter, QOS qos, OnMessageReceivedHandler &&onMessage, OnSubAckHandler &&onSubAck) noexcept
 
uint16_t Subscribe (const char *topicFilter, QOS qos, OnPublishReceivedHandler &&onPublish, OnSubAckHandler &&onSubAck) noexcept
 
uint16_t Subscribe (const Vector< std::pair< const char *, OnMessageReceivedHandler > > &topicFilters, QOS qos, OnMultiSubAckHandler &&onOpComplete) noexcept
 
uint16_t Subscribe (const Vector< std::pair< const char *, OnPublishReceivedHandler > > &topicFilters, QOS qos, OnMultiSubAckHandler &&onOpComplete) noexcept
 
bool SetOnMessageHandler (OnMessageReceivedHandler &&onMessage) noexcept
 
bool SetOnMessageHandler (OnPublishReceivedHandler &&onPublish) noexcept
 
uint16_t Unsubscribe (const char *topicFilter, OnOperationCompleteHandler &&onOpComplete) noexcept
 
uint16_t Publish (const char *topic, QOS qos, bool retain, const ByteBuf &payload, OnOperationCompleteHandler &&onOpComplete) noexcept
 

Public Attributes

OnConnectionInterruptedHandler OnConnectionInterrupted
 
OnConnectionResumedHandler OnConnectionResumed
 
OnConnectionCompletedHandler OnConnectionCompleted
 
OnDisconnectHandler OnDisconnect
 
OnWebSocketHandshakeIntercept WebsocketInterceptor
 

Friends

class MqttClient
 

Detailed Description

Represents a persistent Mqtt Connection. The memory is owned by MqttClient. To get a new instance of this class, see MqttClient::NewConnection. Unless specified all function arguments need only to live through the duration of the function call.

Constructor & Destructor Documentation

◆ ~MqttConnection()

Aws::Crt::Mqtt::MqttConnection::~MqttConnection ( )

◆ MqttConnection() [1/2]

Aws::Crt::Mqtt::MqttConnection::MqttConnection ( const MqttConnection )
delete

◆ MqttConnection() [2/2]

Aws::Crt::Mqtt::MqttConnection::MqttConnection ( MqttConnection &&  )
delete

Member Function Documentation

◆ Connect()

bool Aws::Crt::Mqtt::MqttConnection::Connect ( const char *  clientId,
bool  cleanSession,
uint16_t  keepAliveTimeSecs = 0,
uint32_t  pingTimeoutMs = 0,
uint32_t  protocolOperationTimeoutMs = 0 
)
noexcept

Initiates the connection, OnConnectionCompleted will be invoked in an event-loop thread.

◆ Disconnect()

bool Aws::Crt::Mqtt::MqttConnection::Disconnect ( )
noexcept

Initiates disconnect, OnDisconnectHandler will be invoked in an event-loop thread.

◆ GetUnderlyingConnection()

aws_mqtt_client_connection * Aws::Crt::Mqtt::MqttConnection::GetUnderlyingConnection ( )
noexcept
Returns
the pointer to the underlying mqtt connection

◆ LastError()

int Aws::Crt::Mqtt::MqttConnection::LastError ( ) const
noexcept
Returns
the value of the last aws error encountered by operations on this instance.

◆ operator bool()

Aws::Crt::Mqtt::MqttConnection::operator bool ( ) const
noexcept
Returns
true if the instance is in a valid state, false otherwise.

◆ operator=() [1/2]

MqttConnection & Aws::Crt::Mqtt::MqttConnection::operator= ( const MqttConnection )
delete

◆ operator=() [2/2]

MqttConnection & Aws::Crt::Mqtt::MqttConnection::operator= ( MqttConnection &&  )
delete

◆ Publish()

uint16_t Aws::Crt::Mqtt::MqttConnection::Publish ( const char *  topic,
QOS  qos,
bool  retain,
const ByteBuf payload,
OnOperationCompleteHandler &&  onOpComplete 
)
noexcept

Publishes to topic. The backing memory for payload must stay available until the OnOperationCompleteHandler has been invoked.

◆ SetHttpProxyOptions()

bool Aws::Crt::Mqtt::MqttConnection::SetHttpProxyOptions ( const Http::HttpClientConnectionProxyOptions proxyOptions)
noexcept

Sets http proxy options. In order to use an http proxy with mqtt either (1) Websockets are used (2) Mqtt-over-tls is used and the ALPN list of the tls context contains a tag that resolves to mqtt

◆ SetLogin()

bool Aws::Crt::Mqtt::MqttConnection::SetLogin ( const char *  userName,
const char *  password 
)
noexcept

Sets login credentials for the connection. The must get set before the Connect call if it is to be used.

◆ SetOnMessageHandler() [1/2]

bool Aws::Crt::Mqtt::MqttConnection::SetOnMessageHandler ( OnMessageReceivedHandler &&  onMessage)
noexcept

Installs a handler for all incoming publish messages, regardless of if Subscribe has been called on the topic.

◆ SetOnMessageHandler() [2/2]

bool Aws::Crt::Mqtt::MqttConnection::SetOnMessageHandler ( OnPublishReceivedHandler &&  onPublish)
noexcept

◆ SetReconnectTimeout()

bool Aws::Crt::Mqtt::MqttConnection::SetReconnectTimeout ( uint64_t  min_seconds,
uint64_t  max_seconds 
)
noexcept

Customize time to wait between reconnect attempts. The time will start at min and multiply by 2 until max is reached. The time resets back to min after a successful connection. This function should only be called before Connect().

◆ SetWebsocketProxyOptions()

bool Aws::Crt::Mqtt::MqttConnection::SetWebsocketProxyOptions ( const Http::HttpClientConnectionProxyOptions proxyOptions)
noexcept
Deprecated:
Sets websocket proxy options. Replaced by SetHttpProxyOptions.

◆ SetWill()

bool Aws::Crt::Mqtt::MqttConnection::SetWill ( const char *  topic,
QOS  qos,
bool  retain,
const ByteBuf payload 
)
noexcept

Sets LastWill for the connection. The memory backing payload must outlive the connection.

◆ Subscribe() [1/4]

uint16_t Aws::Crt::Mqtt::MqttConnection::Subscribe ( const char *  topicFilter,
QOS  qos,
OnMessageReceivedHandler &&  onMessage,
OnSubAckHandler &&  onSubAck 
)
noexcept

Subscribes to topicFilter. OnMessageReceivedHandler will be invoked from an event-loop thread upon an incoming Publish message. OnSubAckHandler will be invoked upon receipt of a suback message.

◆ Subscribe() [2/4]

uint16_t Aws::Crt::Mqtt::MqttConnection::Subscribe ( const char *  topicFilter,
QOS  qos,
OnPublishReceivedHandler &&  onPublish,
OnSubAckHandler &&  onSubAck 
)
noexcept
Deprecated:
Use alternate Subscribe()

◆ Subscribe() [3/4]

uint16_t Aws::Crt::Mqtt::MqttConnection::Subscribe ( const Vector< std::pair< const char *, OnMessageReceivedHandler > > &  topicFilters,
QOS  qos,
OnMultiSubAckHandler &&  onOpComplete 
)
noexcept

Subscribes to multiple topicFilters. OnMessageReceivedHandler will be invoked from an event-loop thread upon an incoming Publish message. OnMultiSubAckHandler will be invoked upon receipt of a suback message.

◆ Subscribe() [4/4]

uint16_t Aws::Crt::Mqtt::MqttConnection::Subscribe ( const Vector< std::pair< const char *, OnPublishReceivedHandler > > &  topicFilters,
QOS  qos,
OnMultiSubAckHandler &&  onOpComplete 
)
noexcept
Deprecated:
Use alternate Subscribe()

◆ Unsubscribe()

uint16_t Aws::Crt::Mqtt::MqttConnection::Unsubscribe ( const char *  topicFilter,
OnOperationCompleteHandler &&  onOpComplete 
)
noexcept

Unsubscribes from topicFilter. OnOperationCompleteHandler will be invoked upon receipt of an unsuback message.

Friends And Related Function Documentation

◆ MqttClient

friend class MqttClient
friend

Member Data Documentation

◆ OnConnectionCompleted

OnConnectionCompletedHandler Aws::Crt::Mqtt::MqttConnection::OnConnectionCompleted

◆ OnConnectionInterrupted

OnConnectionInterruptedHandler Aws::Crt::Mqtt::MqttConnection::OnConnectionInterrupted

◆ OnConnectionResumed

OnConnectionResumedHandler Aws::Crt::Mqtt::MqttConnection::OnConnectionResumed

◆ OnDisconnect

OnDisconnectHandler Aws::Crt::Mqtt::MqttConnection::OnDisconnect

◆ WebsocketInterceptor

OnWebSocketHandshakeIntercept Aws::Crt::Mqtt::MqttConnection::WebsocketInterceptor

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