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;
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;
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,
173 OnMessageReceivedHandler &&onMessage,
174 OnSubAckHandler &&onSubAck) noexcept;
190 const Vector<
std::pair<const
char *, OnMessageReceivedHandler>> &topicFilters,
192 OnMultiSubAckHandler &&onOpComplete) noexcept;
202 bool SetOnMessageHandler(OnMessageReceivedHandler &&onMessage) noexcept;
214 uint16_t Unsubscribe(const
char *topicFilter, OnOperationCompleteHandler &&onOpComplete) noexcept;
234 const ByteBuf &payload,
235 OnOperationCompleteHandler &&onOpComplete) noexcept;
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 *,
282 ReturnCode returnCode,
286 static
void s_onConnectionFailure(aws_mqtt_client_connection *,
int errorCode,
void *userData);
288 static
void s_onConnectionResumed(
289 aws_mqtt_client_connection *,
290 ReturnCode returnCode,
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;
378 Allocator *m_allocator;
386 std::weak_ptr<MqttConnection> m_connection;
393 std::shared_ptr<MqttConnectionCore> m_self;
std::unique_ptr< T, std::function< void(T *)> > ScopedResource
Definition Types.h:163
Definition Allocator.h:11
Definition StringView.h:862