Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method to report library version from ApiHandle #579

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Version
{
uint16_t major;
uint16_t minor;
uint16_t patch;
};
#pragma pack(pop)
/**
* Gets the version of the AWS-CRT-CPP library
* @return Version representing the library version
*/
Version 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();

Version m_version = {0, 0, 0};
};

/**
Expand Down
6 changes: 5 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_version({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,8 @@ namespace Aws
return s_BYOCryptoIsTlsAlpnSupportedCallback;
}

ApiHandle::Version ApiHandle::GetCrtVersion() const { return m_version; }

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::Version 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)