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

4.115
Last change on this file since 0e27119 was 0e27119, checked in by Joel Sherrill <joel.sherrill@…>, on 10/11/12 at 20:52:18

Use proper 3 line form of license text

  • Property mode set to 100644
File size: 8.4 KB
RevLine 
[3210dcb]1/**
2 * @file
3 *
4 * @brief Header file for status checks.
[06c3530]5 *
6 * @warning Do not include this file in other header files.  Use it only in
7 * source files.
[3210dcb]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 *
[0e27119]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.
[3210dcb]21 */
22
23#ifndef RTEMS_STATUS_CHECKS_H
24#define RTEMS_STATUS_CHECKS_H
25
26#ifdef __cplusplus
27extern "C" {
28#endif /* __cplusplus */
29
[06c3530]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 */
[3210dcb]45#ifdef DEBUG
[06c3530]46  #ifndef RTEMS_DEBUG_PRINT
[a5d5c74]47    #ifdef RTEMS_STATUS_CHECKS_USE_PRINTK
[06c3530]48      #define RTEMS_DEBUG_PRINT( fmt, ...) \
[a5d5c74]49        printk( "%s: " fmt, __func__, ##__VA_ARGS__)
50    #else /* RTEMS_STATUS_CHECKS_USE_PRINTK */
[06c3530]51      #include <stdio.h>
52      #define RTEMS_DEBUG_PRINT( fmt, ...) \
[a5d5c74]53        printf( "%s: " fmt, __func__, ##__VA_ARGS__)
54    #endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */
[06c3530]55  #endif /* RTEMS_DEBUG_PRINT */
[3210dcb]56#else /* DEBUG */
[06c3530]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, ...)
[3210dcb]62#endif /* DEBUG */
63
[06c3530]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
[a5d5c74]74  #ifdef RTEMS_STATUS_CHECKS_USE_PRINTK
[06c3530]75    #define RTEMS_SYSLOG_PRINT( fmt, ...) \
[224aebb3]76      printk( fmt, ##__VA_ARGS__)
[a5d5c74]77  #else /* RTEMS_STATUS_CHECKS_USE_PRINTK */
[06c3530]78    #include <stdio.h>
79    #define RTEMS_SYSLOG_PRINT( fmt, ...) \
[224aebb3]80      printf( fmt, ##__VA_ARGS__)
[a5d5c74]81  #endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */
[06c3530]82#endif /* RTEMS_SYSLOG_PRINT */
[3210dcb]83
[06c3530]84/**
85 * @brief General purpose system log macro.
86 */
87#define RTEMS_SYSLOG( fmt, ...) \
88  RTEMS_SYSLOG_PRINT( "%s: " fmt, __func__, ##__VA_ARGS__)
[3210dcb]89
[06c3530]90/**
91 * @brief General purpose system log macro for warnings.
92 */
93#define RTEMS_SYSLOG_WARNING( fmt, ...) \
94  RTEMS_SYSLOG( "Warning: " fmt, ##__VA_ARGS__)
[3210dcb]95
[06c3530]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); \
[a5d5c74]103  }
[3210dcb]104
[06c3530]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  }
[3210dcb]131
[06c3530]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); \
[a5d5c74]139  }
140
[06c3530]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; \
[a5d5c74]157  } else { \
[06c3530]158    RTEMS_DEBUG_OK( msg); \
[a5d5c74]159  }
160
[06c3530]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); \
[85bca3f]168    return -((int) (sc)); \
[a5d5c74]169  } else { \
[06c3530]170    RTEMS_DEBUG_OK( msg); \
[a5d5c74]171  }
172
[06c3530]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); \
[a5d5c74]180    return; \
181  } else { \
[06c3530]182    RTEMS_DEBUG_OK( msg); \
[a5d5c74]183  }
184
[06c3530]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); \
[a5d5c74]193    return; \
194  } else { \
[06c3530]195    RTEMS_DEBUG_OK( msg); \
[a5d5c74]196  }
197
[06c3530]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; \
[a5d5c74]206  } else { \
[06c3530]207    RTEMS_DEBUG_OK( msg); \
[a5d5c74]208  }
209
[06c3530]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); \
[a5d5c74]217    return RTEMS_IO_ERROR; \
218  } else { \
[06c3530]219    RTEMS_DEBUG_OK( msg); \
[a5d5c74]220  }
221
[06c3530]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); \
[a5d5c74]229    return; \
230  } else { \
[06c3530]231    RTEMS_DEBUG_OK( msg); \
[a5d5c74]232  }
233
[06c3530]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); \
[a5d5c74]242    return; \
243  } else { \
[06c3530]244    RTEMS_DEBUG_OK( msg); \
[a5d5c74]245  }
246
[06c3530]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); \
[a5d5c74]262    goto label; \
263  } else { \
[06c3530]264    RTEMS_DEBUG_OK( msg); \
[a5d5c74]265  }
266
[06c3530]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); \
[85bca3f]275    rv = -((int) (sc)); \
[a5d5c74]276    goto label; \
277  } else { \
[06c3530]278    RTEMS_DEBUG_OK( msg); \
[a5d5c74]279  }
280
[06c3530]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); \
[a5d5c74]288    goto label; \
289  } else { \
[06c3530]290    RTEMS_DEBUG_OK( msg); \
[a5d5c74]291  }
292
[06c3530]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); \
[a5d5c74]301    sc = RTEMS_IO_ERROR; \
302    goto label; \
303  } else { \
[06c3530]304    RTEMS_DEBUG_OK( msg); \
[a5d5c74]305  }
306
[06c3530]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) \
[a5d5c74]321  do { \
[06c3530]322    sc = (rtems_status_code) val; \
323    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
[a5d5c74]324    goto label; \
325  } while (0)
326
[06c3530]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) \
[a5d5c74]332  do { \
[06c3530]333    rv = (int) val; \
334    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
[224aebb3]335    goto label; \
[a5d5c74]336  } while (0)
[3210dcb]337
[06c3530]338/** @} */
339
340/** @} */
341
[3210dcb]342#ifdef __cplusplus
343}
344#endif /* __cplusplus */
345
346#endif /* RTEMS_STATUS_CHECKS_H */
Note: See TracBrowser for help on using the repository browser.