13#include "azure/core/dll_import_export.hpp"
14#include "azure/core/rtti.hpp"
24namespace Azure {
namespace Core {
namespace Tracing {
28namespace Azure {
namespace Core {
52 Key const* m_uniqueAddress;
59 Key() : m_uniqueAddress(this) {}
68 return this->m_uniqueAddress == other.m_uniqueAddress;
80 struct ContextSharedState final
82 std::shared_ptr<ContextSharedState> Parent;
83 std::atomic<DateTime::rep> Deadline;
84 std::shared_ptr<Azure::Core::Tracing::TracerProvider> TraceProvider;
86 std::shared_ptr<void> Value;
87#if defined(AZ_CORE_RTTI)
88 const std::type_info& ValueType;
90 static constexpr DateTime::rep ToDateTimeRepresentation(
DateTime const& dateTime)
92 return dateTime.time_since_epoch().count();
95 static constexpr DateTime FromDateTimeRepresentation(DateTime::rep dtRepresentation)
100 explicit ContextSharedState()
101 : Deadline(ToDateTimeRepresentation((DateTime::max)())), Value(nullptr)
102#if defined(AZ_CORE_RTTI)
104 ValueType(typeid(std::nullptr_t))
109 explicit ContextSharedState(
110 const std::shared_ptr<ContextSharedState>& parent,
111 DateTime
const& deadline)
112 : Parent(parent), Deadline(ToDateTimeRepresentation(deadline)), Value(nullptr)
113#if defined(AZ_CORE_RTTI)
115 ValueType(typeid(std::nullptr_t))
121 explicit ContextSharedState(
122 const std::shared_ptr<ContextSharedState>& parent,
123 DateTime
const& deadline,
124 Context::Key
const& key,
126 : Parent(parent), Deadline(ToDateTimeRepresentation(deadline)), Key(key),
127 Value(std::make_shared<T>(std::move(value)))
128#if defined(AZ_CORE_RTTI)
136 std::shared_ptr<ContextSharedState> m_contextSharedState;
138 explicit Context(std::shared_ptr<ContextSharedState> impl)
139 : m_contextSharedState(std::move(impl))
148 Context() : m_contextSharedState(std::make_shared<ContextSharedState>()) {}
159 return Context{std::make_shared<ContextSharedState>(m_contextSharedState, deadline)};
173 return Context{std::make_shared<ContextSharedState>(
174 m_contextSharedState, (DateTime::max)(), key, std::forward<T>(value))};
203 for (
auto ptr = m_contextSharedState; ptr; ptr = ptr->Parent)
207#if defined(AZ_CORE_RTTI)
209 typeid(T) == ptr->ValueType,
"Type mismatch for Context::TryGetValue().");
212 outputValue = *
reinterpret_cast<const T*
>(ptr->Value.get());
225 m_contextSharedState->Deadline
226 = ContextSharedState::ToDateTimeRepresentation((DateTime::min)());
Provide assert macros to use with pre-conditions.
#define AZURE_ASSERT_MSG(exp, msg)
Azure specific assert macro with message.
Definition azure_assert.hpp:53
A key used to store and retrieve data in an Azure::Core::Context object.
Definition context.hpp:51
bool operator!=(Key const &other) const
Compares with other Key for equality.
Definition context.hpp:76
bool operator==(Key const &other) const
Compares with other Key for equality.
Definition context.hpp:66
Key()
Constructs a default instance of Key.
Definition context.hpp:59
A context is a node within a tree that represents deadlines and key/value pairs.
Definition context.hpp:46
void ThrowIfCancelled() const
Checks if the context is cancelled.
Definition context.hpp:240
void Cancel()
Cancels the context.
Definition context.hpp:223
bool TryGetValue(Key const &key, T &outputValue) const
Gets the value associated with a key parameter within this context or the branch of contexts this con...
Definition context.hpp:201
Context WithDeadline(DateTime const &deadline) const
Creates a context with a deadline.
Definition context.hpp:157
Context WithValue(Key const &key, T &&value) const
Creates a context without a deadline, but with key and value associated with it.
Definition context.hpp:171
static const AZ_CORE_DLLEXPORT Context ApplicationContext
The application context (root).
Definition context.hpp:252
Context()
Constructs a new context with no deadline, and no value associated.
Definition context.hpp:148
bool IsCancelled() const
Checks if the context is cancelled.
Definition context.hpp:233
DateTime GetDeadline() const
Gets the deadline for this context or the branch of contexts this context belongs to.
Definition context.cpp:10
An exception thrown when an operation is cancelled.
Definition context.hpp:33
OperationCancelledException(std::string const &what)
Constructs an OperationCancelledException with message string as the description.
Definition context.hpp:40
Manages date and time in standardized string formats.
Definition datetime.hpp:54
operator std::chrono::system_clock::time_point() const
Convert an instance of Azure::DateTime to std::chrono::system_clock::time_point.
Definition datetime.cpp:423
Support for date and time standardized string formats.
Compute the hash value for the input binary data, using SHA256, SHA384 and SHA512.
Definition azure_assert.hpp:57