Azure SDK for Embedded C
az_context.h
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // SPDX-License-Identifier: MIT
3 
15 #ifndef _az_CONTEXT_H
16 #define _az_CONTEXT_H
17 
18 #include <azure/core/az_result.h>
19 
20 #include <stddef.h>
21 #include <stdint.h>
22 
23 #include <azure/core/_az_cfg_prefix.h>
24 
28 // Definition is below. Defining the typedef first is necessary here since there is a cycle.
29 typedef struct az_context az_context;
30 
36 struct az_context
37 {
38  struct
39  {
40  az_context const* parent; // Pointer to parent context (or NULL); immutable after creation
41  int64_t expiration; // Time when context expires
42  void const* key; // Pointers to the key & value (usually NULL)
43  void const* value;
44  } _internal;
45 };
46 
47 #define _az_CONTEXT_MAX_EXPIRATION 0x7FFFFFFFFFFFFFFF
48 
55 
64 AZ_NODISCARD az_context
65 az_context_create_with_expiration(az_context const* parent, int64_t expiration);
66 
76 AZ_NODISCARD az_context
77 az_context_create_with_value(az_context const* parent, void const* key, void const* value);
78 
84 void az_context_cancel(az_context* ref_context);
85 
92 AZ_NODISCARD int64_t az_context_get_expiration(az_context const* context);
93 
101 AZ_NODISCARD bool az_context_has_expired(az_context const* context, int64_t current_time);
102 
116 AZ_NODISCARD az_result
117 az_context_get_value(az_context const* context, void const* key, void const** out_value);
118 
119 #include <azure/core/_az_cfg_suffix.h>
120 
121 #endif // _az_CONTEXT_H
az_result.h
Definition of az_result and helper functions.
az_result
az_result
The type represents the various success and error conditions.
Definition: az_result.h:53
az_context_application
az_context az_context_application
The application root az_context instances.
az_context_get_value
AZ_NODISCARD az_result az_context_get_value(az_context const *context, void const *key, void const **out_value)
Walks up this az_context node's parents until it find a node whose key matches the specified key and ...
az_context_cancel
void az_context_cancel(az_context *ref_context)
Cancels the specified az_context node; this cancels all the child nodes as well.
az_context_get_expiration
AZ_NODISCARD int64_t az_context_get_expiration(az_context const *context)
Returns the soonest expiration time of this az_context node or any of its parent nodes.
az_context_create_with_value
AZ_NODISCARD az_context az_context_create_with_value(az_context const *parent, void const *key, void const *value)
Creates a new key/value az_context node that is a child of the specified parent.
az_context_has_expired
AZ_NODISCARD bool az_context_has_expired(az_context const *context, int64_t current_time)
Returns true if this az_context node or any of its parent nodes' expiration is before the current_tim...
az_context
A context is a node within a tree that represents expiration times and key/value pairs.
Definition: az_context.h:37
az_context_create_with_expiration
AZ_NODISCARD az_context az_context_create_with_expiration(az_context const *parent, int64_t expiration)
Creates a new expiring az_context node that is a child of the specified parent.