AWS IoT Device SDK C++ v2  1.34.0
AWS IoT Device SDK C++ v2
Api.h
Go to the documentation of this file.
1 #pragma once
2 
6 #include <aws/crt/Types.h>
7 #include <aws/crt/crypto/HMAC.h>
8 #include <aws/crt/crypto/Hash.h>
11 
12 #include <aws/common/logging.h>
13 
14 namespace Aws
15 {
16  namespace Crt
17  {
21  enum class LogLevel
22  {
23  None = AWS_LL_NONE,
24  Fatal = AWS_LL_FATAL,
25  Error = AWS_LL_ERROR,
26  Warn = AWS_LL_WARN,
27  Info = AWS_LL_INFO,
28  Debug = AWS_LL_DEBUG,
29  Trace = AWS_LL_TRACE,
30 
31  Count
32  };
33 
38  {
39  Blocking,
41  };
42 
48  {
49  public:
54  ApiHandle(Allocator *allocator) noexcept;
55  ApiHandle() noexcept;
56  ~ApiHandle();
57  ApiHandle(const ApiHandle &) = delete;
58  ApiHandle(ApiHandle &&) = delete;
59  ApiHandle &operator=(const ApiHandle &) = delete;
60  ApiHandle &operator=(ApiHandle &&) = delete;
61 
68  void InitializeLogging(LogLevel level, const char *filename);
69 
76  void InitializeLogging(LogLevel level, FILE *fp);
77 
82  void SetShutdownBehavior(ApiHandleShutdownBehavior behavior);
83 
88  void SetBYOCryptoNewMD5Callback(Crypto::CreateHashCallback &&callback);
89 
94  void SetBYOCryptoNewSHA256Callback(Crypto::CreateHashCallback &&callback);
95 
100  void SetBYOCryptoNewSHA1Callback(Crypto::CreateHashCallback &&callback);
101 
106  void SetBYOCryptoNewSHA256HMACCallback(Crypto::CreateHMACCallback &&callback);
107 
113  void SetBYOCryptoClientTlsCallback(Io::NewClientTlsHandlerCallback &&callback);
114 
124  void SetBYOCryptoTlsContextCallbacks(
125  Io::NewTlsContextImplCallback &&newCallback,
126  Io::DeleteTlsContextImplCallback &&deleteCallback,
127  Io::IsTlsAlpnSupportedCallback &&alpnCallback);
128 
130  static const Io::NewTlsContextImplCallback &GetBYOCryptoNewTlsContextImplCallback();
132  static const Io::DeleteTlsContextImplCallback &GetBYOCryptoDeleteTlsContextImplCallback();
134  static const Io::IsTlsAlpnSupportedCallback &GetBYOCryptoIsTlsAlpnSupportedCallback();
135 
149  static Io::ClientBootstrap *GetOrCreateStaticDefaultClientBootstrap();
150 
166  static Io::EventLoopGroup *GetOrCreateStaticDefaultEventLoopGroup();
167 
183  static Io::HostResolver *GetOrCreateStaticDefaultHostResolver();
184 
185 #pragma pack(push, 1)
186  struct Version
187  {
188  uint16_t major;
189  uint16_t minor;
190  uint16_t patch;
191  };
192 #pragma pack(pop)
193 
197  Version GetCrtVersion() const;
198 
199  private:
200  void InitializeLoggingCommon(struct aws_logger_standard_options &options);
201 
202  aws_logger m_logger;
203 
204  ApiHandleShutdownBehavior m_shutdownBehavior;
205 
206  static Io::ClientBootstrap *s_static_bootstrap;
207  static std::mutex s_lock_client_bootstrap;
208  static void ReleaseStaticDefaultClientBootstrap();
209 
210  static Io::EventLoopGroup *s_static_event_loop_group;
211  static std::mutex s_lock_event_loop_group;
212  static void ReleaseStaticDefaultEventLoopGroup();
213 
214  static int s_host_resolver_default_max_hosts;
215  static Io::HostResolver *s_static_default_host_resolver;
216  static std::mutex s_lock_default_host_resolver;
217  static void ReleaseStaticDefaultHostResolver();
218 
219  Version m_version = {0, 0, 0};
220  };
221 
227  AWS_CRT_CPP_API const char *ErrorDebugString(int error) noexcept;
228 
232  AWS_CRT_CPP_API int LastError() noexcept;
233 
238  AWS_CRT_CPP_API int LastErrorOrUnknown() noexcept;
239  } // namespace Crt
240 } // namespace Aws
Aws::Crt::ApiHandle::ApiHandle
ApiHandle(const ApiHandle &)=delete
Aws::Crt::ApiHandle
Definition: Api.h:48
HMAC.h
Aws::Crt::Crypto::CreateHMACCallback
std::function< std::shared_ptr< ByoHMAC >(size_t digestSize, const ByteCursor &secret, Allocator *)> CreateHMACCallback
Definition: HMAC.h:164
Aws::Crt::LastError
AWS_CRT_CPP_API int LastError() noexcept
Definition: Api.cpp:422
Aws::Crt::ApiHandle::Version::patch
uint16_t patch
Definition: Api.h:190
Aws::Crt::ApiHandle::operator=
ApiHandle & operator=(ApiHandle &&)=delete
Aws::Crt::ApiHandleShutdownBehavior
ApiHandleShutdownBehavior
Definition: Api.h:38
Mqtt5Client.h
Aws::Crt::Io::IsTlsAlpnSupportedCallback
std::function< bool()> IsTlsAlpnSupportedCallback
Definition: TlsOptions.h:388
Aws::Crt::Io::DeleteTlsContextImplCallback
std::function< void(void *)> DeleteTlsContextImplCallback
Definition: TlsOptions.h:387
Aws::Crt::LogLevel
LogLevel
Definition: Api.h:22
Aws::Crt::ApiHandle::Version::major
uint16_t major
Definition: Api.h:188
Aws::Crt::Crypto::CreateHashCallback
std::function< std::shared_ptr< ByoHash >(size_t digestSize, Allocator *)> CreateHashCallback
Definition: Hash.h:208
Aws::Crt::ApiHandle::Version
Definition: Api.h:187
Aws::Crt::Io::NewClientTlsHandlerCallback
std::function< std::shared_ptr< ClientTlsChannelHandler >(struct aws_channel_slot *slot, const struct aws_tls_connection_options &options, Allocator *allocator)> NewClientTlsHandlerCallback
Definition: TlsOptions.h:449
Types.h
Aws::Crt::LastErrorOrUnknown
AWS_CRT_CPP_API int LastErrorOrUnknown() noexcept
Definition: Api.cpp:427
Aws::Crt::Io::HostResolver
Definition: HostResolver.h:35
Aws::Crt::LogLevel::None
@ None
Aws::Crt::ApiHandle::operator=
ApiHandle & operator=(const ApiHandle &)=delete
Aws::Crt::ApiHandle::ApiHandle
ApiHandle(ApiHandle &&)=delete
AWS_CRT_CPP_API
#define AWS_CRT_CPP_API
Definition: Exports.h:37
Aws
Definition: Allocator.h:11
Aws::Crt::ApiHandle::Version::minor
uint16_t minor
Definition: Api.h:189
Aws::Crt::Allocator
aws_allocator Allocator
Definition: Allocator.h:14
Aws::Crt::Io::NewTlsContextImplCallback
std::function< void *(TlsContextOptions &, TlsMode, Allocator *)> NewTlsContextImplCallback
Definition: TlsOptions.h:386
Aws::Crt::ErrorDebugString
AWS_CRT_CPP_API const char * ErrorDebugString(int error) noexcept
Definition: Api.cpp:417
Aws::Crt::Io::ClientBootstrap
Definition: Bootstrap.h:35
MqttClient.h
Hash.h
Aws::Crt::ApiHandleShutdownBehavior::Blocking
@ Blocking
Aws::Crt::Io::EventLoopGroup
Definition: EventLoopGroup.h:33