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
42namespace nros {
43
50inline void* global_handle() {
51 if (!Node::global_initialized()) return nullptr;
52 return Node::global_storage();
53}
54
63 if (!Node::global_initialized()) {
65 }
66 return Result(nros_cpp_spin_once(Node::global_storage(), timeout_ms));
67}
68
77inline Result spin() {
78 if (!Node::global_initialized()) {
80 }
82 while (ok()) {
83 last = Result(nros_cpp_spin_once(Node::global_storage(), 10));
84 if (!last.ok()) return last;
85 }
86 return last;
87}
88
98 if (!Node::global_initialized()) {
100 }
101 uint32_t elapsed = 0;
103 while (elapsed < duration_ms) {
104 int32_t remaining = static_cast<int32_t>(duration_ms - elapsed);
106 last = Result(nros_cpp_spin_once(Node::global_storage(), timeout));
107 if (!last.ok()) return last;
108 elapsed += static_cast<uint32_t>(timeout);
109 }
110 return last;
111}
112
113} // namespace nros
114
115#ifdef NROS_CPP_STD
116#include "nros/std_compat.hpp"
117#endif
118
119#endif // NROS_CPP_HPP
nros::ActionClient<A> — typed action client.
nros::ActionServer<A> — typed action server.
Definition future.hpp:40
Definition result.hpp:52
static constexpr Result success()
Named constructors.
Definition result.hpp:74
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:42
Result spin()
Definition nros.hpp:77
Result spin_once(int32_t timeout_ms=10)
Definition nros.hpp:62
bool ok()
Check if the nros session is initialized.
Definition node.hpp:717
void * global_handle()
Definition nros.hpp:50
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.