From f6ae678a60f631e2d7e75855557c6500f33787ff Mon Sep 17 00:00:00 2001 From: SergeyRyabinin Date: Fri, 15 Nov 2024 19:31:20 +0000 Subject: [PATCH 1/2] Default init SDK options --- src/aws-cpp-sdk-core/include/aws/core/Aws.h | 41 ++++++++++----------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/aws-cpp-sdk-core/include/aws/core/Aws.h b/src/aws-cpp-sdk-core/include/aws/core/Aws.h index c07887bfaba..ad4f12eb0e8 100644 --- a/src/aws-cpp-sdk-core/include/aws/core/Aws.h +++ b/src/aws-cpp-sdk-core/include/aws/core/Aws.h @@ -25,18 +25,17 @@ namespace Aws */ struct LoggingOptions { - LoggingOptions() : logLevel(Aws::Utils::Logging::LogLevel::Off), defaultLogPrefix(DEFAULT_LOG_PREFIX) - { } + LoggingOptions() = default; /** * Defaults to Off, if this is set to something else, then logging will be turned on and logLevel will be passed to the logger */ - Aws::Utils::Logging::LogLevel logLevel; + Aws::Utils::Logging::LogLevel logLevel = Aws::Utils::Logging::LogLevel::Off; /** * Defaults to aws_sdk_. This will only be used if the default logger is used. */ - const char* defaultLogPrefix; + const char* defaultLogPrefix = DEFAULT_LOG_PREFIX; /** * Defaults to empty, if logLevel has been set and this field is empty, then the default log system will be used. @@ -56,15 +55,14 @@ namespace Aws */ struct MemoryManagementOptions { - MemoryManagementOptions() : memoryManager(nullptr) - { } + MemoryManagementOptions() = default; /** * Defaults to nullptr. If custom memory management is being used and this hasn't been set then the default memory * manager will be used. If this has been set and custom memory management has been turned on, then this will be installed * at startup time. */ - Aws::Utils::Memory::MemorySystemInterface* memoryManager; + Aws::Utils::Memory::MemorySystemInterface* memoryManager = nullptr; }; /** @@ -81,8 +79,7 @@ namespace Aws */ struct HttpOptions { - HttpOptions() : initAndCleanupCurl(true), installSigPipeHandler(false), compliantRfc3986Encoding(false) - { } + HttpOptions() = default; /** * Defaults to empty, if this is set, then the result of your closure will be installed and used instead of the system defaults @@ -92,7 +89,7 @@ namespace Aws * libCurl infects everything with its global state. If it is being used then we automatically initialize and clean it up. * If this is a problem for you, set this to false. If you manually initialize libcurl please add the option CURL_GLOBAL_ALL to your init call. */ - bool initAndCleanupCurl; + bool initAndCleanupCurl = true; /** * Installs a global SIGPIPE handler that logs the error and prevents it from terminating the current process. * This can be used on operating systems on which CURL is being used. In some situations CURL cannot avoid @@ -100,11 +97,11 @@ namespace Aws * For more information see: https://curl.haxx.se/libcurl/c/CURLOPT_NOSIGNAL.html * NOTE: CURLOPT_NOSIGNAL is already being set. */ - bool installSigPipeHandler; + bool installSigPipeHandler = false; /** * Disable legacy URL encoding that leaves `$&,:@=` unescaped for legacy purposes. */ - bool compliantRfc3986Encoding; + bool compliantRfc3986Encoding = false; /** * When constructing Path segments in a URI preserve path separators instead of collapsing * slashes. This is useful for aligning with other SDKs and tools on key path for S3 objects @@ -120,8 +117,7 @@ namespace Aws */ struct CryptoOptions { - CryptoOptions() : initAndCleanupOpenSSL(true) - { } + CryptoOptions() = default; /** * If set, this closure will be used to create and install the factory. @@ -164,7 +160,7 @@ namespace Aws * If this is a problem for you, set this to false. Be aware that if you don't use our init and cleanup and you are using * crypto functionality, you are responsible for installing thread locking, and loading strings and error messages. */ - bool initAndCleanupOpenSSL; + bool initAndCleanupOpenSSL = true; }; /** @@ -224,40 +220,41 @@ namespace Aws */ struct SDKOptions { + SDKOptions() = default; /** * SDK wide options for I/O: client bootstrap and TLS connection options */ - IoOptions ioOptions; + IoOptions ioOptions = {}; /** * SDK wide options for logging */ - LoggingOptions loggingOptions; + LoggingOptions loggingOptions = {}; /** * SDK wide options for memory management */ - MemoryManagementOptions memoryManagementOptions; + MemoryManagementOptions memoryManagementOptions = {}; /** * SDK wide options for http */ - HttpOptions httpOptions; + HttpOptions httpOptions = {}; /** * SDK wide options for crypto */ - CryptoOptions cryptoOptions; + CryptoOptions cryptoOptions = {}; /** * Options used to set up customized monitoring implementations * Put your monitoring factory in a closure (a create factory function) and put all closures in a vector. * Basic usage can be found in aws-cpp-sdk-core-tests/monitoring/MonitoringTest.cpp */ - MonitoringOptions monitoringOptions; + MonitoringOptions monitoringOptions = {}; struct SDKVersion { unsigned char major = AWS_SDK_VERSION_MAJOR; unsigned char minor = AWS_SDK_VERSION_MINOR; unsigned short patch = AWS_SDK_VERSION_PATCH; - } sdkVersion; + } sdkVersion = {}; }; /* From 5c1825b776b298030dd6647373fec081673fbe5e Mon Sep 17 00:00:00 2001 From: SergeyRyabinin Date: Fri, 15 Nov 2024 20:07:46 +0000 Subject: [PATCH 2/2] Run clang-format --- src/aws-cpp-sdk-core/include/aws/core/Aws.h | 548 ++++++++++---------- 1 file changed, 270 insertions(+), 278 deletions(-) diff --git a/src/aws-cpp-sdk-core/include/aws/core/Aws.h b/src/aws-cpp-sdk-core/include/aws/core/Aws.h index ad4f12eb0e8..dc68dde4600 100644 --- a/src/aws-cpp-sdk-core/include/aws/core/Aws.h +++ b/src/aws-cpp-sdk-core/include/aws/core/Aws.h @@ -4,305 +4,297 @@ */ #pragma once +#include +#include +#include +#include +#include +#include #include #include -#include #include -#include -#include -#include -#include -#include #include #include -namespace Aws -{ - static const char* DEFAULT_LOG_PREFIX = "aws_sdk_"; +namespace Aws { +static const char* DEFAULT_LOG_PREFIX = "aws_sdk_"; - /** - * SDK wide options for logging - */ - struct LoggingOptions - { - LoggingOptions() = default; - - /** - * Defaults to Off, if this is set to something else, then logging will be turned on and logLevel will be passed to the logger - */ - Aws::Utils::Logging::LogLevel logLevel = Aws::Utils::Logging::LogLevel::Off; +/** + * SDK wide options for logging + */ +struct LoggingOptions { + LoggingOptions() = default; - /** - * Defaults to aws_sdk_. This will only be used if the default logger is used. - */ - const char* defaultLogPrefix = DEFAULT_LOG_PREFIX; + /** + * Defaults to Off, if this is set to something else, then logging will be turned on and logLevel will be passed to the logger + */ + Aws::Utils::Logging::LogLevel logLevel = Aws::Utils::Logging::LogLevel::Off; - /** - * Defaults to empty, if logLevel has been set and this field is empty, then the default log system will be used. - * otherwise, we will call this closure to create a logger - */ - std::function()> logger_create_fn; + /** + * Defaults to aws_sdk_. This will only be used if the default logger is used. + */ + const char* defaultLogPrefix = DEFAULT_LOG_PREFIX; - /** - * Defaults to empty, if logLevel has been set and this field is empty, then the default CRT log system will be used. - * The default CRT log system will redirect all logs from common runtime libraries (CRT) to C++ SDK with the same log level and formatting. - */ - std::function()> crt_logger_create_fn; - }; + /** + * Defaults to empty, if logLevel has been set and this field is empty, then the default log system will be used. + * otherwise, we will call this closure to create a logger + */ + std::function()> logger_create_fn; - /** - * SDK wide options for memory management - */ - struct MemoryManagementOptions - { - MemoryManagementOptions() = default; + /** + * Defaults to empty, if logLevel has been set and this field is empty, then the default CRT log system will be used. + * The default CRT log system will redirect all logs from common runtime libraries (CRT) to C++ SDK with the same log level and + * formatting. + */ + std::function()> crt_logger_create_fn; +}; - /** - * Defaults to nullptr. If custom memory management is being used and this hasn't been set then the default memory - * manager will be used. If this has been set and custom memory management has been turned on, then this will be installed - * at startup time. - */ - Aws::Utils::Memory::MemorySystemInterface* memoryManager = nullptr; - }; +/** + * SDK wide options for memory management + */ +struct MemoryManagementOptions { + MemoryManagementOptions() = default; - /** - * SDK wide options for I/O: client bootstrap and TLS connection options - */ - struct IoOptions - { - std::function()> clientBootstrap_create_fn; - std::function()> tlsConnectionOptions_create_fn; - }; + /** + * Defaults to nullptr. If custom memory management is being used and this hasn't been set then the default memory + * manager will be used. If this has been set and custom memory management has been turned on, then this will be installed + * at startup time. + */ + Aws::Utils::Memory::MemorySystemInterface* memoryManager = nullptr; +}; - /** - * SDK wide options for http - */ - struct HttpOptions - { - HttpOptions() = default; +/** + * SDK wide options for I/O: client bootstrap and TLS connection options + */ +struct IoOptions { + std::function()> clientBootstrap_create_fn; + std::function()> tlsConnectionOptions_create_fn; +}; - /** - * Defaults to empty, if this is set, then the result of your closure will be installed and used instead of the system defaults - */ - std::function()> httpClientFactory_create_fn; - /** - * libCurl infects everything with its global state. If it is being used then we automatically initialize and clean it up. - * If this is a problem for you, set this to false. If you manually initialize libcurl please add the option CURL_GLOBAL_ALL to your init call. - */ - bool initAndCleanupCurl = true; - /** - * Installs a global SIGPIPE handler that logs the error and prevents it from terminating the current process. - * This can be used on operating systems on which CURL is being used. In some situations CURL cannot avoid - * triggering a SIGPIPE. - * For more information see: https://curl.haxx.se/libcurl/c/CURLOPT_NOSIGNAL.html - * NOTE: CURLOPT_NOSIGNAL is already being set. - */ - bool installSigPipeHandler = false; - /** - * Disable legacy URL encoding that leaves `$&,:@=` unescaped for legacy purposes. - */ - bool compliantRfc3986Encoding = false; - /** - * When constructing Path segments in a URI preserve path separators instead of collapsing - * slashes. This is useful for aligning with other SDKs and tools on key path for S3 objects - * as currently the C++ SDK sanitizes the path. - * - * TODO: In the next major release, this will become the default to align better with other SDKs. - */ - bool preservePathSeparators = false; - }; +/** + * SDK wide options for http + */ +struct HttpOptions { + HttpOptions() = default; - /** - * SDK wide options for crypto - */ - struct CryptoOptions - { - CryptoOptions() = default; + /** + * Defaults to empty, if this is set, then the result of your closure will be installed and used instead of the system defaults + */ + std::function()> httpClientFactory_create_fn; + /** + * libCurl infects everything with its global state. If it is being used then we automatically initialize and clean it up. + * If this is a problem for you, set this to false. If you manually initialize libcurl please add the option CURL_GLOBAL_ALL to your init + * call. + */ + bool initAndCleanupCurl = true; + /** + * Installs a global SIGPIPE handler that logs the error and prevents it from terminating the current process. + * This can be used on operating systems on which CURL is being used. In some situations CURL cannot avoid + * triggering a SIGPIPE. + * For more information see: https://curl.haxx.se/libcurl/c/CURLOPT_NOSIGNAL.html + * NOTE: CURLOPT_NOSIGNAL is already being set. + */ + bool installSigPipeHandler = false; + /** + * Disable legacy URL encoding that leaves `$&,:@=` unescaped for legacy purposes. + */ + bool compliantRfc3986Encoding = false; + /** + * When constructing Path segments in a URI preserve path separators instead of collapsing + * slashes. This is useful for aligning with other SDKs and tools on key path for S3 objects + * as currently the C++ SDK sanitizes the path. + * + * TODO: In the next major release, this will become the default to align better with other SDKs. + */ + bool preservePathSeparators = false; +}; - /** - * If set, this closure will be used to create and install the factory. - */ - std::function()> md5Factory_create_fn; - /** - * If set, this closure will be used to create and install the factory. - */ - std::function()> sha1Factory_create_fn; - /** - * If set, this closure will be used to create and install the factory. - */ - std::function()> sha256Factory_create_fn; - /** - * If set, this closure will be used to create and install the factory. - */ - std::function()> sha256HMACFactory_create_fn; - /** - * If set, this closure will be used to create and install the factory. - */ - std::function()> aes_CBCFactory_create_fn; - /** - * If set, this closure will be used to create and install the factory. - */ - std::function()> aes_CTRFactory_create_fn; - /** - * If set, this closure will be used to create and install the factory. - */ - std::function()> aes_GCMFactory_create_fn; - /** - * If set, this closure will be used to create and install the factory. - */ - std::function()> aes_KeyWrapFactory_create_fn; - /** - * If set, this closure will be used to create and install the factory. - */ - std::function()> secureRandomFactory_create_fn; - /** - * OpenSSL infects everything with its global state. If it is being used then we automatically initialize and clean it up. - * If this is a problem for you, set this to false. Be aware that if you don't use our init and cleanup and you are using - * crypto functionality, you are responsible for installing thread locking, and loading strings and error messages. - */ - bool initAndCleanupOpenSSL = true; - }; +/** + * SDK wide options for crypto + */ +struct CryptoOptions { + CryptoOptions() = default; - /** - * MonitoringOptions is used to set up monitoring functionalities globally and(or) for users to customize monitoring listeners. - */ - struct MonitoringOptions - { - /** - * These factory functions will be used to try to create customized monitoring listener factories, then be used to create monitoring listener instances. - * Based on functions and factory's implementation, it may fail to create an instance. - * If a function failed to create factory or a created factory failed to create an instance, SDK just ignore it. - * By default, SDK will try to create a default Client Side Monitoring Listener. - */ - std::vector customizedMonitoringFactory_create_fn; - }; + /** + * If set, this closure will be used to create and install the factory. + */ + std::function()> md5Factory_create_fn; + /** + * If set, this closure will be used to create and install the factory. + */ + std::function()> sha1Factory_create_fn; + /** + * If set, this closure will be used to create and install the factory. + */ + std::function()> sha256Factory_create_fn; + /** + * If set, this closure will be used to create and install the factory. + */ + std::function()> sha256HMACFactory_create_fn; + /** + * If set, this closure will be used to create and install the factory. + */ + std::function()> aes_CBCFactory_create_fn; + /** + * If set, this closure will be used to create and install the factory. + */ + std::function()> aes_CTRFactory_create_fn; + /** + * If set, this closure will be used to create and install the factory. + */ + std::function()> aes_GCMFactory_create_fn; + /** + * If set, this closure will be used to create and install the factory. + */ + std::function()> aes_KeyWrapFactory_create_fn; + /** + * If set, this closure will be used to create and install the factory. + */ + std::function()> secureRandomFactory_create_fn; + /** + * OpenSSL infects everything with its global state. If it is being used then we automatically initialize and clean it up. + * If this is a problem for you, set this to false. Be aware that if you don't use our init and cleanup and you are using + * crypto functionality, you are responsible for installing thread locking, and loading strings and error messages. + */ + bool initAndCleanupOpenSSL = true; +}; +/** + * MonitoringOptions is used to set up monitoring functionalities globally and(or) for users to customize monitoring listeners. + */ +struct MonitoringOptions { + /** + * These factory functions will be used to try to create customized monitoring listener factories, then be used to create monitoring + * listener instances. Based on functions and factory's implementation, it may fail to create an instance. If a function failed to create + * factory or a created factory failed to create an instance, SDK just ignore it. By default, SDK will try to create a default Client Side + * Monitoring Listener. + */ + std::vector customizedMonitoringFactory_create_fn; +}; - /** - * You may notice that instead of taking pointers directly to your factories, we take a closure. This is because - * if you have installed custom memory management, the allocation for your factories needs to happen after - * the memory system has been initialized and shutdown needs to happen prior to the memory management being shutdown. - * - * Common Recipes: - * - * Just use defaults: - * - * SDKOptions options; - * Aws::InitAPI(options); - * ..... - * Aws::ShutdownAPI(options); - * - * Turn logging on using the default logger: - * - * SDKOptions options; - * options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info; - * Aws::InitAPI(options); - * ..... - * Aws::ShutdownAPI(options); - * - * Install custom memory manager: - * - * MyMemoryManager memoryManager; - * - * SDKOptions options; - * options.memoryManagementOptions.memoryManager = &memoryManager; - * Aws::InitAPI(options); - * ..... - * Aws::ShutdownAPI(options); - * - * Override default http client factory - * - * SDKOptions options; - * options.httpOptions.httpClientFactory_create_fn = [](){ return Aws::MakeShared("ALLOC_TAG", arg1); }; - * Aws::InitAPI(options); - * ..... - * Aws::ShutdownAPI(options); - */ - struct SDKOptions - { - SDKOptions() = default; - /** - * SDK wide options for I/O: client bootstrap and TLS connection options - */ - IoOptions ioOptions = {}; - /** - * SDK wide options for logging - */ - LoggingOptions loggingOptions = {}; - /** - * SDK wide options for memory management - */ - MemoryManagementOptions memoryManagementOptions = {}; - /** - * SDK wide options for http - */ - HttpOptions httpOptions = {}; - /** - * SDK wide options for crypto - */ - CryptoOptions cryptoOptions = {}; +/** + * You may notice that instead of taking pointers directly to your factories, we take a closure. This is because + * if you have installed custom memory management, the allocation for your factories needs to happen after + * the memory system has been initialized and shutdown needs to happen prior to the memory management being shutdown. + * + * Common Recipes: + * + * Just use defaults: + * + * SDKOptions options; + * Aws::InitAPI(options); + * ..... + * Aws::ShutdownAPI(options); + * + * Turn logging on using the default logger: + * + * SDKOptions options; + * options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info; + * Aws::InitAPI(options); + * ..... + * Aws::ShutdownAPI(options); + * + * Install custom memory manager: + * + * MyMemoryManager memoryManager; + * + * SDKOptions options; + * options.memoryManagementOptions.memoryManager = &memoryManager; + * Aws::InitAPI(options); + * ..... + * Aws::ShutdownAPI(options); + * + * Override default http client factory + * + * SDKOptions options; + * options.httpOptions.httpClientFactory_create_fn = [](){ return Aws::MakeShared("ALLOC_TAG", arg1); }; + * Aws::InitAPI(options); + * ..... + * Aws::ShutdownAPI(options); + */ +struct SDKOptions { + SDKOptions() = default; + /** + * SDK wide options for I/O: client bootstrap and TLS connection options + */ + IoOptions ioOptions = {}; + /** + * SDK wide options for logging + */ + LoggingOptions loggingOptions = {}; + /** + * SDK wide options for memory management + */ + MemoryManagementOptions memoryManagementOptions = {}; + /** + * SDK wide options for http + */ + HttpOptions httpOptions = {}; + /** + * SDK wide options for crypto + */ + CryptoOptions cryptoOptions = {}; - /** - * Options used to set up customized monitoring implementations - * Put your monitoring factory in a closure (a create factory function) and put all closures in a vector. - * Basic usage can be found in aws-cpp-sdk-core-tests/monitoring/MonitoringTest.cpp - */ - MonitoringOptions monitoringOptions = {}; + /** + * Options used to set up customized monitoring implementations + * Put your monitoring factory in a closure (a create factory function) and put all closures in a vector. + * Basic usage can be found in aws-cpp-sdk-core-tests/monitoring/MonitoringTest.cpp + */ + MonitoringOptions monitoringOptions = {}; - struct SDKVersion - { - unsigned char major = AWS_SDK_VERSION_MAJOR; - unsigned char minor = AWS_SDK_VERSION_MINOR; - unsigned short patch = AWS_SDK_VERSION_PATCH; - } sdkVersion = {}; - }; + struct SDKVersion { + unsigned char major = AWS_SDK_VERSION_MAJOR; + unsigned char minor = AWS_SDK_VERSION_MINOR; + unsigned short patch = AWS_SDK_VERSION_PATCH; + } sdkVersion = {}; +}; - /* - * Initialize SDK wide state for the SDK. This method must be called before doing anything else with this library. - * - * Common Recipes: - * - * Just use defaults: - * - * SDKOptions options; - * Aws::InitAPI(options); - * ..... - * Aws::ShutdownAPI(options); - * - * Turn logging on using the default logger: - * - * SDKOptions options; - * options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info; - * Aws::InitAPI(options); - * ..... - * Aws::ShutdownAPI(options); - * - * Install custom memory manager: - * - * MyMemoryManager memoryManager; - * - * SDKOptions options; - * options.memoryManagementOptions.memoryManager = &memoryManager; - * Aws::InitAPI(options); - * ..... - * Aws::ShutdownAPI(options); - * - * Override default http client factory - * - * SDKOptions options; - * options.httpOptions.httpClientFactory_create_fn = [](){ return Aws::MakeShared("ALLOC_TAG", arg1); }; - * Aws::InitAPI(options); - * ..... - * Aws::ShutdownAPI(options); - */ - AWS_CORE_API void InitAPI(const SDKOptions& options); +/* + * Initialize SDK wide state for the SDK. This method must be called before doing anything else with this library. + * + * Common Recipes: + * + * Just use defaults: + * + * SDKOptions options; + * Aws::InitAPI(options); + * ..... + * Aws::ShutdownAPI(options); + * + * Turn logging on using the default logger: + * + * SDKOptions options; + * options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info; + * Aws::InitAPI(options); + * ..... + * Aws::ShutdownAPI(options); + * + * Install custom memory manager: + * + * MyMemoryManager memoryManager; + * + * SDKOptions options; + * options.memoryManagementOptions.memoryManager = &memoryManager; + * Aws::InitAPI(options); + * ..... + * Aws::ShutdownAPI(options); + * + * Override default http client factory + * + * SDKOptions options; + * options.httpOptions.httpClientFactory_create_fn = [](){ return Aws::MakeShared("ALLOC_TAG", arg1); }; + * Aws::InitAPI(options); + * ..... + * Aws::ShutdownAPI(options); + */ +AWS_CORE_API void InitAPI(const SDKOptions& options); - /** - * Shutdown SDK wide state for the SDK. This method must be called when you are finished using the SDK. - * Notes: - * 1) Please call this from the same thread from which InitAPI() has been called (use a dedicated thread - * if necessary). This avoids problems in initializing the dependent Common RunTime C libraries. - * 2) Do not call any other SDK methods after calling ShutdownAPI. - */ - AWS_CORE_API void ShutdownAPI(const SDKOptions& options); -} +/** + * Shutdown SDK wide state for the SDK. This method must be called when you are finished using the SDK. + * Notes: + * 1) Please call this from the same thread from which InitAPI() has been called (use a dedicated thread + * if necessary). This avoids problems in initializing the dependent Common RunTime C libraries. + * 2) Do not call any other SDK methods after calling ShutdownAPI. + */ +AWS_CORE_API void ShutdownAPI(const SDKOptions& options); +} // namespace Aws