10#ifndef NROS_CPP_EXECUTOR_HPP
11#define NROS_CPP_EXECUTOR_HPP
17#include "nros/nros_cpp_config_generated.h"
19#include "nros_cpp_ffi.h"
54 bool valid()
const {
return value_ != NROS_CPP_SHUTDOWN_CALLBACK_HANDLE_INVALID; }
57 nros_cpp_shutdown_callback_handle_t
value()
const {
return value_; }
60 nros_cpp_shutdown_callback_handle_t value_;
121 return create(out, locator, domain_id,
"nros_cpp");
131 const char* session_name) {
133 if (session_name ==
nullptr) {
141 const char* rmw = NROS_ENTRY_RMW;
143 const char* rmw =
nullptr;
146 nros_cpp_init_rmw(rmw, locator, domain_id, session_name,
nullptr, out.storage_);
148 out.initialized_ =
true;
162 uint8_t domain_id = 0,
const char* session_name =
"nros_cpp") {
163 if (session_name ==
nullptr) {
167 nros_cpp_init_rmw(rmw, locator, domain_id, session_name,
nullptr, out.storage_);
169 out.initialized_ =
true;
216 return Result(nros_cpp_executor_ping(storage_, timeout_ms));
238 return Result(nros_cpp_executor_get_node_names(storage_, visit, ctx));
249 return Result(nros_cpp_executor_get_topic_names_and_types(storage_, visit, ctx));
256 return Result(nros_cpp_executor_get_service_names_and_types(storage_, visit, ctx));
266 return Result(nros_cpp_executor_count_publishers(storage_, topic_name, out_count));
273 return Result(nros_cpp_executor_count_subscribers(storage_, topic_name, out_count));
278 nros_cpp_names_and_types_visit_fn visit,
281 return Result(nros_cpp_executor_get_publisher_names_and_types_by_node(
282 storage_, node_name, node_namespace, visit, ctx));
294 const char* node_namespace,
295 nros_cpp_names_and_types_visit_fn visit,
298 return Result(nros_cpp_executor_get_subscription_names_and_types_by_node(
299 storage_, node_name, node_namespace, visit, ctx));
304 nros_cpp_names_and_types_visit_fn visit,
void* ctx) {
306 return Result(nros_cpp_executor_get_service_names_and_types_by_node(
307 storage_, node_name, node_namespace, visit, ctx));
312 nros_cpp_names_and_types_visit_fn visit,
void* ctx) {
314 return Result(nros_cpp_executor_get_client_names_and_types_by_node(
315 storage_, node_name, node_namespace, visit, ctx));
325 nros_cpp_endpoint_info_visit_fn visit,
void* ctx) {
328 nros_cpp_executor_get_publishers_info_by_topic(storage_, topic_name, visit, ctx));
333 nros_cpp_endpoint_info_visit_fn visit,
void* ctx) {
336 nros_cpp_executor_get_subscriptions_info_by_topic(storage_, topic_name, visit, ctx));
357 while (initialized_) {
359 if (!last.
ok())
return last;
378 return Result(nros_cpp_spin_for(storage_, duration_ms, poll_ms));
386 [[deprecated(
"bounded spin is now `spin_for(duration_ms, poll_ms)`; "
387 "`spin()` blocks until shutdown, matching rclcpp (issue 0338)")]]
Result
388 spin(uint32_t duration_ms, int32_t poll_ms) {
389 return spin_for(duration_ms, poll_ms);
393 bool ok()
const {
return initialized_; }
429 nros_cpp_shutdown_callback_handle_t raw = NROS_CPP_SHUTDOWN_CALLBACK_HANDLE_INVALID;
430 nros_cpp_ret_t ret = nros_cpp_add_pre_shutdown_callback(storage_, callback, context, &raw);
447 nros_cpp_shutdown_callback_handle_t raw = NROS_CPP_SHUTDOWN_CALLBACK_HANDLE_INVALID;
448 nros_cpp_ret_t ret = nros_cpp_add_on_shutdown_callback(storage_, callback, context, &raw);
461 if (!initialized_)
return false;
462 return nros_cpp_remove_pre_shutdown_callback(storage_,
handle.value()) == 0;
469 if (!initialized_)
return false;
470 return nros_cpp_remove_on_shutdown_callback(storage_,
handle.value()) == 0;
477 initialized_ =
false;
484 nros_cpp_fini(storage_);
485 initialized_ =
false;
491 for (
unsigned i = 0; i <
sizeof(storage_); ++i) {
492 storage_[i] = other.storage_[i];
493 other.storage_[i] = 0;
495 other.initialized_ =
false;
499 if (
this != &other) {
501 nros_cpp_fini(storage_);
503 for (
unsigned i = 0; i <
sizeof(storage_); ++i) {
504 storage_[i] = other.storage_[i];
505 other.storage_[i] = 0;
507 initialized_ = other.initialized_;
508 other.initialized_ =
false;
517 alignas(8) uint8_t storage_[NROS_CPP_EXECUTOR_STORAGE_SIZE];
Definition executor.hpp:106
Result get_client_names_and_types_by_node(const char *node_name, const char *node_namespace, nros_cpp_names_and_types_visit_fn visit, void *ctx)
phase-381 W4 — what services one named node CALLS, with the types.
Definition executor.hpp:311
Executor()
Default constructor — creates an uninitialized executor.
Definition executor.hpp:109
Result ping(int32_t timeout_ms)
Definition executor.hpp:214
NodeBuilder node_builder(const char *name)
Definition node.hpp:1147
Executor & operator=(Executor &&other)
Definition executor.hpp:498
Result get_node_names(nros_cpp_node_visit_fn visit, void *ctx)
Definition executor.hpp:236
~Executor()
Destructor — shuts down if still active.
Definition executor.hpp:482
static Result create(Executor &out, const char *locator=nullptr, uint8_t domain_id=0)
Definition executor.hpp:120
Result get_publishers_info_by_topic(const char *topic_name, nros_cpp_endpoint_info_visit_fn visit, void *ctx)
Definition executor.hpp:324
bool ok() const
Check if the executor is initialized.
Definition executor.hpp:393
Result get_topic_names_and_types(nros_cpp_names_and_types_visit_fn visit, void *ctx)
Definition executor.hpp:247
Result get_subscriptions_info_by_topic(const char *topic_name, nros_cpp_endpoint_info_visit_fn visit, void *ctx)
phase-381 W4 — the subscriptions on topic_name, one visit each.
Definition executor.hpp:332
bool remove_on_shutdown_callback(OnShutdownCallbackHandle handle)
Definition executor.hpp:468
Result get_subscription_names_and_types_by_node(const char *node_name, const char *node_namespace, nros_cpp_names_and_types_visit_fn visit, void *ctx)
Definition executor.hpp:293
void * handle()
Definition executor.hpp:401
Result shutdown()
Shut down the executor and close the middleware connection.
Definition executor.hpp:474
Result spin_once(int32_t timeout_ms=10)
Definition executor.hpp:198
Result count_publishers(const char *topic_name, size_t *out_count)
Definition executor.hpp:264
static Result create(Executor &out, const char *locator, uint8_t domain_id, const char *session_name)
Definition executor.hpp:130
Result get_service_names_and_types(nros_cpp_names_and_types_visit_fn visit, void *ctx)
Definition executor.hpp:254
Result get_service_names_and_types_by_node(const char *node_name, const char *node_namespace, nros_cpp_names_and_types_visit_fn visit, void *ctx)
phase-381 W4 — what services one named node SERVES, with the types.
Definition executor.hpp:303
bool remove_pre_shutdown_callback(PreShutdownCallbackHandle handle)
Definition executor.hpp:460
Result spin(int32_t poll_ms=10)
Definition executor.hpp:354
Result count_subscribers(const char *topic_name, size_t *out_count)
Definition executor.hpp:271
Result add_pre_shutdown_callback(ShutdownCallback callback, void *context=nullptr, PreShutdownCallbackHandle *out=nullptr)
Definition executor.hpp:426
static Result create_with_rmw(Executor &out, const char *rmw, const char *locator=nullptr, uint8_t domain_id=0, const char *session_name="nros_cpp")
Definition executor.hpp:161
Result get_publisher_names_and_types_by_node(const char *node_name, const char *node_namespace, nros_cpp_names_and_types_visit_fn visit, void *ctx)
phase-381 W4 — what one named node PUBLISHES, with the types.
Definition executor.hpp:277
Result add_on_shutdown_callback(ShutdownCallback callback, void *context=nullptr, OnShutdownCallbackHandle *out=nullptr)
Definition executor.hpp:444
Result spin(uint32_t duration_ms, int32_t poll_ms)
Definition executor.hpp:388
Result spin_for(uint32_t duration_ms, int32_t poll_ms=10)
Definition executor.hpp:372
Executor(Executor &&other)
Definition executor.hpp:490
Result create_node(Node &out, const char *name, const char *ns=nullptr)
Definition node.hpp:1048
Definition executor.hpp:78
Definition executor.hpp:71
static constexpr Result success()
Named constructors.
Definition result.hpp:112
bool ok() const
Returns true if the operation succeeded.
Definition result.hpp:100
Definition executor.hpp:43
ShutdownCallbackHandle(nros_cpp_shutdown_callback_handle_t value)
Definition executor.hpp:51
bool valid() const
True when this handle came from a successful registration.
Definition executor.hpp:54
ShutdownCallbackHandle()
Definition executor.hpp:47
nros_cpp_shutdown_callback_handle_t value() const
The raw FFI value, for passing to the C entry points directly.
Definition executor.hpp:57
int nros_cpp_ret_t
Definition future.hpp:21
nros_cpp_ret_t nros_cpp_spin_once(void *handle, int32_t timeout_ms)
void(*)(void *context) ShutdownCallback
Definition executor.hpp:34
nros::Result, nros::ErrorCode, and the NROS_TRY macro.