nros C API
Lightweight ROS 2 client for embedded real-time systems
Loading...
Searching...
No Matches
check.h
Go to the documentation of this file.
1
30#ifndef NROS_CHECK_H
31#define NROS_CHECK_H
32
33#include "rclc/types.h"
34
35#ifndef RCLC_CHECK_LOG
36#if defined(RCLC_CHECK_STDIO) || (defined(__STDC_HOSTED__) && __STDC_HOSTED__)
37#include <stdio.h>
38#define RCLC_CHECK_LOG(file, line, expr, ret) \
39 printf("[nros] %s:%d %s -> %d\n", (file), (line), (expr), (int)(ret))
40#else
41/* Issue 0332 — freestanding default: no-op, no `<stdio.h>` pulled. Define
42 RCLC_CHECK_STDIO for the printf form, or RCLC_CHECK_LOG to route to a board
43 UART / RTT / nros-log. The `(void)` casts keep -Wunused quiet at the sites. */
44#define RCLC_CHECK_LOG(file, line, expr, ret) \
45 ((void)(file), (void)(line), (void)(expr), (void)(ret))
46#endif
47#endif
48
54#define RCLC_CHECK(call) \
55 do { \
56 rcl_ret_t _nros_check_ret = (call); \
57 if (_nros_check_ret != RCL_RET_OK) { \
58 RCLC_CHECK_LOG(__FILE__, __LINE__, #call, _nros_check_ret); \
59 return; \
60 } \
61 } while (0)
62
68#define RCLC_SOFTCHECK(call) \
69 do { \
70 rcl_ret_t _nros_softcheck_ret = (call); \
71 if (_nros_softcheck_ret != RCL_RET_OK) { \
72 RCLC_CHECK_LOG(__FILE__, __LINE__, #call, _nros_softcheck_ret); \
73 } \
74 } while (0)
75
80#define RCLC_CHECK_RET(call, retval) \
81 do { \
82 rcl_ret_t _nros_check_ret = (call); \
83 if (_nros_check_ret != RCL_RET_OK) { \
84 RCLC_CHECK_LOG(__FILE__, __LINE__, #call, _nros_check_ret); \
85 return (retval); \
86 } \
87 } while (0)
88
89#endif /* NROS_CHECK_H */
Shared types and constants for the nros C API.