10#ifndef NROS_RCLCPP_ACTION_SERVER_HPP
11#define NROS_RCLCPP_ACTION_SERVER_HPP
17#include "rclcpp/detail/callback_context.hpp"
19#include "rclcpp/detail/entity_name.hpp"
24#include "rclcpp/size_bound.hpp"
36#include "rclcpp/detail/nros_cpp_ffi.h"
40 size_t len,
void* ctx);
78 typename nros_void_<
decltype(A::SEND_GOAL_SERVICE_HASH)>::type> {
81 A::GET_RESULT_SERVICE_HASH, A::FEEDBACK_MESSAGE_HASH,
82 A::STATUS_MESSAGE_HASH};
126 static const size_t SIZE = 16;
136 for (
size_t i = 0;
i < SIZE; ++
i) {
147 for (
size_t i = 0;
i < SIZE; ++
i) {
148 if (uuid[
i] != 0)
return false;
154 for (
size_t i = 0;
i < SIZE; ++
i) {
155 if (uuid[
i] !=
other.uuid[
i])
return false;
166 for (
size_t i = 0;
i < SIZE; ++
i) {
173static_assert(
sizeof(GoalUUID) == 16,
174 "rclcpp_action::GoalUUID must be exactly the 16 bytes the FFI passes as uint8_t[16]");
175static_assert(
alignof(GoalUUID) ==
alignof(uint8_t),
176 "rclcpp_action::GoalUUID must not add alignment over its uint8_t[16]");
235 return (
r == GoalResponse::ACCEPT_AND_EXECUTE) ? 1
236 : (
r == GoalResponse::ACCEPT_AND_DEFER) ? 2
243 return (
r == CancelResponse::ACCEPT) ? 1 : 0;
373 user_goal_fn_ctx_ =
nullptr;
374 user_goal_ctx_ =
nullptr;
375 return install_callbacks();
387 user_goal_fn_ctx_ =
f;
388 user_goal_ctx_ =
ctx;
389 user_goal_fn_ =
nullptr;
390 return install_callbacks();
399 user_cancel_fn_ctx_ =
nullptr;
400 user_cancel_ctx_ =
nullptr;
401 return install_callbacks();
412 user_cancel_fn_ctx_ =
f;
413 user_cancel_ctx_ =
ctx;
414 user_cancel_fn_ =
nullptr;
415 return install_callbacks();
441 user_accepted_fn_ctx_ =
nullptr;
442 user_accepted_ctx_ =
nullptr;
443 return install_callbacks();
452 user_accepted_fn_ctx_ =
f;
453 user_accepted_ctx_ =
ctx;
454 user_accepted_fn_ =
nullptr;
455 return install_callbacks();
470 uint8_t buf[::rclcpp::detail::buffer_bounds<FeedbackType>::tx];
472 if (FeedbackType::ffi_serialize(&feedback,
buf,
sizeof(
buf), &len) != 0) {
476 storage_, executor_,
reinterpret_cast<const uint8_t(*)[16]
>(goal_id),
buf, len));
496 uint8_t buf[::rclcpp::detail::buffer_bounds<ResultType>::tx];
498 if (ResultType::ffi_serialize(&result,
buf,
sizeof(
buf), &len) != 0) {
502 storage_, executor_,
reinterpret_cast<const uint8_t(*)[16]
>(goal_id),
515 return publish_feedback(goal_id.data(), feedback);
521 return complete_goal(goal_id.data(),
status, result);
612 if (
fn ==
nullptr)
return;
618 ::rclcpp::detail::fn_to_context(
visitor)));
653 if (!initialized_)
return false;
655 reinterpret_cast<const uint8_t(*)[16]
>(goal_id));
659 bool goal_exists(const ::rclcpp_action::GoalUUID& goal_id)
const {
660 return goal_exists(goal_id.data());
684 initialized_ =
false;
694 : executor_(
other.executor_), user_goal_fn_(
other.user_goal_fn_),
695 user_goal_fn_ctx_(
other.user_goal_fn_ctx_), user_goal_ctx_(
other.user_goal_ctx_),
696 user_cancel_fn_(
other.user_cancel_fn_), user_cancel_fn_ctx_(
other.user_cancel_fn_ctx_),
697 user_cancel_ctx_(
other.user_cancel_ctx_), user_accepted_fn_(
other.user_accepted_fn_),
698 user_accepted_fn_ctx_(
other.user_accepted_fn_ctx_),
699 user_accepted_ctx_(
other.user_accepted_ctx_), action_name_{},
700 initialized_(
other.initialized_) {
701 ::memcpy(action_name_,
other.action_name_,
sizeof(action_name_));
702 if (
other.initialized_) {
704 other.initialized_ =
false;
710 if (
this != &
other) {
718 executor_ =
other.executor_;
719 user_goal_fn_ =
other.user_goal_fn_;
720 user_goal_fn_ctx_ =
other.user_goal_fn_ctx_;
721 user_goal_ctx_ =
other.user_goal_ctx_;
722 user_cancel_fn_ =
other.user_cancel_fn_;
723 user_cancel_fn_ctx_ =
other.user_cancel_fn_ctx_;
724 user_cancel_ctx_ =
other.user_cancel_ctx_;
725 user_accepted_fn_ =
other.user_accepted_fn_;
726 user_accepted_fn_ctx_ =
other.user_accepted_fn_ctx_;
727 user_accepted_ctx_ =
other.user_accepted_ctx_;
728 ::memcpy(action_name_,
other.action_name_,
sizeof(action_name_));
729 initialized_ =
other.initialized_;
730 if (
other.initialized_) {
732 other.initialized_ =
false;
745 user_accepted_ctx_(
nullptr), action_name_{}, initialized_(
false) {}
751 friend class ::rclcpp::Node;
764 if (GoalType::ffi_deserialize(data, len, &
g) != 0) {
767 if (
self->user_goal_fn_ctx_ !=
nullptr) {
768 return ::rclcpp_action::to_ffi(
769 self->user_goal_fn_ctx_(goal_id,
g,
self->user_goal_ctx_));
771 if (
self->user_goal_fn_ !=
nullptr) {
772 return ::rclcpp_action::to_ffi(
self->user_goal_fn_(goal_id,
g));
780 if (
self->user_cancel_fn_ctx_ !=
nullptr) {
781 return ::rclcpp_action::to_ffi(
782 self->user_cancel_fn_ctx_(goal_id,
self->user_cancel_ctx_));
784 if (self->user_cancel_fn_ !=
nullptr) {
785 return ::rclcpp_action::to_ffi(self->user_cancel_fn_(goal_id));
790 static void accepted_trampoline(
const uint8_t goal_id[16],
void* ctx) {
791 auto* self =
static_cast<Server*
>(ctx);
793 if (self->user_accepted_fn_ctx_ !=
nullptr) {
794 self->user_accepted_fn_ctx_(goal_id, self->user_accepted_ctx_);
797 if (self->user_accepted_fn_ !=
nullptr) {
798 self->user_accepted_fn_(goal_id);
803 bool goal_set = (user_goal_fn_ !=
nullptr) || (user_goal_fn_ctx_ !=
nullptr);
804 bool cancel_set = (user_cancel_fn_ !=
nullptr) || (user_cancel_fn_ctx_ !=
nullptr);
805 bool accepted_set = (user_accepted_fn_ !=
nullptr) || (user_accepted_fn_ctx_ !=
nullptr);
809 if (ret != 0) return ::rclcpp::Result(ret);
819 alignas(8) uint8_t storage_[NROS_CPP_ACTION_SERVER_STORAGE_SIZE];
821 TypedGoalFn user_goal_fn_;
822 TypedGoalFnWithCtx user_goal_fn_ctx_;
823 void* user_goal_ctx_;
824 TypedCancelFn user_cancel_fn_;
825 TypedCancelFnWithCtx user_cancel_fn_ctx_;
826 void* user_cancel_ctx_;
827 TypedAcceptedFn user_accepted_fn_;
828 TypedAcceptedFnWithCtx user_accepted_fn_ctx_;
829 void* user_accepted_ctx_;
851 const ::rclcpp::QoS&
qos,
852 const ::rclcpp::ActionServerOptions&
options) {
869 A::Goal::TYPE_HASH, &
hashes, sched);
871 out.executor_ = executor_handle_;
876 ::rclcpp::detail::assign_entity_name(
out.action_name_,
action_name);
877 out.initialized_ =
true;
Definition client.hpp:129
Definition result.hpp:216
Definition server.hpp:340
void(*)(const uint8_t uuid[16], ::rclcpp_action::GoalStatus status) TypedVisitorFn
User-facing visitor signature for for_each_active_goal.
Definition server.hpp:362
~Server()
Definition server.hpp:680
::rclcpp::Result abort(const ::rclcpp_action::GoalUUID &goal_id, const ResultType &result)
abort taking a GoalUUID value.
Definition server.hpp:576
::rclcpp::Result complete_goal(const uint8_t goal_id[16], const ResultType &result)
Definition server.hpp:508
::rclcpp::Result abort(const uint8_t goal_id[16], const ResultType &result)
Definition server.hpp:554
::rclcpp::Result publish_feedback(const uint8_t goal_id[16], const FeedbackType &feedback)
Definition server.hpp:467
::rclcpp::Result complete_goal(const uint8_t goal_id[16], ::rclcpp_action::GoalStatus status, const ResultType &result)
Definition server.hpp:492
::rclcpp::Result set_goal_callback_with_ctx(TypedGoalFnWithCtx f, void *ctx)
Definition server.hpp:385
bool goal_exists(const ::rclcpp_action::GoalUUID &goal_id) const
goal_exists taking a GoalUUID value.
Definition server.hpp:659
::rclcpp::Result set_accepted_callback_with_ctx(TypedAcceptedFnWithCtx f, void *ctx)
Definition server.hpp:450
::rclcpp::Result set_cancel_callback(F f)
Definition server.hpp:396
typename A::Feedback FeedbackType
Definition server.hpp:344
::rclcpp::Result succeed(const ::rclcpp_action::GoalUUID &goal_id, const ResultType &result)
succeed taking a GoalUUID value.
Definition server.hpp:571
::rclcpp::Result complete_goal(const ::rclcpp_action::GoalUUID &goal_id, ::rclcpp_action::GoalStatus status, const ResultType &result)
complete_goal taking a GoalUUID value (phase-417 W4.b).
Definition server.hpp:519
::rclcpp::Result canceled(const uint8_t goal_id[16], const ResultType &result)
Definition server.hpp:566
const char * get_action_name() const
Definition server.hpp:643
Server(Server &&other)
Definition server.hpp:693
Server()
Definition server.hpp:741
::rclcpp::Result canceled(const ::rclcpp_action::GoalUUID &goal_id, const ResultType &result)
canceled taking a GoalUUID value.
Definition server.hpp:581
Server & operator=(Server &&other)
Definition server.hpp:709
::rclcpp::Result set_goal_callback(F f)
Definition server.hpp:370
::rclcpp::Result set_accepted_callback(F f)
Definition server.hpp:438
::rclcpp::Result publish_feedback(const ::rclcpp_action::GoalUUID &goal_id, const FeedbackType &feedback)
publish_feedback taking a GoalUUID value (phase-417 W4.b).
Definition server.hpp:513
bool goal_exists(const uint8_t goal_id[16]) const
Definition server.hpp:652
::rclcpp::Result set_cancel_callback_with_ctx(TypedCancelFnWithCtx f, void *ctx)
Definition server.hpp:410
typename A::Goal GoalType
Definition server.hpp:342
bool is_valid() const
Check if the action server is initialized and valid.
Definition server.hpp:664
::rclcpp::Result complete_goal(const ::rclcpp_action::GoalUUID &goal_id, const ResultType &result)
complete_goal taking a GoalUUID value (phase-417 W4.b).
Definition server.hpp:525
typename A::Result ResultType
Definition server.hpp:343
::rclcpp::Result for_each_active_goal(F f)
Definition server.hpp:606
::rclcpp::Result succeed(const uint8_t goal_id[16], const ResultType &result)
Definition server.hpp:546
Inline storage-size macros for opaque entity buffers.
int nros_cpp_ret_t
Definition future.hpp:21
nros_cpp_action_hashes_t action_endpoint_hashes()
Definition server.hpp:87
constexpr int32_t to_ffi(GoalResponse r)
Definition server.hpp:234
CancelResponse
Definition server.hpp:224
GoalStatus
Definition server.hpp:262
static const size_t ACTION_NAME_MAX
Definition server.hpp:189
GoalResponse
Definition server.hpp:204
CancelReturnCode
Definition server.hpp:253
@ Error
Generic failure not covered by a more specific code.
rclcpp::Node and global session helpers.
rclcpp::Result, rclcpp::ErrorCode, and the RCLCPP_TRY macro.
int32_t(* nros_cpp_goal_callback_t)(const uint8_t goal_id[16], const uint8_t *data, size_t len, void *ctx)
Definition server.hpp:39
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 server.hpp:41
nros_cpp_ret_t nros_cpp_action_server_set_accepted_callback(void *handle, nros_cpp_accepted_callback_t accepted_cb, void *ctx)
void(* nros_cpp_accepted_callback_t)(const uint8_t goal_id[16], void *ctx)
Definition server.hpp:46
static nros_cpp_action_hashes_t get()
Definition server.hpp:79
static nros_cpp_action_hashes_t get()
Definition server.hpp:70
void type
Definition server.hpp:66
Definition server.hpp:124
bool operator!=(const GoalUUID &other) const
Definition server.hpp:160
bool operator==(const GoalUUID &other) const
Definition server.hpp:153
const uint8_t * data() const
Definition server.hpp:143
bool is_zero() const
True when every byte is zero — mirrors nros_core::GoalId::is_zero().
Definition server.hpp:146
GoalUUID()
The zero ("null") goal id — mirrors nros_core::GoalId::zero().
Definition server.hpp:132
uint8_t * data()
Pointer to the 16 bytes — what the raw-array overloads and the FFI take.
Definition server.hpp:142
GoalUUID(const uint8_t *src)
Copy the 16 bytes at src, which must point to at least that many.
Definition server.hpp:135
bool operator<(const GoalUUID &other) const
Definition server.hpp:165