AWS IoT Device SDK C++ v2  1.34.0
AWS IoT Device SDK C++ v2
Mqtt5Client.h
Go to the documentation of this file.
1 #pragma once
2 
6 #include <aws/crt/Config.h>
7 #include <aws/crt/Exports.h>
10 #include <aws/iot/MqttCommon.h>
11 
12 #if !BYO_CRYPTO
13 
14 namespace Aws
15 {
16  using namespace Crt::Mqtt5;
17 
18  namespace Io
19  {
20  class ClientBootstrap;
21  class SocketOptions;
22  class TlsContextOptions;
23  class WebsocketConfig;
24  } // namespace Io
25 
26  namespace Iot
27  {
28 
33  {
34  public:
39  virtual ~Mqtt5CustomAuthConfig();
40 
43 
44  Mqtt5CustomAuthConfig &operator=(const Mqtt5CustomAuthConfig &rhs);
46 
47  Mqtt5CustomAuthConfig &WithAuthorizerName(Crt::String authName);
48  Mqtt5CustomAuthConfig &WithUsername(Crt::String username);
49  Mqtt5CustomAuthConfig &WithPassword(Crt::ByteCursor password);
50  Mqtt5CustomAuthConfig &WithTokenKeyName(Crt::String tokenKeyName);
51  Mqtt5CustomAuthConfig &WithTokenValue(Crt::String tokenValue);
52  Mqtt5CustomAuthConfig &WithTokenSignature(Crt::String tokenSignature);
53 
54  const Crt::Optional<Crt::String> &GetAuthorizerName();
55  const Crt::Optional<Crt::String> &GetUsername();
56  const Crt::Optional<Crt::ByteCursor> &GetPassword();
57  const Crt::Optional<Crt::String> &GetTokenKeyName();
58  const Crt::Optional<Crt::String> &GetTokenValue();
59  const Crt::Optional<Crt::String> &GetTokenSignature();
60 
61  private:
68  Crt::Optional<Crt::String> m_authorizerName;
69 
82  Crt::Optional<Crt::String> m_username;
83 
89 
96  Crt::Optional<Crt::String> m_tokenKeyName;
97 
104  Crt::Optional<Crt::String> m_tokenValue;
105 
112  Crt::Optional<Crt::String> m_tokenSignature;
113 
114  Crt::ByteBuf m_passwordStorage;
115  Crt::Allocator *m_allocator;
116  };
117 
123  {
124  public:
136  static Mqtt5ClientBuilder *NewMqtt5ClientBuilderWithMtlsFromPath(
137  const Crt::String hostName,
138  const char *certPath,
139  const char *pkeyPath,
140  Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
141 
153  static Mqtt5ClientBuilder *NewMqtt5ClientBuilderWithMtlsFromMemory(
154  const Crt::String hostName,
155  const Crt::ByteCursor &certPath,
156  const Crt::ByteCursor &pkeyPath,
157  Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
158 
170  static Mqtt5ClientBuilder *NewMqtt5ClientBuilderWithMtlsPkcs11(
171  const Crt::String hostName,
172  const Crt::Io::TlsContextPkcs11Options &pkcs11Options,
173  Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
174 
186  static Mqtt5ClientBuilder *NewMqtt5ClientBuilderWithMtlsPkcs12(
187  const Crt::String hostName,
188  const struct Pkcs12Options &options,
189  Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
190 
204  static Mqtt5ClientBuilder *NewMqtt5ClientBuilderWithWindowsCertStorePath(
205  const Crt::String hostName,
206  const char *windowsCertStorePath,
207  Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
208 
218  static Mqtt5ClientBuilder *NewMqtt5ClientBuilderWithWebsocket(
219  const Crt::String hostName,
220  const WebsocketConfig &config,
221  Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
222 
232  static Mqtt5ClientBuilder *NewMqtt5ClientBuilderWithCustomAuthorizer(
233  const Crt::String hostName,
234  const Mqtt5CustomAuthConfig &customAuthConfig,
235  Crt::Allocator *allocator) noexcept;
236 
247  static Mqtt5ClientBuilder *NewMqtt5ClientBuilderWithCustomAuthorizerWebsocket(
248  const Crt::String hostName,
249  const Mqtt5CustomAuthConfig &customAuthConfig,
250  const WebsocketConfig &config,
251  Crt::Allocator *allocator) noexcept;
252 
260  Mqtt5ClientBuilder &WithHostName(Crt::String hostname);
261 
269  Mqtt5ClientBuilder &WithPort(uint32_t port) noexcept;
270 
279  Mqtt5ClientBuilder &WithBootstrap(Crt::Io::ClientBootstrap *bootStrap) noexcept;
280 
289  Mqtt5ClientBuilder &WithCertificateAuthority(const char *caPath) noexcept;
290 
299  Mqtt5ClientBuilder &WithCertificateAuthority(const Crt::ByteCursor &cert) noexcept;
300 
308  Mqtt5ClientBuilder &WithSocketOptions(Crt::Io::SocketOptions socketOptions) noexcept;
309 
317  Mqtt5ClientBuilder &WithHttpProxyOptions(
318  const Crt::Http::HttpClientConnectionProxyOptions &proxyOptions) noexcept;
319 
325  Mqtt5ClientBuilder &WithCustomAuthorizer(const Iot::Mqtt5CustomAuthConfig &config) noexcept;
326 
334  Mqtt5ClientBuilder &WithConnectOptions(std::shared_ptr<ConnectPacket> packetConnect) noexcept;
335 
343  Mqtt5ClientBuilder &WithSessionBehavior(ClientSessionBehaviorType sessionBehavior) noexcept;
344 
354  Mqtt5ClientBuilder &WithClientExtendedValidationAndFlowControl(
355  ClientExtendedValidationAndFlowControl clientExtendedValidationAndFlowControl) noexcept;
356 
367  Mqtt5ClientBuilder &WithOfflineQueueBehavior(
368  ClientOperationQueueBehaviorType offlineQueueBehavior) noexcept;
369 
378  Mqtt5ClientBuilder &WithReconnectOptions(ReconnectOptions reconnectOptions) noexcept;
379 
386  Mqtt5ClientBuilder &WithTopicAliasingOptions(TopicAliasingOptions topicAliasingOptions) noexcept;
387 
398  uint64_t minConnectedTimeToResetReconnectDelayMs) noexcept;
399 
408  Mqtt5ClientBuilder &WithPingTimeoutMs(uint32_t pingTimeoutMs) noexcept;
409 
418  Mqtt5ClientBuilder &WithConnackTimeoutMs(uint32_t connackTimeoutMs) noexcept;
419 
428  Mqtt5ClientBuilder &WithAckTimeoutSec(uint32_t ackTimeoutSec) noexcept;
429 
440  Mqtt5ClientBuilder &WithAckTimeoutSeconds(uint32_t ackTimeoutSec) noexcept;
441 
449  Mqtt5ClientBuilder &WithSdkName(const Crt::String &sdkName);
450 
458  Mqtt5ClientBuilder &WithSdkVersion(const Crt::String &sdkVersion);
459 
465  std::shared_ptr<Mqtt5Client> Build() noexcept;
466 
470  explicit operator bool() const noexcept { return m_lastError == 0; }
471 
475  int LastError() const noexcept { return m_lastError ? m_lastError : AWS_ERROR_UNKNOWN; }
476 
478  {
479  if (m_options)
480  {
481  delete m_options;
482  }
483  };
488 
496  Mqtt5ClientBuilder &WithClientConnectionSuccessCallback(OnConnectionSuccessHandler callback) noexcept;
497 
505  Mqtt5ClientBuilder &WithClientConnectionFailureCallback(OnConnectionFailureHandler callback) noexcept;
506 
514  Mqtt5ClientBuilder &WithClientDisconnectionCallback(OnDisconnectionHandler callback) noexcept;
515 
523  Mqtt5ClientBuilder &WithClientStoppedCallback(OnStoppedHandler callback) noexcept;
524 
532  Mqtt5ClientBuilder &WithClientAttemptingConnectCallback(OnAttemptingConnectHandler callback) noexcept;
533 
541  Mqtt5ClientBuilder &WithPublishReceivedCallback(OnPublishReceivedHandler callback) noexcept;
542 
543  private:
544  // Common setup shared by all valid constructors
545  Mqtt5ClientBuilder(Crt::Allocator *allocator) noexcept;
546  // Common setup shared by all valid constructors
547  Mqtt5ClientBuilder(int error, Crt::Allocator *allocator) noexcept;
548 
549  Crt::Allocator *m_allocator;
550 
554  uint32_t m_port;
555 
560  Crt::Optional<Crt::Io::TlsContextOptions> m_tlsConnectionOptions;
561 
566 
570  Crt::Optional<WebsocketConfig> m_websocketConfig;
571 
575  Crt::Optional<Mqtt5CustomAuthConfig> m_customAuthConfig;
576 
581  std::shared_ptr<ConnectPacket> m_connectOptions;
582 
584 
585  /* Error */
586  int m_lastError;
587 
588  bool m_enableMetricsCollection;
589 
590  Crt::String m_sdkName = "CPPv2";
591  Crt::String m_sdkVersion = AWS_CRT_CPP_VERSION;
592  };
593 
594  } // namespace Iot
595 } // namespace Aws
596 
597 #endif // !BYO_CRYPTO
Aws::Iot::Mqtt5ClientBuilder
Definition: Mqtt5Client.h:123
MqttCommon.h
Aws::Crt::ApiAllocator
AWS_CRT_CPP_API Allocator * ApiAllocator() noexcept
Definition: Allocator.cpp:24
Aws::Iot::Mqtt5CustomAuthConfig::Mqtt5CustomAuthConfig
Mqtt5CustomAuthConfig(Mqtt5CustomAuthConfig &&rhs)=delete
Aws::Iot::Mqtt5ClientBuilder::Mqtt5ClientBuilder
Mqtt5ClientBuilder(const Mqtt5ClientBuilder &)=delete
Aws::Iot::WebsocketConfig
Definition: MqttCommon.h:24
Aws::Crt::Mqtt5::Mqtt5ClientOptions
Definition: Mqtt5Client.h:451
Aws::Iot::Mqtt5ClientBuilder::~Mqtt5ClientBuilder
virtual ~Mqtt5ClientBuilder()
Definition: Mqtt5Client.h:477
Aws::Iot::Mqtt5ClientBuilder::operator=
Mqtt5ClientBuilder & operator=(Mqtt5ClientBuilder &&)=delete
Aws::Iot::Mqtt5CustomAuthConfig::operator=
Mqtt5CustomAuthConfig & operator=(Mqtt5CustomAuthConfig &&rhs)=delete
Aws::Crt::Mqtt5::ClientExtendedValidationAndFlowControl
aws_mqtt5_extended_validation_and_flow_control_options ClientExtendedValidationAndFlowControl
Definition: Mqtt5Types.h:200
Aws::Iot::Pkcs12Options
Definition: MqttCommon.h:105
Aws::Iot::Mqtt5ClientBuilder::WithMinConnectedTimeToResetReconnectDelayMs
Mqtt5ClientBuilder & WithMinConnectedTimeToResetReconnectDelayMs(uint64_t minConnectedTimeToResetReconnectDelayMs) noexcept
Aws::Crt::Mqtt5::OnPublishReceivedHandler
std::function< void(const PublishReceivedEventData &)> OnPublishReceivedHandler
Definition: Mqtt5Client.h:308
Mqtt5Client.h
Aws::Crt::Optional< Crt::String >
Aws::Iot::Mqtt5CustomAuthConfig
Definition: Mqtt5Client.h:33
Aws::Crt::Io::TlsContextPkcs11Options
Definition: TlsOptions.h:217
Aws::Iot::Mqtt5ClientBuilder::LastError
int LastError() const noexcept
Definition: Mqtt5Client.h:475
Aws::Crt::Mqtt5::OnAttemptingConnectHandler
std::function< void(const OnAttemptingConnectEventData &)> OnAttemptingConnectHandler
Definition: Mqtt5Client.h:282
Aws::Crt::Mqtt5::TopicAliasingOptions
Definition: Mqtt5Client.h:101
Aws::Iot::Mqtt5ClientBuilder::operator=
Mqtt5ClientBuilder & operator=(const Mqtt5ClientBuilder &)=delete
Aws::Crt::Mqtt5::OnConnectionFailureHandler
std::function< void(const OnConnectionFailureEventData &)> OnConnectionFailureHandler
Definition: Mqtt5Client.h:271
Aws::Crt::Mqtt5::OnDisconnectionHandler
std::function< void(const OnDisconnectionEventData &)> OnDisconnectionHandler
Definition: Mqtt5Client.h:276
Aws::Crt::Http::HttpClientConnectionProxyOptions
Definition: HttpConnection.h:270
Aws::Iot::Mqtt5ClientBuilder::Mqtt5ClientBuilder
Mqtt5ClientBuilder(Mqtt5ClientBuilder &&)=delete
Aws::Crt::Io::SocketOptions
Definition: SocketOptions.h:48
Aws::Crt::ByteBuf
aws_byte_buf ByteBuf
Definition: Types.h:30
AWS_CRT_CPP_API
#define AWS_CRT_CPP_API
Definition: Exports.h:37
Aws
Definition: Allocator.h:11
Aws::Crt::Mqtt5::ReconnectOptions
Definition: Mqtt5Client.h:145
Aws::Crt::ByteCursor
aws_byte_cursor ByteCursor
Definition: Types.h:31
Aws::Crt::Allocator
aws_allocator Allocator
Definition: Allocator.h:14
Exports.h
Sigv4Signing.h
Aws::Crt::Io::ClientBootstrap
Definition: Bootstrap.h:35
Aws::Crt::Mqtt5::ClientSessionBehaviorType
aws_mqtt5_client_session_behavior_type ClientSessionBehaviorType
Definition: Mqtt5Types.h:186
Aws::Crt::Mqtt5::OnConnectionSuccessHandler
std::function< void(const OnConnectionSuccessEventData &)> OnConnectionSuccessHandler
Definition: Mqtt5Client.h:266
Aws::Crt::Mqtt5::OnStoppedHandler
std::function< void(const OnStoppedEventData &)> OnStoppedHandler
Definition: Mqtt5Client.h:288
Aws::Crt::String
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > String
Definition: Types.h:45
Aws::Crt::Mqtt5::ClientOperationQueueBehaviorType
aws_mqtt5_client_operation_queue_behavior_type ClientOperationQueueBehaviorType
Definition: Mqtt5Types.h:223