Skip to content

Commit

Permalink
Add a method to report library version from ApiHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyRyabinin committed Dec 7, 2023
1 parent 0c64f25 commit 3ae76d4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
16 changes: 16 additions & 0 deletions include/aws/crt/Api.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ namespace Aws
*/
static Io::HostResolver *GetOrCreateStaticDefaultHostResolver();

#pragma pack(push, 1)
struct CrtCppVersion
{
uint16_t major;
uint16_t minor;
uint16_t patch;
};
#pragma pack(pop)
/**
* Gets the version of the AWS-CRT-CPP library
* @return- CrtCppVersion representing the library version
*/
const CrtCppVersion& GetCrtVersion() const;

private:
void InitializeLoggingCommon(struct aws_logger_standard_options &options);

Expand All @@ -195,6 +209,8 @@ namespace Aws
static Io::HostResolver *s_static_default_host_resolver;
static std::mutex s_lock_default_host_resolver;
static void ReleaseStaticDefaultHostResolver();

CrtCppVersion m_crtVersion = {0, 0, 0};
};

/**
Expand Down
9 changes: 8 additions & 1 deletion source/Api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/crt/Api.h>
#include <aws/crt/Config.h>
#include <aws/crt/JsonObject.h>
#include <aws/crt/StlAllocator.h>
#include <aws/crt/io/TlsOptions.h>
Expand Down Expand Up @@ -37,7 +38,8 @@ namespace Aws
std::mutex ApiHandle::s_lock_default_host_resolver;

ApiHandle::ApiHandle(Allocator *allocator) noexcept
: m_logger(), m_shutdownBehavior(ApiHandleShutdownBehavior::Blocking)
: m_logger(), m_shutdownBehavior(ApiHandleShutdownBehavior::Blocking),
m_crtVersion({AWS_CRT_CPP_VERSION_MAJOR, AWS_CRT_CPP_VERSION_MINOR, AWS_CRT_CPP_VERSION_PATCH})
{
// sets up the StlAllocator for use.
g_allocator = allocator;
Expand Down Expand Up @@ -373,6 +375,11 @@ namespace Aws
return s_BYOCryptoIsTlsAlpnSupportedCallback;
}

const ApiHandle::CrtCppVersion& ApiHandle::GetCrtVersion() const
{
return m_crtVersion;
}

const char *ErrorDebugString(int error) noexcept { return aws_error_debug_str(error); }

int LastError() noexcept { return aws_last_error(); }
Expand Down
16 changes: 16 additions & 0 deletions tests/ApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/crt/Api.h>
#include <aws/crt/Config.h>
#include <aws/crt/Types.h>
#include <aws/testing/aws_test_harness.h>

Expand Down Expand Up @@ -54,3 +55,18 @@ static int s_TestApiStaticDefaultCreateDestroy(struct aws_allocator *allocator,
}

AWS_TEST_CASE(ApiStaticDefaultCreateDestroy, s_TestApiStaticDefaultCreateDestroy)

static int s_TestApiVersionReporting(struct aws_allocator *allocator, void *)
{
{
Aws::Crt::ApiHandle apiHandle(allocator);
Aws::Crt::ApiHandle::CrtCppVersion version = apiHandle.GetCrtVersion();
ASSERT_UINT_EQUALS(version.major, AWS_CRT_CPP_VERSION_MAJOR);
ASSERT_UINT_EQUALS(version.minor, AWS_CRT_CPP_VERSION_MINOR);
ASSERT_UINT_EQUALS(version.patch, AWS_CRT_CPP_VERSION_PATCH);
}

return AWS_ERROR_SUCCESS;
}

AWS_TEST_CASE(ApiStaticVersionReporting, s_TestApiVersionReporting)

0 comments on commit 3ae76d4

Please sign in to comment.