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;
46 ~MqttConnectionCore();
47 MqttConnectionCore(
const MqttConnectionCore &) =
delete;
48 MqttConnectionCore(MqttConnectionCore &&) =
delete;
49 MqttConnectionCore &operator=(
const MqttConnectionCore &) =
delete;
50 MqttConnectionCore &operator=(MqttConnectionCore &&) =
delete;
56 operator bool() const noexcept;
71 int LastError() const noexcept;
82 bool SetWill(const
char *topic, QOS qos,
bool retain, const ByteBuf &payload) noexcept;
92 bool SetLogin(const
char *username, const
char *password) noexcept;
104 bool SetHttpProxyOptions(const Http::HttpClientConnectionProxyOptions &proxyOptions) noexcept;
118 bool SetReconnectTimeout(uint64_t min_seconds, uint64_t max_seconds) noexcept;
139 const
char *clientId,
141 uint16_t keepAliveTimeSecs,
142 uint32_t pingTimeoutMs,
143 uint32_t protocolOperationTimeoutMs,
144 bool setWebSocketInterceptor) noexcept;
151 bool Disconnect() noexcept;
154 aws_mqtt_client_connection *GetUnderlyingConnection() const noexcept;
170 const
char *topicFilter,
172 OnMessageReceivedHandler &&onMessage,
173 OnSubAckHandler &&onSubAck) noexcept;
189 const Vector<
std::pair<const
char *, OnMessageReceivedHandler>> &topicFilters,
191 OnMultiSubAckHandler &&onOpComplete) noexcept;
201 bool SetOnMessageHandler(OnMessageReceivedHandler &&onMessage) noexcept;
213 uint16_t Unsubscribe(const
char *topicFilter, OnOperationCompleteHandler &&onOpComplete) noexcept;
233 const ByteBuf &payload,
234 OnOperationCompleteHandler &&onOpComplete) noexcept;
242 const MqttConnectionOperationStatistics &GetOperationStatistics() noexcept;
252 static
std::shared_ptr<MqttConnectionCore> s_createMqttConnectionCore(
253 aws_mqtt_client *client,
254 std::shared_ptr<MqttConnection> connection,
255 MqttConnectionOptions options) noexcept;
264 static
std::shared_ptr<MqttConnectionCore> s_createMqttConnectionCore(
265 aws_mqtt5_client *mqtt5Client,
266 std::shared_ptr<MqttConnection> connection,
267 MqttConnectionOptions options) noexcept;
269 static
void s_onConnectionTermination(
void *userData);
271 static
void s_onConnectionInterrupted(aws_mqtt_client_connection *,
int errorCode,
void *userData);
272 static
void s_onConnectionCompleted(
273 aws_mqtt_client_connection *,
275 enum aws_mqtt_connect_return_code returnCode,
279 static
void s_onConnectionSuccess(
280 aws_mqtt_client_connection *,
281 ReturnCode returnCode,
285 static
void s_onConnectionFailure(aws_mqtt_client_connection *,
int errorCode,
void *userData);
287 static
void s_onConnectionResumed(
288 aws_mqtt_client_connection *,
289 ReturnCode returnCode,
293 static
void s_onConnectionClosed(
294 aws_mqtt_client_connection *,
295 on_connection_closed_data *data,
298 static
void s_onDisconnect(aws_mqtt_client_connection *connection,
void *userData);
299 static
void s_onPublish(
300 aws_mqtt_client_connection *connection,
301 const aws_byte_cursor *topic,
302 const aws_byte_cursor *payload,
304 enum aws_mqtt_qos qos,
308 static
void s_onSubAck(
309 aws_mqtt_client_connection *connection,
311 const struct aws_byte_cursor *topic,
312 enum aws_mqtt_qos qos,
315 static
void s_onMultiSubAck(
316 aws_mqtt_client_connection *connection,
318 const struct aws_array_list *topicSubacks,
321 static
void s_onOpComplete(
322 aws_mqtt_client_connection *connection,
327 static
void s_onWebsocketHandshake(
328 struct aws_http_message *request,
330 aws_mqtt_transform_websocket_handshake_complete_fn *completeFn,
347 aws_mqtt_client *client,
348 aws_mqtt5_client *mqtt5Client,
349 std::shared_ptr<MqttConnection> connection,
350 MqttConnectionOptions options) noexcept;
352 void createUnderlyingConnection(aws_mqtt_client *mqttClient);
353 void createUnderlyingConnection(aws_mqtt5_client *mqtt5Client);
354 void connectionInit();
362 std::shared_ptr<MqttConnection> obtainConnectionInstance();
364 aws_mqtt_client_connection *m_underlyingConnection;
367 Crt::Io::TlsContext m_tlsContext;
368 Io::TlsConnectionOptions m_tlsOptions;
369 Io::SocketOptions m_socketOptions;
370 Crt::Optional<Http::HttpClientConnectionProxyOptions> m_proxyOptions;
374 MqttConnectionOperationStatistics m_operationStatistics;
375 Allocator *m_allocator;
383 std::weak_ptr<MqttConnection> m_connection;
390 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