S2OPC OPCUA Toolkit
Loading...
Searching...
No Matches
sopc_assert.h File Reference

Redirection of code assertions depending on user needs. Assert provides one of the following indirection for the assertion "SOPC_ASSERT" macro, depending on build flags: More...

#include <assert.h>

Go to the source code of this file.

Macros

#define SOPC_PP_XSTR(x)
 
#define SOPC_PP_STR(x)
 
#define WITH_MINIMAL_FOOTPRINT   0
 
#define SOPC_ASSERT_CONTEXT(context)
 
#define SOPC_ASSERT   assert
 

Typedefs

typedef void SOPC_Assert_UserCallback(const char *context)
 User-defined implementation of Fail-Safe behavior. This method shall be provided when WITH_USER_ASSERT is defined. This method shall not use any code implementation that relies on SOPC_ASSERT.
 

Functions

void SOPC_Assert_Set_UserCallback (SOPC_Assert_UserCallback *callback)
 Define the user event to call in case of Assert failure.
 
void SOPC_Assert_Failure (const char *context)
 Called by SOPC_ASSERT in case of failure.
 

Detailed Description

Redirection of code assertions depending on user needs. Assert provides one of the following indirection for the assertion "SOPC_ASSERT" macro, depending on build flags:

  • WITH_NO_ASSERT The assertion is casted to void, so that tested variables are seen "used" by the compiler. This options aims at reducing code footprint by removing assertions. Note that this implies that SOPC_ASSERT calls must have no side-effect.
  • WITH_USER_ASSERT The user can call (once) SOPC_Assert_Set_UserCallback to route failed asserts its own handling. This intends at providing a safety software event to set Fail-Safe behavior. If SOPC_Assert_Set_UserCallback is not called, or if the user callback returns, the failed assertion will simply call system assert with "false"
  • Otherwise By default the system assertion is used (assert, see <assert.h>), but

Macro Definition Documentation

◆ SOPC_PP_XSTR

#define SOPC_PP_XSTR ( x)
Value:
#x

These macros are required to convert at build_time the LINE into a string

◆ SOPC_PP_STR

#define SOPC_PP_STR ( x)
Value:
#define SOPC_PP_XSTR(x)
Definition sopc_assert.h:43

◆ WITH_MINIMAL_FOOTPRINT

#define WITH_MINIMAL_FOOTPRINT   0

◆ SOPC_ASSERT_CONTEXT

#define SOPC_ASSERT_CONTEXT ( context)
Value:
__FILE__ ":" SOPC_PP_STR(__LINE__) " => " #context
#define SOPC_PP_STR(x)
Definition sopc_assert.h:44

SOPC_ASSERT_CONTEXT expands the calling context, only if WITH_MINIMAL_FOOTPRINT option is not set

◆ SOPC_ASSERT

#define SOPC_ASSERT   assert

SOPC_ASSERT implementation depends on build options (see module description)

Typedef Documentation

◆ SOPC_Assert_UserCallback

typedef void SOPC_Assert_UserCallback(const char *context)

User-defined implementation of Fail-Safe behavior. This method shall be provided when WITH_USER_ASSERT is defined. This method shall not use any code implementation that relies on SOPC_ASSERT.

Parameters
contextThe context of failed assertion. Note that when WITH_MINIMAL_FOOTPRINT option is set, this parameter will always be empty.
Postcondition
This function has no constraint return (may return or not).

Function Documentation

◆ SOPC_Assert_Set_UserCallback()

void SOPC_Assert_Set_UserCallback ( SOPC_Assert_UserCallback * callback)

Define the user event to call in case of Assert failure.

Parameters
callbackCallback event.

◆ SOPC_Assert_Failure()

void SOPC_Assert_Failure ( const char * context)

Called by SOPC_ASSERT in case of failure.

Parameters
contextThe context of failed assertion.
Postcondition
This function does not return