source: rtems/cpukit/include/rtems/status-checks.h @ 2afb22b

5
Last change on this file since 2afb22b was 2a21c80, checked in by Chris Johns <chrisj@…>, on 12/27/17 at 02:43:02

Include rtems/bspIo.h for printk.

Closes @3267.

  • Property mode set to 100644
File size: 8.5 KB
Line 
1/**
2 * @file
3 *
4 * @brief Header File for Status Checks
5 *
6 * @warning Do not include this file in other header files.  Use it only in
7 * source files.
8 */
9
10/*
11 * Copyright (c) 2008
12 * Embedded Brains GmbH
13 * Obere Lagerstr. 30
14 * D-82178 Puchheim
15 * Germany
16 * rtems@embedded-brains.de
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 */
22
23#ifndef RTEMS_STATUS_CHECKS_H
24#define RTEMS_STATUS_CHECKS_H
25
26#include <rtems/bspIo.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif /* __cplusplus */
31
32/**
33 * @defgroup rtems_status_checks Status Checks
34 */
35/**@{**/
36
37/**
38 * @name Print Macros
39 */
40/**@{**/
41
42/**
43 * @brief General purpose debug print macro.
44 */
45#ifdef DEBUG
46  #ifndef RTEMS_DEBUG_PRINT
47    #ifdef RTEMS_STATUS_CHECKS_USE_PRINTK
48      #define RTEMS_DEBUG_PRINT( fmt, ...) \
49        printk( "%s: " fmt, __func__, ##__VA_ARGS__)
50    #else /* RTEMS_STATUS_CHECKS_USE_PRINTK */
51      #include <stdio.h>
52      #define RTEMS_DEBUG_PRINT( fmt, ...) \
53        printf( "%s: " fmt, __func__, ##__VA_ARGS__)
54    #endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */
55  #endif /* RTEMS_DEBUG_PRINT */
56#else /* DEBUG */
57  #ifdef RTEMS_DEBUG_PRINT
58    #warning RTEMS_DEBUG_PRINT was defined, but DEBUG was undefined
59    #undef RTEMS_DEBUG_PRINT
60  #endif /* RTEMS_DEBUG_PRINT */
61  #define RTEMS_DEBUG_PRINT( fmt, ...)
62#endif /* DEBUG */
63
64/**
65 * @brief Macro to print debug messages for successful operations.
66 */
67#define RTEMS_DEBUG_OK( msg) \
68  RTEMS_DEBUG_PRINT( "Ok: %s\n", msg)
69
70/**
71 * @brief General purpose system log print macro.
72 */
73#ifndef RTEMS_SYSLOG_PRINT
74  #ifdef RTEMS_STATUS_CHECKS_USE_PRINTK
75    #define RTEMS_SYSLOG_PRINT( fmt, ...) \
76      printk( fmt, ##__VA_ARGS__)
77  #else /* RTEMS_STATUS_CHECKS_USE_PRINTK */
78    #include <stdio.h>
79    #define RTEMS_SYSLOG_PRINT( fmt, ...) \
80      printf( fmt, ##__VA_ARGS__)
81  #endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */
82#endif /* RTEMS_SYSLOG_PRINT */
83
84/**
85 * @brief General purpose system log macro.
86 */
87#define RTEMS_SYSLOG( fmt, ...) \
88  RTEMS_SYSLOG_PRINT( "%s: " fmt, __func__, ##__VA_ARGS__)
89
90/**
91 * @brief General purpose system log macro for warnings.
92 */
93#define RTEMS_SYSLOG_WARNING( fmt, ...) \
94  RTEMS_SYSLOG( "Warning: " fmt, ##__VA_ARGS__)
95
96/**
97 * @brief Macro to generate a system log warning message if the status code @a
98 * sc is not equal to @ref RTEMS_SUCCESSFUL.
99 */
100#define RTEMS_SYSLOG_WARNING_SC( sc, msg) \
101  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
102    RTEMS_SYSLOG_WARNING( "SC = %i: %s\n", (int) sc, msg); \
103  }
104
105/**
106 * @brief General purpose system log macro for errors.
107 */
108#define RTEMS_SYSLOG_ERROR( fmt, ...) \
109  RTEMS_SYSLOG( "Error: " fmt, ##__VA_ARGS__)
110
111/**
112 * @brief Macro for system log error messages with status code.
113 */
114#define RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg) \
115  RTEMS_SYSLOG_ERROR( "SC = %i: %s\n", (int) sc, msg);
116
117/**
118 * @brief Macro for system log error messages with return value.
119 */
120#define RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg) \
121  RTEMS_SYSLOG_ERROR( "RV = %i: %s\n", (int) rv, msg);
122
123/**
124 * @brief Macro to generate a system log error message if the status code @a
125 * sc is not equal to @ref RTEMS_SUCCESSFUL.
126 */
127#define RTEMS_SYSLOG_ERROR_SC( sc, msg) \
128  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
129    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
130  }
131
132/**
133 * @brief Macro to generate a system log error message if the return value @a
134 * rv is less than zero.
135 */
136#define RTEMS_SYSLOG_ERROR_RV( rv, msg) \
137  if ((int) (rv) < 0) { \
138    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
139  }
140
141/** @} */
142
143/**
144 * @name Check Macros
145 */
146/**@{**/
147
148/**
149 * @brief Prints message @a msg and returns with status code @a sc if the status
150 * code @a sc is not equal to @ref RTEMS_SUCCESSFUL.
151 */
152#define RTEMS_CHECK_SC( sc, msg) \
153  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
154    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
155    return (rtems_status_code) sc; \
156  } else { \
157    RTEMS_DEBUG_OK( msg); \
158  }
159
160/**
161 * @brief Prints message @a msg and returns with a return value of negative @a sc
162 * if the status code @a sc is not equal to @ref RTEMS_SUCCESSFUL.
163 */
164#define RTEMS_CHECK_SC_RV( sc, msg) \
165  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
166    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
167    return -((int) (sc)); \
168  } else { \
169    RTEMS_DEBUG_OK( msg); \
170  }
171
172/**
173 * @brief Prints message @a msg and returns if the status code @a sc is not equal
174 * to @ref RTEMS_SUCCESSFUL.
175 */
176#define RTEMS_CHECK_SC_VOID( sc, msg) \
177  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
178    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
179    return; \
180  } else { \
181    RTEMS_DEBUG_OK( msg); \
182  }
183
184/**
185 * @brief Prints message @a msg and delete the current task if the status code
186 * @a sc is not equal to @ref RTEMS_SUCCESSFUL.
187 */
188#define RTEMS_CHECK_SC_TASK( sc, msg) \
189  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
190    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
191    (void) rtems_task_delete( RTEMS_SELF); \
192    return; \
193  } else { \
194    RTEMS_DEBUG_OK( msg); \
195  }
196
197/**
198 * @brief Prints message @a msg and returns with a return value @a rv if the
199 * return value @a rv is less than zero.
200 */
201#define RTEMS_CHECK_RV( rv, msg) \
202  if ((int) (rv) < 0) { \
203    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
204    return (int) rv; \
205  } else { \
206    RTEMS_DEBUG_OK( msg); \
207  }
208
209/**
210 * @brief Prints message @a msg and returns with status code @ref RTEMS_IO_ERROR
211 * if the return value @a rv is less than zero.
212 */
213#define RTEMS_CHECK_RV_SC( rv, msg) \
214  if ((int) (rv) < 0) { \
215    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
216    return RTEMS_IO_ERROR; \
217  } else { \
218    RTEMS_DEBUG_OK( msg); \
219  }
220
221/**
222 * @brief Prints message @a msg and returns if the return value @a rv is less
223 * than zero.
224 */
225#define RTEMS_CHECK_RV_VOID( rv, msg) \
226  if ((int) (rv) < 0) { \
227    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
228    return; \
229  } else { \
230    RTEMS_DEBUG_OK( msg); \
231  }
232
233/**
234 * @brief Prints message @a msg and delete the current task if the return value
235 * @a rv is less than zero.
236 */
237#define RTEMS_CHECK_RV_TASK( rv, msg) \
238  if ((int) (rv) < 0) { \
239    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
240    (void) rtems_task_delete( RTEMS_SELF); \
241    return; \
242  } else { \
243    RTEMS_DEBUG_OK( msg); \
244  }
245
246/** @} */
247
248/**
249 * @name Cleanup Macros
250 */
251/**@{**/
252
253/**
254 * @brief Prints message @a msg and jumps to @a label if the status code @a sc
255 * is not equal to @ref RTEMS_SUCCESSFUL.
256 */
257#define RTEMS_CLEANUP_SC( sc, label, msg) \
258  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
259    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
260    goto label; \
261  } else { \
262    RTEMS_DEBUG_OK( msg); \
263  }
264
265/**
266 * @brief Prints message @a msg and jumps to @a label if the status code @a sc
267 * is not equal to @ref RTEMS_SUCCESSFUL.  The return value variable @a rv will
268 * be set to a negative @a sc in this case.
269 */
270#define RTEMS_CLEANUP_SC_RV( sc, rv, label, msg) \
271  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
272    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
273    rv = -((int) (sc)); \
274    goto label; \
275  } else { \
276    RTEMS_DEBUG_OK( msg); \
277  }
278
279/**
280 * @brief Prints message @a msg and jumps to @a label if the return value @a rv
281 * is less than zero.
282 */
283#define RTEMS_CLEANUP_RV( rv, label, msg) \
284  if ((int) (rv) < 0) { \
285    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
286    goto label; \
287  } else { \
288    RTEMS_DEBUG_OK( msg); \
289  }
290
291/**
292 * @brief Prints message @a msg and jumps to @a label if the return value @a rv
293 * is less than zero.  The status code variable @a sc will be set to @ref
294 * RTEMS_IO_ERROR in this case.
295 */
296#define RTEMS_CLEANUP_RV_SC( rv, sc, label, msg) \
297  if ((int) (rv) < 0) { \
298    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
299    sc = RTEMS_IO_ERROR; \
300    goto label; \
301  } else { \
302    RTEMS_DEBUG_OK( msg); \
303  }
304
305/**
306 * @brief Prints message @a msg and jumps to @a label.
307 */
308#define RTEMS_DO_CLEANUP( label, msg) \
309  do { \
310    RTEMS_SYSLOG_ERROR( msg); \
311    goto label; \
312  } while (0)
313
314/**
315 * @brief Prints message @a msg, sets the status code variable @a sc to @a val
316 * and jumps to @a label.
317 */
318#define RTEMS_DO_CLEANUP_SC( val, sc, label, msg) \
319  do { \
320    sc = (rtems_status_code) val; \
321    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
322    goto label; \
323  } while (0)
324
325/**
326 * @brief Prints message @a msg, sets the return value variable @a rv to @a val
327 * and jumps to @a label.
328 */
329#define RTEMS_DO_CLEANUP_RV( val, rv, label, msg) \
330  do { \
331    rv = (int) val; \
332    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
333    goto label; \
334  } while (0)
335
336/** @} */
337
338/** @} */
339
340#ifdef __cplusplus
341}
342#endif /* __cplusplus */
343
344#endif /* RTEMS_STATUS_CHECKS_H */
Note: See TracBrowser for help on using the repository browser.