Zycore  1.2.0.0
Status.h
Go to the documentation of this file.
1 /***************************************************************************************************
2 
3  Zyan Core Library (Zyan-C)
4 
5  Original Author : Florian Bernd, Joel Hoener
6 
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24 
25 ***************************************************************************************************/
26 
32 #ifndef ZYCORE_STATUS_H
33 #define ZYCORE_STATUS_H
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #include <Zycore/Types.h>
40 
41 /* ============================================================================================== */
42 /* Enums and types */
43 /* ============================================================================================== */
44 
48 typedef ZyanU32 ZyanStatus;
49 
50 /* ============================================================================================== */
51 /* Macros */
52 /* ============================================================================================== */
53 
54 /* ---------------------------------------------------------------------------------------------- */
55 /* Definition */
56 /* ---------------------------------------------------------------------------------------------- */
57 
67 #define ZYAN_MAKE_STATUS(error, module, code) \
68  (ZyanStatus)((((error) & 0x01u) << 31u) | (((module) & 0x7FFu) << 20u) | ((code) & 0xFFFFFu))
69 
70 /* ---------------------------------------------------------------------------------------------- */
71 /* Checks */
72 /* ---------------------------------------------------------------------------------------------- */
73 
81 #define ZYAN_SUCCESS(status) \
82  (!((status) & 0x80000000u))
83 
91 #define ZYAN_FAILED(status) \
92  ((status) & 0x80000000u)
93 
99 #define ZYAN_CHECK(status) \
100  do \
101  { \
102  const ZyanStatus status_047620348 = (status); \
103  if (!ZYAN_SUCCESS(status_047620348)) \
104  { \
105  return status_047620348; \
106  } \
107  } while (0)
108 
109 /* ---------------------------------------------------------------------------------------------- */
110 /* Information */
111 /* ---------------------------------------------------------------------------------------------- */
112 
120 #define ZYAN_STATUS_MODULE(status) \
121  (((status) >> 20) & 0x7FFu)
122 
130 #define ZYAN_STATUS_CODE(status) \
131  ((status) & 0xFFFFFu)
132 
133 /* ============================================================================================== */
134 /* Status codes */
135 /* ============================================================================================== */
136 
137 /* ---------------------------------------------------------------------------------------------- */
138 /* Module IDs */
139 /* ---------------------------------------------------------------------------------------------- */
140 
144 #define ZYAN_MODULE_ZYCORE 0x001u
145 
149 #define ZYAN_MODULE_ARGPARSE 0x003u
150 
154 #define ZYAN_MODULE_USER 0x3FFu
155 
156 /* ---------------------------------------------------------------------------------------------- */
157 /* Status codes (general purpose) */
158 /* ---------------------------------------------------------------------------------------------- */
159 
163 #define ZYAN_STATUS_SUCCESS \
164  ZYAN_MAKE_STATUS(0u, ZYAN_MODULE_ZYCORE, 0x00u)
165 
169 #define ZYAN_STATUS_FAILED \
170  ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x01u)
171 
175 #define ZYAN_STATUS_TRUE \
176  ZYAN_MAKE_STATUS(0u, ZYAN_MODULE_ZYCORE, 0x02u)
177 
181 #define ZYAN_STATUS_FALSE \
182  ZYAN_MAKE_STATUS(0u, ZYAN_MODULE_ZYCORE, 0x03u)
183 
187 #define ZYAN_STATUS_INVALID_ARGUMENT \
188  ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x04u)
189 
193 #define ZYAN_STATUS_INVALID_OPERATION \
194  ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x05u)
195 
199 #define ZYAN_STATUS_ACCESS_DENIED \
200  ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x06u)
201 
205 #define ZYAN_STATUS_NOT_FOUND \
206  ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x07u)
207 
211 #define ZYAN_STATUS_OUT_OF_RANGE \
212  ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x08u)
213 
217 #define ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE \
218  ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x09u)
219 
223 #define ZYAN_STATUS_NOT_ENOUGH_MEMORY \
224  ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x0Au)
225 
229 #define ZYAN_STATUS_BAD_SYSTEMCALL \
230  ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x0Bu)
231 
235 #define ZYAN_STATUS_OUT_OF_RESOURCES \
236  ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x0Cu)
237 
242 #define ZYAN_STATUS_MISSING_DEPENDENCY \
243  ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x0Du)
244 
245 /* ---------------------------------------------------------------------------------------------- */
246 /* Status codes (arg parse) */
247 /* ---------------------------------------------------------------------------------------------- */
248 
252 #define ZYAN_STATUS_ARG_NOT_UNDERSTOOD \
253  ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x00u)
254 
258 #define ZYAN_STATUS_TOO_FEW_ARGS \
259  ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x01u)
260 
264 #define ZYAN_STATUS_TOO_MANY_ARGS \
265  ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x02u)
266 
270 #define ZYAN_STATUS_ARG_MISSES_VALUE \
271  ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x03u)
272 
276 #define ZYAN_STATUS_REQUIRED_ARG_MISSING \
277  ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x04u)
278 
279 /* ---------------------------------------------------------------------------------------------- */
280 
281 /* ============================================================================================== */
282 
283 #ifdef __cplusplus
284 }
285 #endif
286 
287 #endif /* ZYCORE_STATUS_H */
ZyanU32 ZyanStatus
Definition: Status.h:48