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

4.104.11
Last change on this file since 06c3530 was 06c3530, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on Oct 10, 2008 at 3:56:32 PM

libnetworking/rtems/rtems_glue.c: Copy nothing if rtems_bsdnet_parse_driver_name() if namep is NULL.

include/rtems/status-checks.h: Added prefix "RTEMS" for all macros. Doxygen style comments. Cleanup.

  • 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 found in the file
19 * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE.
20 */
21
22#ifndef RTEMS_STATUS_CHECKS_H
23#define RTEMS_STATUS_CHECKS_H
24
25#ifdef __cplusplus
26extern "C" {
27#endif /* __cplusplus */
28
29/**
30 * @defgroup rtems_status_checks Status Checks
31 *
32 * @{
33 */
34
35/**
36 * @name Print Macros
37 *
38 * @{
39 */
40
41/**
42 * @brief General purpose debug print macro.
43 */
44#ifdef DEBUG
45  #ifndef RTEMS_DEBUG_PRINT
46    #ifdef RTEMS_STATUS_CHECKS_USE_PRINTK
47      #define RTEMS_DEBUG_PRINT( fmt, ...) \
48        printk( "%s: " fmt, __func__, ##__VA_ARGS__)
49    #else /* RTEMS_STATUS_CHECKS_USE_PRINTK */
50      #include <stdio.h>
51      #define RTEMS_DEBUG_PRINT( fmt, ...) \
52        printf( "%s: " fmt, __func__, ##__VA_ARGS__)
53    #endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */
54  #endif /* RTEMS_DEBUG_PRINT */
55#else /* DEBUG */
56  #ifdef RTEMS_DEBUG_PRINT
57    #warning RTEMS_DEBUG_PRINT was defined, but DEBUG was undefined
58    #undef RTEMS_DEBUG_PRINT
59  #endif /* RTEMS_DEBUG_PRINT */
60  #define RTEMS_DEBUG_PRINT( fmt, ...)
61#endif /* DEBUG */
62
63/**
64 * @brief Macro to print debug messages for successful operations.
65 */
66#define RTEMS_DEBUG_OK( msg) \
67  RTEMS_DEBUG_PRINT( "Ok: %s\n", msg)
68
69/**
70 * @brief General purpose system log print macro.
71 */
72#ifndef RTEMS_SYSLOG_PRINT
73  #ifdef RTEMS_STATUS_CHECKS_USE_PRINTK
74    #define RTEMS_SYSLOG_PRINT( fmt, ...) \
75      printk( fmt, ##__VA_ARGS__)
76  #else /* RTEMS_STATUS_CHECKS_USE_PRINTK */
77    #include <stdio.h>
78    #define RTEMS_SYSLOG_PRINT( fmt, ...) \
79      printf( fmt, ##__VA_ARGS__)
80  #endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */
81#endif /* RTEMS_SYSLOG_PRINT */
82
83/**
84 * @brief General purpose system log macro.
85 */
86#define RTEMS_SYSLOG( fmt, ...) \
87  RTEMS_SYSLOG_PRINT( "%s: " fmt, __func__, ##__VA_ARGS__)
88
89/**
90 * @brief General purpose system log macro for warnings.
91 */
92#define RTEMS_SYSLOG_WARNING( fmt, ...) \
93  RTEMS_SYSLOG( "Warning: " fmt, ##__VA_ARGS__)
94
95/**
96 * @brief Macro to generate a system log warning message if the status code @a
97 * sc is not equal to @ref RTEMS_SUCCESSFUL.
98 */
99#define RTEMS_SYSLOG_WARNING_SC( sc, msg) \
100  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
101    RTEMS_SYSLOG_WARNING( "SC = %i: %s\n", (int) sc, msg); \
102  }
103
104/**
105 * @brief General purpose system log macro for errors.
106 */
107#define RTEMS_SYSLOG_ERROR( fmt, ...) \
108  RTEMS_SYSLOG( "Error: " fmt, ##__VA_ARGS__)
109
110/**
111 * @brief Macro for system log error messages with status code.
112 */
113#define RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg) \
114  RTEMS_SYSLOG_ERROR( "SC = %i: %s\n", (int) sc, msg);
115
116/**
117 * @brief Macro for system log error messages with return value.
118 */
119#define RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg) \
120  RTEMS_SYSLOG_ERROR( "RV = %i: %s\n", (int) rv, msg);
121
122/**
123 * @brief Macro to generate a system log error message if the status code @a
124 * sc is not equal to @ref RTEMS_SUCCESSFUL.
125 */
126#define RTEMS_SYSLOG_ERROR_SC( sc, msg) \
127  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
128    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
129  }
130
131/**
132 * @brief Macro to generate a system log error message if the return value @a
133 * rv is less than zero.
134 */
135#define RTEMS_SYSLOG_ERROR_RV( rv, msg) \
136  if ((int) (rv) < 0) { \
137    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
138  }
139
140/** @} */
141
142/**
143 * @name Check Macros
144 *
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/**
255 * @brief Prints message @a msg and jumps to @a label if the status code @a sc
256 * is not equal to @ref RTEMS_SUCCESSFUL.
257 */
258#define RTEMS_CLEANUP_SC( sc, label, msg) \
259  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
260    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
261    goto label; \
262  } else { \
263    RTEMS_DEBUG_OK( msg); \
264  }
265
266/**
267 * @brief Prints message @a msg and jumps to @a label if the status code @a sc
268 * is not equal to @ref RTEMS_SUCCESSFUL.  The return value variable @a rv will
269 * be set to a negative @a sc in this case.
270 */
271#define RTEMS_CLEANUP_SC_RV( sc, rv, label, msg) \
272  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
273    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
274    rv = -((int) (sc)); \
275    goto label; \
276  } else { \
277    RTEMS_DEBUG_OK( msg); \
278  }
279
280/**
281 * @brief Prints message @a msg and jumps to @a label if the return value @a rv
282 * is less than zero.
283 */
284#define RTEMS_CLEANUP_RV( rv, label, msg) \
285  if ((int) (rv) < 0) { \
286    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
287    goto label; \
288  } else { \
289    RTEMS_DEBUG_OK( msg); \
290  }
291
292/**
293 * @brief Prints message @a msg and jumps to @a label if the return value @a rv
294 * is less than zero.  The status code variable @a sc will be set to @ref
295 * RTEMS_IO_ERROR in this case.
296 */
297#define RTEMS_CLEANUP_RV_SC( rv, sc, label, msg) \
298  if ((int) (rv) < 0) { \
299    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
300    sc = RTEMS_IO_ERROR; \
301    goto label; \
302  } else { \
303    RTEMS_DEBUG_OK( msg); \
304  }
305
306/**
307 * @brief Prints message @a msg and jumps to @a label.
308 */
309#define RTEMS_DO_CLEANUP( label, msg) \
310  do { \
311    RTEMS_SYSLOG_ERROR( msg); \
312    goto label; \
313  } while (0)
314
315/**
316 * @brief Prints message @a msg, sets the status code variable @a sc to @a val
317 * and jumps to @a label.
318 */
319#define RTEMS_DO_CLEANUP_SC( val, sc, label, msg) \
320  do { \
321    sc = (rtems_status_code) val; \
322    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
323    goto label; \
324  } while (0)
325
326/**
327 * @brief Prints message @a msg, sets the return value variable @a rv to @a val
328 * and jumps to @a label.
329 */
330#define RTEMS_DO_CLEANUP_RV( val, rv, label, msg) \
331  do { \
332    rv = (int) val; \
333    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
334    goto label; \
335  } while (0)
336
337/** @} */
338
339/** @} */
340
341#ifdef __cplusplus
342}
343#endif /* __cplusplus */
344
345#endif /* RTEMS_STATUS_CHECKS_H */
Note: See TracBrowser for help on using the repository browser.