10#ifndef NROS_CPP_ACTION_SERVER_HPP
11#define NROS_CPP_ACTION_SERVER_HPP
30#include "nros_cpp_ffi.h"
34 size_t len,
void* ctx);
119 user_goal_fn_ctx_ =
nullptr;
120 user_goal_ctx_ =
nullptr;
121 return install_callbacks();
133 user_goal_fn_ctx_ =
f;
134 user_goal_ctx_ =
ctx;
135 user_goal_fn_ =
nullptr;
136 return install_callbacks();
145 user_cancel_fn_ctx_ =
nullptr;
146 user_cancel_ctx_ =
nullptr;
147 return install_callbacks();
158 user_cancel_fn_ctx_ =
f;
159 user_cancel_ctx_ =
ctx;
160 user_cancel_fn_ =
nullptr;
161 return install_callbacks();
172 uint8_t buf[FeedbackType::SERIALIZED_SIZE_MAX];
174 if (FeedbackType::ffi_serialize(&feedback,
buf,
sizeof(
buf), &len) != 0) {
178 storage_, executor_,
reinterpret_cast<const uint8_t(*)[16]
>(goal_id),
buf, len));
187 if (ResultType::ffi_serialize(&result,
buf,
sizeof(
buf), &len) != 0) {
191 storage_, executor_,
reinterpret_cast<const uint8_t(*)[16]
>(goal_id),
buf, len));
205 user_visitor_fn_ =
Fn(
f);
209 if (!
self ||
self->user_visitor_fn_ ==
nullptr)
return;
215 user_visitor_fn_ =
nullptr;
226 initialized_ =
false;
236 : executor_(
other.executor_), user_goal_fn_(
other.user_goal_fn_),
237 user_goal_fn_ctx_(
other.user_goal_fn_ctx_), user_goal_ctx_(
other.user_goal_ctx_),
238 user_cancel_fn_(
other.user_cancel_fn_), user_cancel_fn_ctx_(
other.user_cancel_fn_ctx_),
239 user_cancel_ctx_(
other.user_cancel_ctx_), user_visitor_fn_(
other.user_visitor_fn_),
240 initialized_(
other.initialized_) {
241 if (
other.initialized_) {
243 other.initialized_ =
false;
249 if (
this != &
other) {
253 executor_ =
other.executor_;
254 user_goal_fn_ =
other.user_goal_fn_;
255 user_goal_fn_ctx_ =
other.user_goal_fn_ctx_;
256 user_goal_ctx_ =
other.user_goal_ctx_;
257 user_cancel_fn_ =
other.user_cancel_fn_;
258 user_cancel_fn_ctx_ =
other.user_cancel_fn_ctx_;
259 user_cancel_ctx_ =
other.user_cancel_ctx_;
260 user_visitor_fn_ =
other.user_visitor_fn_;
261 initialized_ =
other.initialized_;
262 if (
other.initialized_) {
264 other.initialized_ =
false;
295 if (GoalType::ffi_deserialize(data, len, &
g) != 0) {
298 if (
self->user_goal_fn_ctx_ !=
nullptr) {
299 return static_cast<int32_t>(
self->user_goal_fn_ctx_(goal_id,
g,
self->user_goal_ctx_));
301 if (self->user_goal_fn_ !=
nullptr) {
302 return static_cast<int32_t
>(self->user_goal_fn_(goal_id, g));
307 static int32_t cancel_trampoline(
const uint8_t goal_id[16],
void* ctx) {
310 if (self->user_cancel_fn_ctx_ !=
nullptr) {
311 return static_cast<int32_t
>(self->user_cancel_fn_ctx_(goal_id, self->user_cancel_ctx_));
313 if (self->user_cancel_fn_ !=
nullptr) {
314 return static_cast<int32_t
>(self->user_cancel_fn_(goal_id));
319 Result install_callbacks() {
320 bool goal_set = (user_goal_fn_ !=
nullptr) || (user_goal_fn_ctx_ !=
nullptr);
321 bool cancel_set = (user_cancel_fn_ !=
nullptr) || (user_cancel_fn_ctx_ !=
nullptr);
327 alignas(8) uint8_t storage_[NROS_CPP_ACTION_SERVER_STORAGE_SIZE];
331 void* user_goal_ctx_;
334 void* user_cancel_ctx_;
339 char action_name_[256] = {};
361 ffi_qos.liveliness_lease_ms =
qos.liveliness_lease_ms();
362 ffi_qos.avoid_ros_namespace_conventions =
qos.avoid_ros_namespace_conventions() ? 1 : 0;
376 A::Goal::TYPE_HASH, sched);
386 out.executor_ = executor_handle_;
387 out.initialized_ =
true;
int32_t(* nros_cpp_goal_callback_t)(const uint8_t goal_id[16], const uint8_t *data, size_t len, void *ctx)
Definition action_server.hpp:33
nros_cpp_ret_t nros_cpp_action_server_set_callbacks(void *handle, nros_cpp_goal_callback_t goal_cb, nros_cpp_cancel_callback_t cancel_cb, void *ctx)
int32_t(* nros_cpp_cancel_callback_t)(const uint8_t goal_id[16], void *ctx)
Definition action_server.hpp:35
Definition action_server.hpp:92
ActionServer()
Definition action_server.hpp:273
Result for_each_active_goal(F f)
Definition action_server.hpp:202
bool is_valid() const
Check if the action server is initialized and valid.
Definition action_server.hpp:220
ActionServer & operator=(ActionServer &&other)
Definition action_server.hpp:248
typename A::Goal GoalType
Definition action_server.hpp:94
void(*)(const uint8_t uuid[16], GoalStatus status) TypedVisitorFn
User-facing visitor signature for for_each_active_goal.
Definition action_server.hpp:108
Result set_goal_callback(F f)
Definition action_server.hpp:116
Result set_cancel_callback(F f)
Definition action_server.hpp:142
Result set_cancel_callback_with_ctx(TypedCancelFnWithCtx f, void *ctx)
Definition action_server.hpp:156
~ActionServer()
Destructor — releases action server resources.
Definition action_server.hpp:223
Result publish_feedback(const uint8_t goal_id[16], const FeedbackType &feedback)
Definition action_server.hpp:169
CancelResponse(*)(const uint8_t uuid[16], void *ctx) TypedCancelFnWithCtx
User-facing typed cancel callback signature with user context (Phase 84.G9).
Definition action_server.hpp:106
Result set_goal_callback_with_ctx(TypedGoalFnWithCtx f, void *ctx)
Definition action_server.hpp:131
typename A::Feedback FeedbackType
Definition action_server.hpp:96
ActionServer(ActionServer &&other)
Definition action_server.hpp:235
GoalResponse(*)(const uint8_t uuid[16], const GoalType &goal, void *ctx) TypedGoalFnWithCtx
User-facing typed goal callback signature with user context (Phase 84.G9).
Definition action_server.hpp:102
GoalResponse(*)(const uint8_t uuid[16], const GoalType &goal) TypedGoalFn
User-facing typed goal callback signature.
Definition action_server.hpp:99
CancelResponse(*)(const uint8_t uuid[16]) TypedCancelFn
User-facing typed cancel callback signature.
Definition action_server.hpp:104
Result complete_goal(const uint8_t goal_id[16], const ResultType &result)
Complete a goal with a result.
Definition action_server.hpp:182
typename A::Result ResultType
Definition action_server.hpp:95
Result create_action_server(ActionServer< A > &out, const char *action_name, const QoS &qos=QoS::services(), const ActionServerOptions &options={})
Definition action_server.hpp:350
Inline storage-size macros for opaque entity buffers.
int nros_cpp_ret_t
Definition future.hpp:20
GoalResponse
Goal acceptance response returned from the user's goal callback.
Definition action_server.hpp:45
CancelResponse
Cancel acceptance response returned from the user's cancel callback.
Definition action_server.hpp:52
GoalStatus
Definition action_server.hpp:59
@ Error
Generic failure not covered by a more specific code.
nros::Node and global session helpers.
nros_cpp_qos_history_t
Definition qos.hpp:31
nros_cpp_qos_liveliness_t
Definition qos.hpp:35
nros_cpp_qos_durability_t
Definition qos.hpp:27
nros_cpp_qos_reliability_t
Definition qos.hpp:23
nros::Result, nros::ErrorCode, and the NROS_TRY macro.