Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,29 @@
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
ly_get_list_relative_pal_filename(pal_dir ${CMAKE_CURRENT_LIST_DIR}/source/Platform/${PAL_PLATFORM_NAME})
ly_add_target(
NAME AWSNativeSDKInit STATIC
NAMESPACE AZ
FILES_CMAKE
aws_native_sdk_init_files.cmake
${pal_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
INCLUDE_DIRECTORIES
PUBLIC
include
PRIVATE
${pal_dir}
BUILD_DEPENDENCIES
PRIVATE
3rdParty::AWSNativeSDK::Core
AZ::AzCore
)
@@ -0,0 +1,19 @@
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
set(FILES
include/AWSNativeSDKInit/AWSNativeSDKInit.h
include/AWSNativeSDKInit/AWSMemoryInterface.h
include/AWSNativeSDKInit/AWSLogSystemInterface.h
source/AWSNativeSDKInit.cpp
source/AWSMemoryInterface.cpp
source/AWSLogSystemInterface.cpp
)
@@ -0,0 +1,80 @@
/*
* All or portions of this file Copyright(c) Amazon.com, Inc.or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
#pragma once
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
#include <AzCore/PlatformDef.h>
AZ_PUSH_DISABLE_WARNING(4251 4996, "-Wunknown-warning-option")
#include <aws/core/utils/logging/LogSystemInterface.h>
AZ_POP_DISABLE_WARNING
#else
#include <sstream>
namespace Aws
{
using OStringStream = std::basic_ostringstream<char>;
namespace Utils
{
namespace Logging
{
using LogLevel = int;
}
}
}
#endif
namespace AWSNativeSDKInit
{
class AWSLogSystemInterface
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
: public Aws::Utils::Logging::LogSystemInterface
#endif
{
public:
static const char* AWS_API_LOG_PREFIX;
static const int MAX_MESSAGE_LENGTH;
static const char* MESSAGE_FORMAT;
static const char* ERROR_WINDOW_NAME;
static const char* LOG_ENV_VAR;
AWSLogSystemInterface(Aws::Utils::Logging::LogLevel logLevel);
/**
* Gets the currently configured log level for this logger.
*/
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
Aws::Utils::Logging::LogLevel GetLogLevel(void) const override;
#else
Aws::Utils::Logging::LogLevel GetLogLevel(void) const;
#endif
/**
* Does a printf style output to the output stream. Don't use this, it's unsafe. See LogStream
*/
void Log(Aws::Utils::Logging::LogLevel logLevel, const char* tag, const char* formatStr, ...);
/**
* Writes the stream to the output stream.
*/
void LogStream(Aws::Utils::Logging::LogLevel logLevel, const char* tag, const Aws::OStringStream &messageStream);
void Flush();
private:
bool ShouldLog(Aws::Utils::Logging::LogLevel logLevel);
void SetLogLevel(Aws::Utils::Logging::LogLevel newLevel);
void ForwardAwsApiLogMessage(Aws::Utils::Logging::LogLevel logLevel, const char* tag, const char* message);
Aws::Utils::Logging::LogLevel m_logLevel;
};
}
@@ -0,0 +1,73 @@
/*
* All or portions of this file Copyright(c) Amazon.com, Inc.or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
#pragma once
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
#include <aws/core/utils/memory/MemorySystemInterface.h>
#else
#include <cstddef>
#endif
#include <AzCore/Memory/Memory.h>
#include <AzCore/Memory/SystemAllocator.h>
namespace AWSNativeSDKInit
{
class AWSNativeSDKAllocator final
: public AZ::SystemAllocator
{
public:
AZ_CLASS_ALLOCATOR(AWSNativeSDKAllocator, AZ::SystemAllocator, 0);
AZ_TYPE_INFO(AWSNativeSDKAllocator, "{8B4DA42F-2507-4A5B-B13C-4B2A72BC161E}");
///////////////////////////////////////////////////////////////////////////////////////////
// IAllocator
const char* GetName() const override
{
return "AWSNativeSDKAllocator";
}
const char* GetDescription() const override
{
return "Allocator used by the AWSNativeSDK";
}
///////////////////////////////////////////////////////////////////////////////////////////
};
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
class MemoryManager : public Aws::Utils::Memory::MemorySystemInterface
{
static const char* AWS_API_ALLOC_TAG;
public:
void Begin() override;
void End() override;
void* AllocateMemory(std::size_t blockSize, std::size_t alignment, const char* allocationTag = nullptr) override;
void FreeMemory(void* memoryPtr) override;
AZ::AllocatorWrapper<AWSNativeSDKAllocator> m_allocator;
bool m_systemAllocatorCreated{ false };
};
#else
class MemoryManager
{
static const char* AWS_API_ALLOC_TAG;
public:
void Begin();
void End();
void* AllocateMemory(std::size_t blockSize, std::size_t alignment, const char* allocationTag = nullptr);
void FreeMemory(void* memoryPtr);
};
#endif
}
@@ -0,0 +1,62 @@
/*
* All or portions of this file Copyright(c) Amazon.com, Inc.or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
#pragma once
#include <AWSNativeSDKInit/AWSMemoryInterface.h>
#include <AzCore/Module/Environment.h>
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
// The AWS Native SDK AWSAllocator triggers a warning due to accessing members of std::allocator directly.
// AWSAllocator.h(70): warning C4996: 'std::allocator<T>::pointer': warning STL4010: Various members of std::allocator are deprecated in C++17.
// Use std::allocator_traits instead of accessing these members directly.
// You can define _SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning.
AZ_PUSH_DISABLE_WARNING(4251 4996, "-Wunknown-warning-option")
#include <aws/core/Aws.h>
AZ_POP_DISABLE_WARNING
#endif
namespace AWSNativeSDKInit
{
// Entry point for Lumberyard managing the AWSNativeSDK's initialization and shutdown requirements
// Use an AZ::Environment variable to enforce only one init and shutdown
class InitializationManager
{
public:
static const char* const initializationManagerTag;
InitializationManager();
~InitializationManager();
// Call to guarantee that the API is initialized with proper Lumberyard settings.
// It's fine to call this from every module which needs to use the NativeSDK
// Creates a static shared pointer using the AZ EnvironmentVariable system.
// This will prevent a the AWS SDK from going through the shutdown routine until all references are gone, or
// the AZ::EnvironmentVariable system is brought down.
static void InitAwsApi();
static bool IsInitialized();
// Remove our reference
static void Shutdown();
private:
void InitializeAwsApiInternal();
void ShutdownAwsApiInternal();
MemoryManager m_memoryManager;
static AZ::EnvironmentVariable<InitializationManager> s_initManager;
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
Aws::SDKOptions m_awsSDKOptions;
#endif
};
}
@@ -0,0 +1,162 @@
/*
* All or portions of this file Copyright(c) Amazon.com, Inc.or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
#include <AWSNativeSDKInit/AWSLogSystemInterface.h>
#include <AzCore/base.h>
#include <AzCore/Module/Environment.h>
#include <stdarg.h>
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
AZ_PUSH_DISABLE_WARNING(4251 4996, "-Wunknown-warning-option")
#include <aws/core/utils/logging/AWSLogging.h>
#include <aws/core/utils/logging/DefaultLogSystem.h>
#include <aws/core/utils/logging/ConsoleLogSystem.h>
AZ_POP_DISABLE_WARNING
#endif
namespace AWSNativeSDKInit
{
const char* AWSLogSystemInterface::AWS_API_LOG_PREFIX = "AwsApi-";
const int AWSLogSystemInterface::MAX_MESSAGE_LENGTH = 4096;
const char* AWSLogSystemInterface::MESSAGE_FORMAT = "[AWS] %s - %s";
const char* AWSLogSystemInterface::ERROR_WINDOW_NAME = "AwsNativeSDK";
AWSLogSystemInterface::AWSLogSystemInterface(Aws::Utils::Logging::LogLevel logLevel)
: m_logLevel(logLevel)
{
}
/**
* Gets the currently configured log level for this logger.
*/
Aws::Utils::Logging::LogLevel AWSLogSystemInterface::GetLogLevel() const
{
Aws::Utils::Logging::LogLevel newLevel = m_logLevel;
static const char* const logLevelEnvVar = "sys_SetLogLevel";
auto logVar = AZ::Environment::FindVariable<int>(logLevelEnvVar);
if (logVar)
{
newLevel = (Aws::Utils::Logging::LogLevel) *logVar;
}
return newLevel != m_logLevel ? newLevel : m_logLevel;
}
/**
* Does a printf style output to the output stream. Don't use this, it's unsafe. See LogStream
*/
void AWSLogSystemInterface::Log(Aws::Utils::Logging::LogLevel logLevel, const char* tag, const char* formatStr, ...)
{
if (!ShouldLog(logLevel))
{
return;
}
char message[MAX_MESSAGE_LENGTH];
va_list mark;
va_start(mark, formatStr);
azvsnprintf(message, MAX_MESSAGE_LENGTH, formatStr, mark);
va_end(mark);
ForwardAwsApiLogMessage(logLevel, tag, message);
}
/**
* Writes the stream to the output stream.
*/
void AWSLogSystemInterface::LogStream(Aws::Utils::Logging::LogLevel logLevel, const char* tag, const Aws::OStringStream &messageStream)
{
if(!ShouldLog(logLevel))
{
return;
}
ForwardAwsApiLogMessage(logLevel, tag, messageStream.str().c_str());
}
bool AWSLogSystemInterface::ShouldLog(Aws::Utils::Logging::LogLevel logLevel)
{
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
Aws::Utils::Logging::LogLevel newLevel = GetLogLevel();
if (newLevel > Aws::Utils::Logging::LogLevel::Info && newLevel <= Aws::Utils::Logging::LogLevel::Trace && newLevel != m_logLevel)
{
SetLogLevel(newLevel);
}
#endif
return (logLevel <= m_logLevel);
}
void AWSLogSystemInterface::SetLogLevel(Aws::Utils::Logging::LogLevel newLevel)
{
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
Aws::Utils::Logging::ShutdownAWSLogging();
Aws::Utils::Logging::InitializeAWSLogging(Aws::MakeShared<AWSLogSystemInterface>("AWS", newLevel));
m_logLevel = newLevel;
#endif
}
void AWSLogSystemInterface::ForwardAwsApiLogMessage(Aws::Utils::Logging::LogLevel logLevel, const char* tag, const char* message)
{
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
switch (logLevel)
{
case Aws::Utils::Logging::LogLevel::Off:
break;
case Aws::Utils::Logging::LogLevel::Fatal:
AZ::Debug::Trace::Instance().Error(__FILE__, __LINE__, AZ_FUNCTION_SIGNATURE, AWSLogSystemInterface::ERROR_WINDOW_NAME, MESSAGE_FORMAT, tag, message);
break;
case Aws::Utils::Logging::LogLevel::Error:
AZ::Debug::Trace::Instance().Warning(__FILE__, __LINE__, AZ_FUNCTION_SIGNATURE, AWSLogSystemInterface::ERROR_WINDOW_NAME, MESSAGE_FORMAT, tag, message);
break;
case Aws::Utils::Logging::LogLevel::Warn:
AZ::Debug::Trace::Instance().Warning(__FILE__, __LINE__, AZ_FUNCTION_SIGNATURE, AWSLogSystemInterface::ERROR_WINDOW_NAME, MESSAGE_FORMAT, tag, message);
break;
case Aws::Utils::Logging::LogLevel::Info:
AZ::Debug::Trace::Instance().Printf(AWSLogSystemInterface::ERROR_WINDOW_NAME, MESSAGE_FORMAT, tag, message);
break;
case Aws::Utils::Logging::LogLevel::Debug:
AZ::Debug::Trace::Instance().Printf(AWSLogSystemInterface::ERROR_WINDOW_NAME, MESSAGE_FORMAT, tag, message);
break;
case Aws::Utils::Logging::LogLevel::Trace:
AZ::Debug::Trace::Instance().Printf(AWSLogSystemInterface::ERROR_WINDOW_NAME, MESSAGE_FORMAT, tag, message);
break;
default:
break;
}
#endif
}
void AWSLogSystemInterface::Flush()
{
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
// No-op AZ Debug Trace doesn't have a flush API
#endif
}
}
@@ -0,0 +1,53 @@
/*
* All or portions of this file Copyright(c) Amazon.com, Inc.or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
#include <AWSNativeSDKInit/AWSMemoryInterface.h>
namespace AWSNativeSDKInit
{
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
const char* MemoryManager::AWS_API_ALLOC_TAG = "AwsApi";
void MemoryManager::Begin()
{
// We can't guarantee that all uses cases have/will Create a SystemAllocator which is a dependency of
// the AWSNativeSDKAllocator in SystemAllocator::Create
if (!AZ::AllocatorInstance<AZ::SystemAllocator>::IsReady())
{
AZ::AllocatorInstance<AZ::SystemAllocator>::Create();
m_systemAllocatorCreated = true;
}
AWSNativeSDKAllocator::Descriptor desc;
m_allocator.Create(desc);
}
void MemoryManager::End()
{
m_allocator.Destroy();
if (m_systemAllocatorCreated)
{
AZ::AllocatorInstance<AZ::SystemAllocator>::Destroy();
}
}
void* MemoryManager::AllocateMemory(std::size_t blockSize, std::size_t alignment, const char* allocationTag)
{
return m_allocator->Allocate(blockSize, alignment, 0, allocationTag);
}
void MemoryManager::FreeMemory(void* memoryPtr)
{
m_allocator->DeAllocate(memoryPtr);
}
#endif
}
@@ -0,0 +1,92 @@
/*
* All or portions of this file Copyright(c) Amazon.com, Inc.or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
#include <AWSNativeSDKInit/AWSNativeSDKInit.h>
#include <AzCore/Module/Environment.h>
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
#include <AWSNativeSDKInit/AWSLogSystemInterface.h>
#include <aws/core/Aws.h>
#include <aws/core/utils/logging/AWSLogging.h>
#include <aws/core/utils/logging/DefaultLogSystem.h>
#include <aws/core/utils/logging/ConsoleLogSystem.h>
#endif
namespace AWSNativeSDKInit
{
namespace Platform
{
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
void CustomizeSDKOptions(Aws::SDKOptions& options);
void CustomizeShutdown();
#endif
}
const char* const InitializationManager::initializationManagerTag = "AWSNativeSDKInitializer";
AZ::EnvironmentVariable<InitializationManager> InitializationManager::s_initManager = nullptr;
InitializationManager::InitializationManager()
{
InitializeAwsApiInternal();
}
InitializationManager::~InitializationManager()
{
ShutdownAwsApiInternal();
}
void InitializationManager::InitAwsApi()
{
s_initManager = AZ::Environment::CreateVariable<InitializationManager>(initializationManagerTag);
}
void InitializationManager::Shutdown()
{
s_initManager = nullptr;
}
bool InitializationManager::IsInitialized()
{
return s_initManager.IsConstructed();
}
void InitializationManager::InitializeAwsApiInternal()
{
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
Aws::Utils::Logging::LogLevel logLevel;
#ifdef _DEBUG
logLevel = Aws::Utils::Logging::LogLevel::Warn;
#else
logLevel = Aws::Utils::Logging::LogLevel::Warn;
#endif
m_awsSDKOptions.loggingOptions.logLevel = logLevel;
m_awsSDKOptions.loggingOptions.logger_create_fn = [logLevel]()
{
return Aws::MakeShared<AWSLogSystemInterface>("AWS", logLevel);
};
m_awsSDKOptions.memoryManagementOptions.memoryManager = &m_memoryManager;
Platform::CustomizeSDKOptions(m_awsSDKOptions);
Aws::InitAPI(m_awsSDKOptions);
#endif // #if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
}
void InitializationManager::ShutdownAwsApiInternal()
{
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
Aws::ShutdownAPI(m_awsSDKOptions);
Platform::CustomizeShutdown();
#endif // #if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
}
}
@@ -0,0 +1,14 @@
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
set(FILES
../Common/Default/AWSNativeSDKInit_Default.cpp
)
@@ -0,0 +1,29 @@
/*
* All or portions of this file Copyright(c) Amazon.com, Inc.or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
#include <AWSNativeSDKInit/AWSNativeSDKInit.h>
namespace AWSNativeSDKInit
{
namespace Platform
{
#if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK)
void CustomizeSDKOptions(Aws::SDKOptions& options)
{
AZ_UNUSED(options);
}
void CustomizeShutdown()
{
}
#endif
}
}
@@ -0,0 +1,14 @@
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
set(FILES
../Common/Default/AWSNativeSDKInit_Default.cpp
)
@@ -0,0 +1,14 @@
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
set(FILES
../Common/Default/AWSNativeSDKInit_Default.cpp
)
@@ -0,0 +1,14 @@
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
set(FILES
../Common/Default/AWSNativeSDKInit_Default.cpp
)
@@ -0,0 +1,14 @@
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
set(FILES
../Common/Default/AWSNativeSDKInit_Default.cpp
)