20 #include <aws/mqtt/client.h>
21 #include <aws/mqtt/v5/mqtt5_client.h>
42 class MqttConnectionCore final :
public std::enable_shared_from_this<MqttConnectionCore>
44 friend MqttConnection;
47 ~MqttConnectionCore();
48 MqttConnectionCore(
const MqttConnectionCore &) =
delete;
49 MqttConnectionCore(MqttConnectionCore &&) =
delete;
50 MqttConnectionCore &operator=(
const MqttConnectionCore &) =
delete;
51 MqttConnectionCore &operator=(MqttConnectionCore &&) =
delete;
57 operator bool() const noexcept;
83 bool SetWill(const
char *topic,
QOS qos,
bool retain, const
ByteBuf &payload) noexcept;
93 bool SetLogin(const
char *username, const
char *password) noexcept;
105 bool SetHttpProxyOptions(const Http::HttpClientConnectionProxyOptions &proxyOptions) noexcept;
119 bool SetReconnectTimeout(uint64_t min_seconds, uint64_t max_seconds) noexcept;
140 const
char *clientId,
142 uint16_t keepAliveTimeSecs,
143 uint32_t pingTimeoutMs,
144 uint32_t protocolOperationTimeoutMs,
145 bool setWebSocketInterceptor) noexcept;
152 bool Disconnect() noexcept;
155 aws_mqtt_client_connection *GetUnderlyingConnection() const noexcept;
171 const
char *topicFilter,
243 const MqttConnectionOperationStatistics &GetOperationStatistics() noexcept;
253 static
std::shared_ptr<MqttConnectionCore> s_createMqttConnectionCore(
254 aws_mqtt_client *client,
255 std::shared_ptr<MqttConnection> connection,
256 MqttConnectionOptions options) noexcept;
265 static
std::shared_ptr<MqttConnectionCore> s_createMqttConnectionCore(
266 aws_mqtt5_client *mqtt5Client,
267 std::shared_ptr<MqttConnection> connection,
268 MqttConnectionOptions options) noexcept;
270 static
void s_onConnectionTermination(
void *userData);
272 static
void s_onConnectionInterrupted(aws_mqtt_client_connection *,
int errorCode,
void *userData);
273 static
void s_onConnectionCompleted(
274 aws_mqtt_client_connection *,
276 enum aws_mqtt_connect_return_code returnCode,
280 static
void s_onConnectionSuccess(
281 aws_mqtt_client_connection *,
286 static
void s_onConnectionFailure(aws_mqtt_client_connection *,
int errorCode,
void *userData);
288 static
void s_onConnectionResumed(
289 aws_mqtt_client_connection *,
294 static
void s_onConnectionClosed(
295 aws_mqtt_client_connection *,
296 on_connection_closed_data *data,
299 static
void s_onDisconnect(aws_mqtt_client_connection *connection,
void *userData);
300 static
void s_onPublish(
301 aws_mqtt_client_connection *connection,
302 const aws_byte_cursor *topic,
303 const aws_byte_cursor *payload,
305 enum aws_mqtt_qos qos,
309 static
void s_onSubAck(
310 aws_mqtt_client_connection *connection,
312 const struct aws_byte_cursor *topic,
313 enum aws_mqtt_qos qos,
316 static
void s_onMultiSubAck(
317 aws_mqtt_client_connection *connection,
319 const struct aws_array_list *topicSubacks,
322 static
void s_onOpComplete(
323 aws_mqtt_client_connection *connection,
328 static
void s_onWebsocketHandshake(
329 struct aws_http_message *request,
331 aws_mqtt_transform_websocket_handshake_complete_fn *completeFn,
348 aws_mqtt_client *client,
349 aws_mqtt5_client *mqtt5Client,
350 std::shared_ptr<MqttConnection> connection,
351 MqttConnectionOptions options) noexcept;
353 void createUnderlyingConnection(aws_mqtt_client *mqttClient);
354 void createUnderlyingConnection(aws_mqtt5_client *mqtt5Client);
355 void connectionInit();
363 std::shared_ptr<MqttConnection> obtainConnectionInstance();
365 aws_mqtt_client_connection *m_underlyingConnection;
368 Crt::Io::TlsContext m_tlsContext;
369 Io::TlsConnectionOptions m_tlsOptions;
370 Io::SocketOptions m_socketOptions;
371 Crt::Optional<Http::HttpClientConnectionProxyOptions> m_proxyOptions;
375 MqttConnectionOperationStatistics m_operationStatistics;
376 bool m_enableMetrics = true;
377 IoTDeviceSDKMetrics m_sdkMetrics;
386 std::weak_ptr<MqttConnection> m_connection;
393 std::shared_ptr<MqttConnectionCore> m_self;
std::function< void(MqttConnection &connection, uint16_t packetId, const Vector< String > &topics, QOS qos, int errorCode)> OnMultiSubAckHandler
Definition: MqttTypes.h:85
Definition: StringView.h:861
aws_byte_buf ByteBuf
Definition: Types.h:30
aws_mqtt_connect_return_code ReturnCode
Definition: Types.h:41
std::basic_string< char, std::char_traits< char >, StlAllocator< char >> String
Definition: Types.h:45
std::function< void(MqttConnection &connection, const String &topic, const ByteBuf &payload, bool dup, QOS qos, bool retain)> OnMessageReceivedHandler
Definition: MqttTypes.h:57
aws_allocator Allocator
Definition: Allocator.h:14
std::function< void(MqttConnection &connection, uint16_t packetId, int errorCode)> OnOperationCompleteHandler
Definition: MqttTypes.h:98
std::function< void(MqttConnection &connection, uint16_t packetId, const String &topic, QOS qos, int errorCode)> OnSubAckHandler
Definition: MqttTypes.h:69
AWS_CRT_CPP_API int LastError() noexcept
Definition: Api.cpp:464
std::vector< T, StlAllocator< T >> Vector
Definition: Types.h:53
aws_mqtt_qos QOS
Definition: Types.h:40
Definition: Allocator.h:10