nros C++ API
Lightweight ROS 2 client for embedded real-time systems (C++ headers)
Loading...
Searching...
No Matches
nros.hpp
Go to the documentation of this file.
1// nros-cpp: Umbrella header
2// Include this single header to get the full nros C++ API.
3//
4// Freestanding C++ compatible — no STL, no exceptions, no RTTI required.
5
12#ifndef NROS_CPP_HPP
13#define NROS_CPP_HPP
14
15// Phase 118.D — pull cbindgen-generated FFI before any wrapper hpp so
16// `nros/qos.hpp`'s `#ifndef NROS_CPP_FFI_H` guard skips its local
17// fallback definitions in favor of the canonical types.
18#include "nros_cpp_ffi.h"
19
20#include "nros/log.hpp"
21#include "nros/result.hpp"
22#include "nros/qos.hpp"
23#include "nros/options.hpp"
24#include "nros/future.hpp"
25#include "nros/stream.hpp"
26// Phase 84.G8: node.hpp no longer pulls in the heavy entity headers —
27// each entity header carries its own out-of-line `Node::create_X<>()`
28// template definition. The umbrella pulls in every entity explicitly so
29// `#include <nros/nros.hpp>` still yields the full API.
30#include "nros/node.hpp"
31#include "nros/publisher.hpp"
32#include "nros/subscription.hpp"
33#include "nros/service.hpp"
34#include "nros/client.hpp"
37#include "nros/polling_action_server.hpp"
38#include "nros/polling_action_client.hpp"
39#include "nros/parameter.hpp"
40#include "nros/tick_ctx.hpp"
41#include "nros/lifecycle.hpp"
42
43namespace nros {
44
51inline void* global_handle() {
52 if (!Node::global_initialized()) return nullptr;
53 return Node::global_storage();
54}
55
64 if (!Node::global_initialized()) {
66 }
67 return Result(nros_cpp_spin_once(Node::global_storage(), timeout_ms));
68}
69
78inline Result spin() {
79 if (!Node::global_initialized()) {
81 }
83 while (ok()) {
84 last = Result(nros_cpp_spin_once(Node::global_storage(), 10));
85 if (!last.ok()) return last;
86 }
87 return last;
88}
89
99 if (!Node::global_initialized()) {
101 }
102 uint32_t elapsed = 0;
104 while (elapsed < duration_ms) {
105 int32_t remaining = static_cast<int32_t>(duration_ms - elapsed);
107 last = Result(nros_cpp_spin_once(Node::global_storage(), timeout));
108 if (!last.ok()) return last;
109 elapsed += static_cast<uint32_t>(timeout);
110 }
111 return last;
112}
113
114} // namespace nros
115
116#ifdef NROS_CPP_STD
117#include "nros/std_compat.hpp"
118#endif
119
120#endif // NROS_CPP_HPP
nros::ActionClient<A> — typed action client.
nros::ActionServer<A> — typed action server.
Definition future.hpp:40
Definition result.hpp:87
static constexpr Result success()
Named constructors.
Definition result.hpp:109
nros::Client<S> — typed service client.
nros::Future<T> — single-shot deferred result.
nros_cpp_ret_t nros_cpp_spin_once(void *handle, int32_t timeout_ms)
Definition nros.hpp:43
Result spin()
Definition nros.hpp:78
Result spin_once(int32_t timeout_ms=10)
Definition nros.hpp:63
bool ok()
Check if the nros session is initialized.
Definition node.hpp:842
void * global_handle()
Definition nros.hpp:51
nros::Node and global session helpers.
nros::Publisher<M> — typed topic publisher.
nros::QoS — full DDS-shaped QoS settings (Phase 108.B.7).
nros::Result, nros::ErrorCode, and the NROS_TRY macro.
nros::Service<S> — typed service server.
NROS_CPP_STD opt-in conveniences — std::function, std::string, std::chrono overloads.
nros::Stream<T> — multi-shot message receiver.
nros::Subscription<M> — typed topic subscriber.