Azure SDK for Embedded C
az_result.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_RESULT_H
16 #define _az_RESULT_H
17 
18 #include <stdbool.h>
19 #include <stdint.h>
20 
21 #include <azure/core/_az_cfg_prefix.h>
22 
23 enum
24 {
25  _az_FACILITY_CORE = 0x1,
26  _az_FACILITY_PLATFORM = 0x2,
27  _az_FACILITY_JSON = 0x3,
28  _az_FACILITY_HTTP = 0x4,
29  _az_FACILITY_MQTT = 0x5,
30  _az_FACILITY_IOT = 0x6,
31 };
32 
33 enum
34 {
35  _az_ERROR_FLAG = (int32_t)0x80000000,
36 };
37 
38 #define _az_RESULT_MAKE_ERROR(facility, code) \
39  ((int32_t)(_az_ERROR_FLAG | ((int32_t)(facility) << 16) | (int32_t)(code)))
40 
41 #define _az_RESULT_MAKE_SUCCESS(facility, code) \
42  ((int32_t)(((int32_t)(facility) << 16) | (int32_t)(code)))
43 
44 // az_result Bits:
45 // - 31 Severity (0 - success, 1 - failure).
46 // - 16..30 Facility.
47 // - 0..15 Code.
48 
52 typedef enum
53 {
54  // === Core: Success results ====
56  AZ_OK = _az_RESULT_MAKE_SUCCESS(_az_FACILITY_CORE, 0),
57 
58  // === Core: Error results ===
60  AZ_ERROR_CANCELED = _az_RESULT_MAKE_ERROR(_az_FACILITY_CORE, 0),
61 
63  AZ_ERROR_ARG = _az_RESULT_MAKE_ERROR(_az_FACILITY_CORE, 1),
64 
66  AZ_ERROR_NOT_ENOUGH_SPACE = _az_RESULT_MAKE_ERROR(_az_FACILITY_CORE, 2),
67 
69  AZ_ERROR_NOT_IMPLEMENTED = _az_RESULT_MAKE_ERROR(_az_FACILITY_CORE, 3),
70 
72  AZ_ERROR_ITEM_NOT_FOUND = _az_RESULT_MAKE_ERROR(_az_FACILITY_CORE, 4),
73 
75  AZ_ERROR_UNEXPECTED_CHAR = _az_RESULT_MAKE_ERROR(_az_FACILITY_CORE, 5),
76 
78  AZ_ERROR_UNEXPECTED_END = _az_RESULT_MAKE_ERROR(_az_FACILITY_CORE, 6),
79 
81  AZ_ERROR_NOT_SUPPORTED = _az_RESULT_MAKE_ERROR(_az_FACILITY_CORE, 7),
82 
85  AZ_ERROR_DEPENDENCY_NOT_PROVIDED = _az_RESULT_MAKE_ERROR(_az_FACILITY_CORE, 8),
86 
87  // === Platform ===
89  AZ_ERROR_OUT_OF_MEMORY = _az_RESULT_MAKE_ERROR(_az_FACILITY_PLATFORM, 1),
90 
91  // === JSON error codes ===
93  AZ_ERROR_JSON_INVALID_STATE = _az_RESULT_MAKE_ERROR(_az_FACILITY_JSON, 1),
94 
96  AZ_ERROR_JSON_NESTING_OVERFLOW = _az_RESULT_MAKE_ERROR(_az_FACILITY_JSON, 2),
97 
99  AZ_ERROR_JSON_READER_DONE = _az_RESULT_MAKE_ERROR(_az_FACILITY_JSON, 3),
100 
101  // === HTTP error codes ===
103  AZ_ERROR_HTTP_INVALID_STATE = _az_RESULT_MAKE_ERROR(_az_FACILITY_HTTP, 1),
104 
106  AZ_ERROR_HTTP_PIPELINE_INVALID_POLICY = _az_RESULT_MAKE_ERROR(_az_FACILITY_HTTP, 2),
107 
109  AZ_ERROR_HTTP_INVALID_METHOD_VERB = _az_RESULT_MAKE_ERROR(_az_FACILITY_HTTP, 3),
110 
112  AZ_ERROR_HTTP_AUTHENTICATION_FAILED = _az_RESULT_MAKE_ERROR(_az_FACILITY_HTTP, 4),
113 
115  AZ_ERROR_HTTP_RESPONSE_OVERFLOW = _az_RESULT_MAKE_ERROR(_az_FACILITY_HTTP, 5),
116 
118  AZ_ERROR_HTTP_RESPONSE_COULDNT_RESOLVE_HOST = _az_RESULT_MAKE_ERROR(_az_FACILITY_HTTP, 6),
119 
121  AZ_ERROR_HTTP_CORRUPT_RESPONSE_HEADER = _az_RESULT_MAKE_ERROR(_az_FACILITY_HTTP, 7),
122 
124  AZ_ERROR_HTTP_END_OF_HEADERS = _az_RESULT_MAKE_ERROR(_az_FACILITY_HTTP, 8),
125 
126  // === HTTP Adapter error codes ===
128  AZ_ERROR_HTTP_ADAPTER = _az_RESULT_MAKE_ERROR(_az_FACILITY_HTTP, 9),
129 
130  // === IoT error codes ===
132  AZ_ERROR_IOT_TOPIC_NO_MATCH = _az_RESULT_MAKE_ERROR(_az_FACILITY_IOT, 1),
133 
135  AZ_ERROR_IOT_END_OF_PROPERTIES = _az_RESULT_MAKE_ERROR(_az_FACILITY_IOT, 2),
136 } az_result;
137 
146 AZ_NODISCARD AZ_INLINE bool az_result_failed(az_result result)
147 {
148  return ((int32_t)result & (int32_t)_az_ERROR_FLAG) != 0;
149 }
150 
159 AZ_NODISCARD AZ_INLINE bool az_result_succeeded(az_result result)
160 {
161  return !az_result_failed(result);
162 }
163 
164 #include <azure/core/_az_cfg_suffix.h>
165 
166 #endif // _az_RESULT_H
AZ_ERROR_HTTP_RESPONSE_COULDNT_RESOLVE_HOST
@ AZ_ERROR_HTTP_RESPONSE_COULDNT_RESOLVE_HOST
Couldn't resolve host.
Definition: az_result.h:118
AZ_ERROR_ITEM_NOT_FOUND
@ AZ_ERROR_ITEM_NOT_FOUND
Requested item was not found.
Definition: az_result.h:72
AZ_ERROR_HTTP_ADAPTER
@ AZ_ERROR_HTTP_ADAPTER
Generic error in the HTTP transport adapter implementation.
Definition: az_result.h:128
az_result
az_result
The type represents the various success and error conditions.
Definition: az_result.h:53
AZ_ERROR_CANCELED
@ AZ_ERROR_CANCELED
A context was canceled, and a function had to return before result was ready.
Definition: az_result.h:60
AZ_ERROR_JSON_INVALID_STATE
@ AZ_ERROR_JSON_INVALID_STATE
The kind of the token being read is not compatible with the expected type of the value.
Definition: az_result.h:93
az_result_succeeded
AZ_NODISCARD AZ_INLINE bool az_result_succeeded(az_result result)
Checks whether the result provided indicates a success.
Definition: az_result.h:159
az_result_failed
AZ_NODISCARD AZ_INLINE bool az_result_failed(az_result result)
Checks whether the result provided indicates a failure.
Definition: az_result.h:146
AZ_ERROR_NOT_SUPPORTED
@ AZ_ERROR_NOT_SUPPORTED
Not supported.
Definition: az_result.h:81
AZ_ERROR_DEPENDENCY_NOT_PROVIDED
@ AZ_ERROR_DEPENDENCY_NOT_PROVIDED
Definition: az_result.h:85
AZ_ERROR_HTTP_RESPONSE_OVERFLOW
@ AZ_ERROR_HTTP_RESPONSE_OVERFLOW
HTTP response overflow.
Definition: az_result.h:115
AZ_ERROR_UNEXPECTED_END
@ AZ_ERROR_UNEXPECTED_END
Unexpected end of the input data.
Definition: az_result.h:78
AZ_ERROR_IOT_TOPIC_NO_MATCH
@ AZ_ERROR_IOT_TOPIC_NO_MATCH
The IoT topic is not matching the expected format.
Definition: az_result.h:132
AZ_ERROR_NOT_IMPLEMENTED
@ AZ_ERROR_NOT_IMPLEMENTED
Requested functionality is not implemented.
Definition: az_result.h:69
AZ_ERROR_HTTP_INVALID_METHOD_VERB
@ AZ_ERROR_HTTP_INVALID_METHOD_VERB
Unknown HTTP method verb.
Definition: az_result.h:109
AZ_ERROR_ARG
@ AZ_ERROR_ARG
Input argument does not comply with the expected range of values.
Definition: az_result.h:63
AZ_ERROR_JSON_READER_DONE
@ AZ_ERROR_JSON_READER_DONE
No more JSON text left to process.
Definition: az_result.h:99
AZ_ERROR_HTTP_CORRUPT_RESPONSE_HEADER
@ AZ_ERROR_HTTP_CORRUPT_RESPONSE_HEADER
Error while parsing HTTP response header.
Definition: az_result.h:121
AZ_ERROR_IOT_END_OF_PROPERTIES
@ AZ_ERROR_IOT_END_OF_PROPERTIES
While iterating, there are no more properties to return.
Definition: az_result.h:135
AZ_ERROR_HTTP_AUTHENTICATION_FAILED
@ AZ_ERROR_HTTP_AUTHENTICATION_FAILED
Authentication failed.
Definition: az_result.h:112
AZ_ERROR_UNEXPECTED_CHAR
@ AZ_ERROR_UNEXPECTED_CHAR
Input can't be successfully parsed.
Definition: az_result.h:75
AZ_ERROR_HTTP_END_OF_HEADERS
@ AZ_ERROR_HTTP_END_OF_HEADERS
There are no more headers within the HTTP response payload.
Definition: az_result.h:124
AZ_ERROR_HTTP_PIPELINE_INVALID_POLICY
@ AZ_ERROR_HTTP_PIPELINE_INVALID_POLICY
HTTP pipeline is malformed.
Definition: az_result.h:106
AZ_ERROR_HTTP_INVALID_STATE
@ AZ_ERROR_HTTP_INVALID_STATE
The az_http_response instance is in an invalid state.
Definition: az_result.h:103
AZ_ERROR_JSON_NESTING_OVERFLOW
@ AZ_ERROR_JSON_NESTING_OVERFLOW
The JSON depth is too large.
Definition: az_result.h:96
AZ_ERROR_NOT_ENOUGH_SPACE
@ AZ_ERROR_NOT_ENOUGH_SPACE
The destination size is too small for the operation.
Definition: az_result.h:66
AZ_OK
@ AZ_OK
Success.
Definition: az_result.h:56
AZ_ERROR_OUT_OF_MEMORY
@ AZ_ERROR_OUT_OF_MEMORY
Dynamic memory allocation request was not successful.
Definition: az_result.h:89