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

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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