rmw  beta1
C API providing a middleware abstraction layer which is used to implement the rest of ROS.
Classes | Macros | Typedefs | Functions
error_handling.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include "rmw/macros.h"
#include "rmw/visibility_control.h"

Go to the source code of this file.

Classes

struct  rmw_error_state_t
 Struct which encapsulates the error state set by RMW_SET_ERROR_MSG(). More...
 

Macros

#define RMW_SET_ERROR_MSG(msg)   rmw_set_error_state(msg, __FILE__, __LINE__);
 Set the error message, as well as append the current file and line number. More...
 

Typedefs

typedef struct rmw_error_state_t rmw_error_state_t
 Struct which encapsulates the error state set by RMW_SET_ERROR_MSG(). More...
 

Functions

void rmw_set_error_state (const char *error_msg, const char *file, size_t line_number)
 Set the error message, as well as the file and line on which it occurred. More...
 
bool rmw_error_is_set (void)
 Return true if the error is set, otherwise false. More...
 
const rmw_error_state_trmw_get_error_state (void)
 Return an rmw_error_state_t which was set with rmw_set_error_state(). More...
 
const char * rmw_get_error_string (void)
 Return the error message followed by , at <file>:<line>, or NULL. More...
 
const char * rmw_get_error_string_safe (void)
 Return the error message followed by , at <file>:<line> if set, else "error not set". More...
 
void rmw_reset_error (void)
 Resets the error state by clearing any previously set error state. More...
 

Macro Definition Documentation

§ RMW_SET_ERROR_MSG

#define RMW_SET_ERROR_MSG (   msg)    rmw_set_error_state(msg, __FILE__, __LINE__);

Set the error message, as well as append the current file and line number.

If an error message was previously set, and rmw_reset_error() was not called afterwards, and this library was built with RMW_REPORT_ERROR_HANDLING_ERRORS turned on, then the previously set error message will be printed to stderr. Error state storage is thread local and so all error related functions are also thread local.

Parameters
msgThe error message to be set.

Typedef Documentation

§ rmw_error_state_t

Struct which encapsulates the error state set by RMW_SET_ERROR_MSG().

Function Documentation

§ rmw_set_error_state()

void rmw_set_error_state ( const char *  error_msg,
const char *  file,
size_t  line_number 
)

Set the error message, as well as the file and line on which it occurred.

This is not meant to be used directly, but instead via the RMW_SET_ERROR_MSG(msg) macro.

The error_msg parameter is copied into the internal error storage and must be null terminated. The file parameter is not copied, but instead is assumed to be a global as it should be set to the FILE preprocessor literal when used with the RMW_SET_ERROR_MSG() macro. It should also be null terminated.

Parameters
error_msgThe error message to set.
fileThe path to the file in which the error occurred.
line_numberThe line number on which the error occurred.

§ rmw_error_is_set()

bool rmw_error_is_set ( void  )

Return true if the error is set, otherwise false.

§ rmw_get_error_state()

const rmw_error_state_t* rmw_get_error_state ( void  )

Return an rmw_error_state_t which was set with rmw_set_error_state().

The returned pointer will be NULL if no error has been set in this thread.

The returned pointer is valid until RMW_SET_ERROR_MSG, rmw_set_error_state, or rmw_reset_error are called in the same thread.

Returns
A pointer to the current error state struct.

§ rmw_get_error_string()

const char* rmw_get_error_string ( void  )

Return the error message followed by , at <file>:<line>, or NULL.

The returned pointer is valid until RMW_SET_ERROR_MSG(), rmw_set_error_state(), or rmw_reset_error() are called from the same thread.

Returns
The current formatted error string, or NULL if not set.

§ rmw_get_error_string_safe()

const char* rmw_get_error_string_safe ( void  )

Return the error message followed by , at <file>:<line> if set, else "error not set".

This function is guaranteed to return a valid c-string.

The returned pointer is valid until RMW_SET_ERROR_MSG, rmw_set_error_state, or rmw_reset_error are called in the same thread.

Returns
The current error string, with file and line number, or "error not set" if not set.

§ rmw_reset_error()

void rmw_reset_error ( void  )

Resets the error state by clearing any previously set error state.