RTEMS  5.0.0
status-checks.h
Go to the documentation of this file.
1 
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
29 extern "C" {
30 #endif /* __cplusplus */
31 
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 
67 #define RTEMS_DEBUG_OK( msg) \
68  RTEMS_DEBUG_PRINT( "Ok: %s\n", msg)
69 
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 
87 #define RTEMS_SYSLOG( fmt, ...) \
88  RTEMS_SYSLOG_PRINT( "%s: " fmt, __func__, ##__VA_ARGS__)
89 
93 #define RTEMS_SYSLOG_WARNING( fmt, ...) \
94  RTEMS_SYSLOG( "Warning: " fmt, ##__VA_ARGS__)
95 
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 
108 #define RTEMS_SYSLOG_ERROR( fmt, ...) \
109  RTEMS_SYSLOG( "Error: " fmt, ##__VA_ARGS__)
110 
114 #define RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg) \
115  RTEMS_SYSLOG_ERROR( "SC = %i: %s\n", (int) sc, msg);
116 
120 #define RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg) \
121  RTEMS_SYSLOG_ERROR( "RV = %i: %s\n", (int) rv, msg);
122 
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 
136 #define RTEMS_SYSLOG_ERROR_RV( rv, msg) \
137  if ((int) (rv) < 0) { \
138  RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
139  }
140 
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 
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 
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 
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  rtems_task_exit(); \
192  return; \
193  } else { \
194  RTEMS_DEBUG_OK( msg); \
195  }
196 
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 
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 
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 
237 #define RTEMS_CHECK_RV_TASK( rv, msg) \
238  if ((int) (rv) < 0) { \
239  RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
240  rtems_task_exit(); \
241  return; \
242  } else { \
243  RTEMS_DEBUG_OK( msg); \
244  }
245 
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 
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 
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 
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 
308 #define RTEMS_DO_CLEANUP( label, msg) \
309  do { \
310  RTEMS_SYSLOG_ERROR( msg); \
311  goto label; \
312  } while (0)
313 
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 
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 
340 #ifdef __cplusplus
341 }
342 #endif /* __cplusplus */
343 
344 #endif /* RTEMS_STATUS_CHECKS_H */
Interface to Kernel Print Methods.