RKH
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rkhassert.h
Go to the documentation of this file.
1 /*
2  * --------------------------------------------------------------------------
3  *
4  * Framework RKH
5  * -------------
6  *
7  * State-machine framework for reactive embedded systems
8  *
9  * Copyright (C) 2010 Leandro Francucci.
10  * All rights reserved. Protected by international copyright laws.
11  *
12  *
13  * RKH is free software: you can redistribute it and/or modify it under the
14  * terms of the GNU General Public License as published by the Free Software
15  * Foundation, either version 3 of the License, or (at your option) any
16  * later version.
17  *
18  * RKH is distributed in the hope that it will be useful, but WITHOUT ANY
19  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21  * more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with RKH, see copying.txt file.
25  *
26  * Contact information:
27  * RKH web site: http://sourceforge.net/projects/rkh-reactivesys/
28  * e-mail: francuccilea@gmail.com
29  * ---------------------------------------------------------------------------
30  */
31 
57 /* -------------------------- Development history -------------------------- */
58 /*
59  * 2015.10.24 LeFr v2.4.05 Initial version
60  */
61 
62 /* -------------------------------- Authors -------------------------------- */
63 /*
64  * LeFr Leandro Francucci francuccilea@gmail.com
65  */
66 
67 /* --------------------------------- Notes --------------------------------- */
68 /* --------------------------------- Module -------------------------------- */
69 #ifndef __RKHASSERT_H__
70 #define __RKHASSERT_H__
71 
72 /* ----------------------------- Include files ----------------------------- */
73 #include "rkhcfg.h"
74 
75 /* ---------------------- External C language linkage ---------------------- */
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79 
80 /* --------------------------------- Macros -------------------------------- */
81 #if RKH_CFG_FWK_ASSERT_EN == RKH_ENABLED
82 
91  #define RKH_MODULE_NAME(__fname) \
92  static RKHROM char *const m_name = # __fname;
93 
101  #define RKH_THIS_MODULE \
102  static RKHROM char *const m_name = __FILE__;
103 
147  #define RKH_ASSERT(exp) \
148  if ((exp)) \
149  { \
150  } \
151  else \
152  { \
153  rkh_assert(m_name, __LINE__); \
154  }
155 
169  #define RKH_ALLEGE(exp) RKH_ASSERT(exp)
170 
181  #define RKH_ERROR() rkh_assert(m_name, __LINE__)
182 
183 #else
184  #define RKH_MODULE_NAME(__fname)
185  #define RKH_THIS_MODULE
186  #define RKH_ASSERT(exp) ((void)0)
187  #define RKH_ALLEGE(exp) ((void)(exp))
188  #define RKH_ERROR() ((void)0)
189 #endif
190 
200 #define RKH_REQUIRE(exp) RKH_ASSERT(exp)
201 
211 #define RKH_ENSURE(exp) RKH_ASSERT(exp)
212 
222 #define RKH_INVARIANT(exp) RKH_ASSERT(exp)
223 
224 /* -------------------------------- Constants ------------------------------ */
225 /* ------------------------------- Data types ------------------------------ */
226 /* -------------------------- External variables --------------------------- */
227 /* -------------------------- Function prototypes -------------------------- */
228 #if RKH_CFG_FWK_ASSERT_EN == RKH_ENABLED
229 
283 void rkh_assert(const char *const file, int line);
284 #endif
285 
286 /* -------------------- External C language linkage end -------------------- */
287 #ifdef __cplusplus
288 }
289 #endif
290 
291 /* ------------------------------ Module end ------------------------------- */
292 #endif
293 
294 /* ------------------------------ End of file ------------------------------ */
RKH user configurations.
void rkh_assert(const char *const file, int line)
Callback invoked in case the condition passed to RKH_ASSERT(), RKH_REQUIRE(), RKH_ENSURE(), RKH_ERROR(), or RKH_ALLEGE() evaluates to FALSE.