19#include <aws/mqtt/client.h>
20#include <aws/mqtt/v5/mqtt5_client.h>
41 class MqttConnectionCore
final :
public std::enable_shared_from_this<MqttConnectionCore>
43 friend MqttConnection;
44 friend class IoTSDKMetricsEncoder;
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;
72 int LastError() 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;
106 bool SetHttpProxyOptions(const Http::HttpClientConnectionProxyOptions &proxyOptions) noexcept;
116 bool SetL4ProxyOptions(const
std::shared_ptr<
Aws::Crt::Io::L4ProxyConfig> &l4ProxyOptions) noexcept;
130 bool SetReconnectTimeout(uint64_t min_seconds, uint64_t max_seconds) noexcept;
151 const
char *clientId,
153 uint16_t keepAliveTimeSecs,
154 uint32_t pingTimeoutMs,
155 uint32_t protocolOperationTimeoutMs,
156 bool setWebSocketInterceptor) noexcept;
163 bool Disconnect() noexcept;
166 aws_mqtt_client_connection *GetUnderlyingConnection() const noexcept;
182 const
char *topicFilter,
184 OnMessageReceivedHandler &&onMessage,
185 OnSubAckHandler &&onSubAck) noexcept;
201 const Vector<
std::pair<const
char *, OnMessageReceivedHandler>> &topicFilters,
203 OnMultiSubAckHandler &&onOpComplete) noexcept;
213 bool SetOnMessageHandler(OnMessageReceivedHandler &&onMessage) noexcept;
225 uint16_t Unsubscribe(const
char *topicFilter, OnOperationCompleteHandler &&onOpComplete) noexcept;
245 const ByteBuf &payload,
246 OnOperationCompleteHandler &&onOpComplete) noexcept;
254 const MqttConnectionOperationStatistics &GetOperationStatistics() noexcept;
264 static
std::shared_ptr<MqttConnectionCore> s_createMqttConnectionCore(
265 aws_mqtt_client *client,
266 std::shared_ptr<MqttConnection> connection,
267 MqttConnectionOptions options) noexcept;
276 static
std::shared_ptr<MqttConnectionCore> s_createMqttConnectionCore(
277 aws_mqtt5_client *mqtt5Client,
278 std::shared_ptr<MqttConnection> connection,
279 MqttConnectionOptions options) noexcept;
281 static
void s_onConnectionTermination(
void *userData);
283 static
void s_onConnectionInterrupted(aws_mqtt_client_connection *,
int errorCode,
void *userData);
284 static
void s_onConnectionCompleted(
285 aws_mqtt_client_connection *,
287 enum aws_mqtt_connect_return_code returnCode,
291 static
void s_onConnectionSuccess(
292 aws_mqtt_client_connection *,
293 ReturnCode returnCode,
297 static
void s_onConnectionFailure(aws_mqtt_client_connection *,
int errorCode,
void *userData);
299 static
void s_onConnectionResumed(
300 aws_mqtt_client_connection *,
301 ReturnCode returnCode,
305 static
void s_onConnectionClosed(
306 aws_mqtt_client_connection *,
307 on_connection_closed_data *data,
310 static
void s_onDisconnect(aws_mqtt_client_connection *connection,
void *userData);
311 static
void s_onPublish(
312 aws_mqtt_client_connection *connection,
313 const aws_byte_cursor *topic,
314 const aws_byte_cursor *payload,
316 enum aws_mqtt_qos qos,
320 static
void s_onSubAck(
321 aws_mqtt_client_connection *connection,
323 const struct aws_byte_cursor *topic,
324 enum aws_mqtt_qos qos,
327 static
void s_onMultiSubAck(
328 aws_mqtt_client_connection *connection,
330 const struct aws_array_list *topicSubacks,
333 static
void s_onOpComplete(
334 aws_mqtt_client_connection *connection,
339 static
void s_onWebsocketHandshake(
340 struct aws_http_message *request,
342 aws_mqtt_transform_websocket_handshake_complete_fn *completeFn,
359 aws_mqtt_client *client,
360 aws_mqtt5_client *mqtt5Client,
361 std::shared_ptr<MqttConnection> connection,
362 MqttConnectionOptions options) noexcept;
364 void createUnderlyingConnection(aws_mqtt_client *mqttClient);
365 void createUnderlyingConnection(aws_mqtt5_client *mqtt5Client);
366 void connectionInit();
374 std::shared_ptr<MqttConnection> obtainConnectionInstance();
376 aws_mqtt_client_connection *m_underlyingConnection;
379 Crt::Io::TlsContext m_tlsContext;
380 Io::TlsConnectionOptions m_tlsOptions;
381 Io::SocketOptions m_socketOptions;
382 Crt::Optional<Http::HttpClientConnectionProxyOptions> m_proxyOptions;
383 std::shared_ptr<
Aws::Crt::Io::L4ProxyConfig> m_l4ProxyOptions;
387 MqttConnectionOperationStatistics m_operationStatistics;
388 bool m_enableMetrics = true;
389 Crt::Optional<AWSIoTMetrics> m_sdkMetrics;
390 Allocator *m_allocator;
398 std::weak_ptr<MqttConnection> m_connection;
405 std::shared_ptr<MqttConnectionCore> m_self;
std::unique_ptr< T, std::function< void(T *)> > ScopedResource
Definition Types.h:168
Definition Allocator.h:11
Definition StringView.h:862