summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/status-checks.h
blob: f62289fe4d91336b2eab9fd1f1eb00bf790b086c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/**
 * @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 */
  #ifdef DEBUG_PRINT
    #warning DEBUG_PRINT was defined, but DEBUG was undefined
    #undef DEBUG_PRINT
  #endif /* DEBUG_PRINT */
  #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 ) \
  do { \
    sc = val; \
    SYSLOG_ERROR( "SC = %i: %s\n", sc, hint ); \
    goto label; \
  } while (0)

#define DO_CLEANUP_RV( val, rv, label, hint ) \
  do { \
    rv = val; \
    SYSLOG_ERROR( "RV = %i: %s\n", rv, hint ); \
    goto label; \
  } while (0)

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* RTEMS_STATUS_CHECKS_H */