diff options
author | Thomas Doerfler <Thomas.Doerfler@embedded-brains.de> | 2008-07-10 06:05:12 +0000 |
---|---|---|
committer | Thomas Doerfler <Thomas.Doerfler@embedded-brains.de> | 2008-07-10 06:05:12 +0000 |
commit | 3210dcb39d5d6041a8d096602e2a9cff18fba637 (patch) | |
tree | 8a3ec7d7bf7280e5c66968883c915d80c3a23571 /cpukit/include/rtems | |
parent | Restore terminal settings on exit. (diff) | |
download | rtems-3210dcb39d5d6041a8d096602e2a9cff18fba637.tar.bz2 |
Macros for status code and return value checks.
Diffstat (limited to 'cpukit/include/rtems')
-rw-r--r-- | cpukit/include/rtems/status-checks.h | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/cpukit/include/rtems/status-checks.h b/cpukit/include/rtems/status-checks.h new file mode 100644 index 0000000000..b062c97e3c --- /dev/null +++ b/cpukit/include/rtems/status-checks.h @@ -0,0 +1,176 @@ +/** + * @file + * + * @brief Header file for status checks. + */ + +/* + * Copyright (c) 2008 + * Embedded Brains GmbH + * Obere Lagerstr. 30 + * D-82178 Puchheim + * Germany + * rtems@embedded-brains.de + * + * The license and distribution terms for this file may be found in the file + * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE. + */ + +#ifndef RTEMS_STATUS_CHECKS_H +#define RTEMS_STATUS_CHECKS_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifdef DEBUG +# ifndef DEBUG_PRINT +# ifdef RTEMS_STATUS_CHECKS_USE_PRINTK +# define DEBUG_PRINT( fmt, ...) printk( "%s: " fmt, __func__, ##__VA_ARGS__) +# else /* RTEMS_STATUS_CHECKS_USE_PRINTK */ +# define DEBUG_PRINT( fmt, ...) printf( "%s: " fmt, __func__, ##__VA_ARGS__) +# endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */ +# endif /* DEBUG_PRINT */ +#else /* DEBUG */ +# define DEBUG_PRINT( fmt, ...) +#endif /* DEBUG */ + +#ifndef SYSLOG_PRINT +# ifdef RTEMS_STATUS_CHECKS_USE_PRINTK +# define SYSLOG_PRINT( fmt, ...) printk( fmt, ##__VA_ARGS__) +# else /* RTEMS_STATUS_CHECKS_USE_PRINTK */ +# define SYSLOG_PRINT( fmt, ...) printf( fmt, ##__VA_ARGS__) +# endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */ +#endif /* SYSLOG_PRINT */ + +#define SYSLOG( fmt, ...) SYSLOG_PRINT( "%s: " fmt, __func__, ##__VA_ARGS__) + +#define SYSLOG_WARNING( fmt, ...) SYSLOG_PRINT( "%s: Warning: " fmt, __func__, ##__VA_ARGS__) + +#define SYSLOG_WARNING_SC( sc, fmt, ...) \ +if ((sc) != RTEMS_SUCCESSFUL) { \ + SYSLOG_PRINT( "%s: Warning: SC = %i: " fmt "\n", __func__, sc, ##__VA_ARGS__); \ +} + +#define SYSLOG_ERROR( fmt, ...) SYSLOG_PRINT( "%s: Error: " fmt, __func__, ##__VA_ARGS__) + +#define SYSLOG_ERROR_SC( sc, fmt, ...) \ +if ((sc) != RTEMS_SUCCESSFUL) { \ + SYSLOG_PRINT( "%s: Error: SC = %i: " fmt "\n", __func__, sc, ##__VA_ARGS__); \ +} + +#define CHECK_SC( sc, hint) \ +if ((sc) != RTEMS_SUCCESSFUL) { \ + SYSLOG_ERROR( "SC = %i: %s\n", sc, hint); \ + return sc; \ +} else { \ + DEBUG_PRINT( "Ok: %s\n", hint); \ +} + +#define CHECK_SCRV( sc, hint) \ +if ((sc) != RTEMS_SUCCESSFUL) { \ + SYSLOG_ERROR( "SC = %i: %s\n", sc, hint); \ + return -(sc); \ +} else { \ + DEBUG_PRINT( "Ok: %s\n", hint); \ +} + +#define CHECK_SC_VOID( sc, hint) \ +if ((sc) != RTEMS_SUCCESSFUL) { \ + SYSLOG_ERROR( "SC = %i: %s\n", sc, hint); \ + return; \ +} else { \ + DEBUG_PRINT( "Ok: %s\n", hint); \ +} + +#define CHECK_SC_TASK( sc, hint) \ +if ((sc) != RTEMS_SUCCESSFUL) { \ + SYSLOG_ERROR( "SC = %i: %s\n", sc, hint); \ + rtems_task_delete( RTEMS_SELF); \ + return; \ +} else { \ + DEBUG_PRINT( "Ok: %s\n", hint); \ +} + +#define CHECK_RV( rv, hint) \ +if ((rv) < 0) { \ + SYSLOG_ERROR( "RV = %i: %s\n", rv, hint); \ + return rv; \ +} else { \ + DEBUG_PRINT( "Ok: %s\n", hint); \ +} + +#define CHECK_RVSC( rv, hint) \ +if ((rv) < 0) { \ + SYSLOG_ERROR( "RV = %i: %s\n", rv, hint); \ + return RTEMS_IO_ERROR; \ +} else { \ + DEBUG_PRINT( "Ok: %s\n", hint); \ +} + +#define CHECK_RV_VOID( rv, hint) \ +if ((rv) < 0) { \ + SYSLOG_ERROR( "RV = %i: %s\n", rv, hint); \ + return; \ +} else { \ + DEBUG_PRINT( "Ok: %s\n", hint); \ +} + +#define CHECK_RV_TASK( rv, hint) \ +if ((rv) < 0) { \ + SYSLOG_ERROR( "RV = %i: %s\n", rv, hint); \ + rtems_task_delete( RTEMS_SELF); \ + return; \ +} else { \ + DEBUG_PRINT( "Ok: %s\n", hint); \ +} + +#define CLEANUP_SC( sc, label, hint) \ +if ((sc) != RTEMS_SUCCESSFUL) { \ + SYSLOG_ERROR( "SC = %i: %s\n", sc, hint); \ + goto label; \ +} else { \ + DEBUG_PRINT( "Ok: %s\n", hint); \ +} + +#define CLEANUP_SCRV( sc, rv, label, hint) \ +if ((sc) != RTEMS_SUCCESSFUL) { \ + SYSLOG_ERROR( "SC = %i: %s\n", sc, hint); \ + rv = -(sc); \ + goto label; \ +} else { \ + DEBUG_PRINT( "Ok: %s\n", hint); \ +} + +#define CLEANUP_RV( rv, label, hint) \ +if ((rv) < 0) { \ + SYSLOG_ERROR( "RV = %i: %s\n", rv, hint); \ + goto label; \ +} else { \ + DEBUG_PRINT( "Ok: %s\n", hint); \ +} + +#define CLEANUP_RVSC( rv, sc, label, hint) \ +if ((rv) < 0) { \ + SYSLOG_ERROR( "RV = %i: %s\n", rv, hint); \ + sc = RTEMS_IO_ERROR; \ + goto label; \ +} else { \ + DEBUG_PRINT( "Ok: %s\n", hint); \ +} + +#define DO_CLEANUP_SC( val, sc, label, hint) \ + sc = val; \ + SYSLOG_ERROR( "SC = %i: %s\n", sc, hint); \ + goto label; + +#define DO_CLEANUP_RV( val, rv, label, hint) \ + rv = val; \ + SYSLOG_ERROR( "RV = %i: %s\n", rv, hint); \ + goto label; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* RTEMS_STATUS_CHECKS_H */ |