RTEMS  5.1
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 
47 #ifdef DEBUG
48  #ifndef RTEMS_DEBUG_PRINT
49  #ifdef RTEMS_STATUS_CHECKS_USE_PRINTK
50  #define RTEMS_DEBUG_PRINT( fmt, ...) \
51  printk( "%s: " fmt, __func__, ##__VA_ARGS__)
52  #else /* RTEMS_STATUS_CHECKS_USE_PRINTK */
53  #include <stdio.h>
54  #define RTEMS_DEBUG_PRINT( fmt, ...) \
55  printf( "%s: " fmt, __func__, ##__VA_ARGS__)
56  #endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */
57  #endif /* RTEMS_DEBUG_PRINT */
58 #else /* DEBUG */
59  #ifdef RTEMS_DEBUG_PRINT
60  #warning RTEMS_DEBUG_PRINT was defined, but DEBUG was undefined
61  #undef RTEMS_DEBUG_PRINT
62  #endif /* RTEMS_DEBUG_PRINT */
63  #define RTEMS_DEBUG_PRINT( fmt, ...)
64 #endif /* DEBUG */
65 
69 #define RTEMS_DEBUG_OK( msg) \
70  RTEMS_DEBUG_PRINT( "Ok: %s\n", msg)
71 
75 #ifndef RTEMS_SYSLOG_PRINT
76  #ifdef RTEMS_STATUS_CHECKS_USE_PRINTK
77  #define RTEMS_SYSLOG_PRINT( fmt, ...) \
78  printk( fmt, ##__VA_ARGS__)
79  #else /* RTEMS_STATUS_CHECKS_USE_PRINTK */
80  #include <stdio.h>
81  #define RTEMS_SYSLOG_PRINT( fmt, ...) \
82  printf( fmt, ##__VA_ARGS__)
83  #endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */
84 #endif /* RTEMS_SYSLOG_PRINT */
85 
89 #define RTEMS_SYSLOG( fmt, ...) \
90  RTEMS_SYSLOG_PRINT( "%s: " fmt, __func__, ##__VA_ARGS__)
91 
95 #define RTEMS_SYSLOG_WARNING( fmt, ...) \
96  RTEMS_SYSLOG( "Warning: " fmt, ##__VA_ARGS__)
97 
102 #define RTEMS_SYSLOG_WARNING_SC( sc, msg) \
103  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
104  RTEMS_SYSLOG_WARNING( "SC = %i: %s\n", (int) sc, msg); \
105  }
106 
110 #define RTEMS_SYSLOG_ERROR( fmt, ...) \
111  RTEMS_SYSLOG( "Error: " fmt, ##__VA_ARGS__)
112 
116 #define RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg) \
117  RTEMS_SYSLOG_ERROR( "SC = %i: %s\n", (int) sc, msg);
118 
122 #define RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg) \
123  RTEMS_SYSLOG_ERROR( "RV = %i: %s\n", (int) rv, msg);
124 
129 #define RTEMS_SYSLOG_ERROR_SC( sc, msg) \
130  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
131  RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
132  }
133 
138 #define RTEMS_SYSLOG_ERROR_RV( rv, msg) \
139  if ((int) (rv) < 0) { \
140  RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
141  }
142 
154 #define RTEMS_CHECK_SC( sc, msg) \
155  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
156  RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
157  return (rtems_status_code) sc; \
158  } else { \
159  RTEMS_DEBUG_OK( msg); \
160  }
161 
166 #define RTEMS_CHECK_SC_RV( sc, msg) \
167  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
168  RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
169  return -((int) (sc)); \
170  } else { \
171  RTEMS_DEBUG_OK( msg); \
172  }
173 
178 #define RTEMS_CHECK_SC_VOID( sc, msg) \
179  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
180  RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
181  return; \
182  } else { \
183  RTEMS_DEBUG_OK( msg); \
184  }
185 
190 #define RTEMS_CHECK_SC_TASK( sc, msg) \
191  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
192  RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
193  rtems_task_exit(); \
194  return; \
195  } else { \
196  RTEMS_DEBUG_OK( msg); \
197  }
198 
203 #define RTEMS_CHECK_RV( rv, msg) \
204  if ((int) (rv) < 0) { \
205  RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
206  return (int) rv; \
207  } else { \
208  RTEMS_DEBUG_OK( msg); \
209  }
210 
215 #define RTEMS_CHECK_RV_SC( rv, msg) \
216  if ((int) (rv) < 0) { \
217  RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
218  return RTEMS_IO_ERROR; \
219  } else { \
220  RTEMS_DEBUG_OK( msg); \
221  }
222 
227 #define RTEMS_CHECK_RV_VOID( rv, msg) \
228  if ((int) (rv) < 0) { \
229  RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
230  return; \
231  } else { \
232  RTEMS_DEBUG_OK( msg); \
233  }
234 
239 #define RTEMS_CHECK_RV_TASK( rv, msg) \
240  if ((int) (rv) < 0) { \
241  RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
242  rtems_task_exit(); \
243  return; \
244  } else { \
245  RTEMS_DEBUG_OK( msg); \
246  }
247 
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 
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 
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 
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 
310 #define RTEMS_DO_CLEANUP( label, msg) \
311  do { \
312  RTEMS_SYSLOG_ERROR( msg); \
313  goto label; \
314  } while (0)
315 
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 
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 
342 #ifdef __cplusplus
343 }
344 #endif /* __cplusplus */
345 
346 #endif /* RTEMS_STATUS_CHECKS_H */
Interface to Kernel Print Methods.