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

4.11
Last change on this file since 0e27119 was 0e27119, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 11, 2012 at 8:52:18 PM

Use proper 3 line form of license text

  • 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.com/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/**
37 * @name Print Macros
38 *
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/**
150 * @brief Prints message @a msg and returns with status code @a sc if the status
151 * code @a sc is not equal to @ref RTEMS_SUCCESSFUL.
152 */
153#define RTEMS_CHECK_SC( sc, msg) \
154  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
155    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
156    return (rtems_status_code) sc; \
157  } else { \
158    RTEMS_DEBUG_OK( msg); \
159  }
160
161/**
162 * @brief Prints message @a msg and returns with a return value of negative @a sc
163 * if the status code @a sc is not equal to @ref RTEMS_SUCCESSFUL.
164 */
165#define RTEMS_CHECK_SC_RV( sc, msg) \
166  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
167    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
168    return -((int) (sc)); \
169  } else { \
170    RTEMS_DEBUG_OK( msg); \
171  }
172
173/**
174 * @brief Prints message @a msg and returns if the status code @a sc is not equal
175 * to @ref RTEMS_SUCCESSFUL.
176 */
177#define RTEMS_CHECK_SC_VOID( sc, msg) \
178  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
179    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
180    return; \
181  } else { \
182    RTEMS_DEBUG_OK( msg); \
183  }
184
185/**
186 * @brief Prints message @a msg and delete the current task if the status code
187 * @a sc is not equal to @ref RTEMS_SUCCESSFUL.
188 */
189#define RTEMS_CHECK_SC_TASK( sc, msg) \
190  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
191    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
192    (void) rtems_task_delete( RTEMS_SELF); \
193    return; \
194  } else { \
195    RTEMS_DEBUG_OK( msg); \
196  }
197
198/**
199 * @brief Prints message @a msg and returns with a return value @a rv if the
200 * return value @a rv is less than zero.
201 */
202#define RTEMS_CHECK_RV( rv, msg) \
203  if ((int) (rv) < 0) { \
204    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
205    return (int) rv; \
206  } else { \
207    RTEMS_DEBUG_OK( msg); \
208  }
209
210/**
211 * @brief Prints message @a msg and returns with status code @ref RTEMS_IO_ERROR
212 * if the return value @a rv is less than zero.
213 */
214#define RTEMS_CHECK_RV_SC( rv, msg) \
215  if ((int) (rv) < 0) { \
216    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
217    return RTEMS_IO_ERROR; \
218  } else { \
219    RTEMS_DEBUG_OK( msg); \
220  }
221
222/**
223 * @brief Prints message @a msg and returns if the return value @a rv is less
224 * than zero.
225 */
226#define RTEMS_CHECK_RV_VOID( rv, msg) \
227  if ((int) (rv) < 0) { \
228    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
229    return; \
230  } else { \
231    RTEMS_DEBUG_OK( msg); \
232  }
233
234/**
235 * @brief Prints message @a msg and delete the current task if the return value
236 * @a rv is less than zero.
237 */
238#define RTEMS_CHECK_RV_TASK( rv, msg) \
239  if ((int) (rv) < 0) { \
240    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
241    (void) rtems_task_delete( RTEMS_SELF); \
242    return; \
243  } else { \
244    RTEMS_DEBUG_OK( msg); \
245  }
246
247/** @} */
248
249/**
250 * @name Cleanup Macros
251 *
252 * @{
253 */
254
255/**
256 * @brief Prints message @a msg and jumps to @a label if the status code @a sc
257 * is not equal to @ref RTEMS_SUCCESSFUL.
258 */
259#define RTEMS_CLEANUP_SC( sc, label, msg) \
260  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
261    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
262    goto label; \
263  } else { \
264    RTEMS_DEBUG_OK( msg); \
265  }
266
267/**
268 * @brief Prints message @a msg and jumps to @a label if the status code @a sc
269 * is not equal to @ref RTEMS_SUCCESSFUL.  The return value variable @a rv will
270 * be set to a negative @a sc in this case.
271 */
272#define RTEMS_CLEANUP_SC_RV( sc, rv, label, msg) \
273  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
274    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
275    rv = -((int) (sc)); \
276    goto label; \
277  } else { \
278    RTEMS_DEBUG_OK( msg); \
279  }
280
281/**
282 * @brief Prints message @a msg and jumps to @a label if the return value @a rv
283 * is less than zero.
284 */
285#define RTEMS_CLEANUP_RV( rv, label, msg) \
286  if ((int) (rv) < 0) { \
287    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
288    goto label; \
289  } else { \
290    RTEMS_DEBUG_OK( msg); \
291  }
292
293/**
294 * @brief Prints message @a msg and jumps to @a label if the return value @a rv
295 * is less than zero.  The status code variable @a sc will be set to @ref
296 * RTEMS_IO_ERROR in this case.
297 */
298#define RTEMS_CLEANUP_RV_SC( rv, sc, label, msg) \
299  if ((int) (rv) < 0) { \
300    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
301    sc = RTEMS_IO_ERROR; \
302    goto label; \
303  } else { \
304    RTEMS_DEBUG_OK( msg); \
305  }
306
307/**
308 * @brief Prints message @a msg and jumps to @a label.
309 */
310#define RTEMS_DO_CLEANUP( label, msg) \
311  do { \
312    RTEMS_SYSLOG_ERROR( msg); \
313    goto label; \
314  } while (0)
315
316/**
317 * @brief Prints message @a msg, sets the status code variable @a sc to @a val
318 * and jumps to @a label.
319 */
320#define RTEMS_DO_CLEANUP_SC( val, sc, label, msg) \
321  do { \
322    sc = (rtems_status_code) val; \
323    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
324    goto label; \
325  } while (0)
326
327/**
328 * @brief Prints message @a msg, sets the return value variable @a rv to @a val
329 * and jumps to @a label.
330 */
331#define RTEMS_DO_CLEANUP_RV( val, rv, label, msg) \
332  do { \
333    rv = (int) val; \
334    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
335    goto label; \
336  } while (0)
337
338/** @} */
339
340/** @} */
341
342#ifdef __cplusplus
343}
344#endif /* __cplusplus */
345
346#endif /* RTEMS_STATUS_CHECKS_H */
Note: See TracBrowser for help on using the repository browser.