nros C++ API
Lightweight ROS 2 client for embedded real-time systems (C++ headers)
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends | List of all members
nros::ActionServer< A > Class Template Reference

#include <action_server.hpp>

Public Types

using FeedbackType = typename A::Feedback
 
using GoalType = typename A::Goal
 
using ResultType = typename A::Result
 
using TypedAcceptedFn = void(*)(const uint8_t uuid[16])
 User-facing typed accepted-goal callback signature (issue 0796).
 
using TypedAcceptedFnWithCtx = void(*)(const uint8_t uuid[16], void *ctx)
 User-facing typed accepted-goal callback signature with user context.
 
using TypedCancelFn = CancelResponse(*)(const uint8_t uuid[16])
 User-facing typed cancel callback signature.
 
using TypedCancelFnWithCtx = CancelResponse(*)(const uint8_t uuid[16], void *ctx)
 User-facing typed cancel callback signature with user context (Phase 84.G9).
 
using TypedGoalFn = GoalResponse(*)(const uint8_t uuid[16], const GoalType &goal)
 User-facing typed goal callback signature.
 
using TypedGoalFnWithCtx = GoalResponse(*)(const uint8_t uuid[16], const GoalType &goal, void *ctx)
 User-facing typed goal callback signature with user context (Phase 84.G9).
 
using TypedVisitorFn = void(*)(const uint8_t uuid[16], GoalStatus status)
 User-facing visitor signature for for_each_active_goal.
 

Public Member Functions

 ActionServer ()
 
 ActionServer (ActionServer &&other)
 
Result complete_goal (const uint8_t goal_id[16], const ResultType &result)
 
Result complete_goal (const uint8_t goal_id[16], GoalStatus status, const ResultType &result)
 
template<typename F >
Result for_each_active_goal (F f)
 
bool is_valid () const
 Check if the action server is initialized and valid.
 
ActionServeroperator= (ActionServer &&other)
 
Result publish_feedback (const uint8_t goal_id[16], const FeedbackType &feedback)
 
template<typename F >
Result set_accepted_callback (F f)
 
Result set_accepted_callback_with_ctx (TypedAcceptedFnWithCtx f, void *ctx)
 
template<typename F >
Result set_cancel_callback (F f)
 
Result set_cancel_callback_with_ctx (TypedCancelFnWithCtx f, void *ctx)
 
template<typename F >
Result set_goal_callback (F f)
 
Result set_goal_callback_with_ctx (TypedGoalFnWithCtx f, void *ctx)
 
 ~ActionServer ()
 Destructor — releases action server resources.
 

Friends

class Node
 

Detailed Description

template<typename A>
class nros::ActionServer< A >

Typed action server for a ROS 2 action.

Mirrors rclcpp_action::Server<A> with a callback-based API. The action type A must provide nested Goal, Result, and Feedback types with TYPE_NAME, TYPE_HASH, SERIALIZED_SIZE_MAX, ffi_serialize(), and ffi_deserialize().

Usage:

using Fib = example_interfaces::action::Fibonacci;
NROS_TRY(node.create_action_server(srv, "/fibonacci"));
[](const uint8_t[16], const Fib::Goal& g) {
if (g.order > 46) return nros::GoalResponse::Reject;
});
Definition action_server.hpp:125
Result set_goal_callback(F f)
Definition action_server.hpp:153
#define NROS_TRY(expr)
Definition result.hpp:128

Callbacks must be stateless (empty-capture lambdas or plain function pointers). This is a freestanding C++14 library without std::function, so per-instance closure storage is not available.

Member Typedef Documentation

◆ FeedbackType

template<typename A >
using nros::ActionServer< A >::FeedbackType = typename A::Feedback

◆ GoalType

template<typename A >
using nros::ActionServer< A >::GoalType = typename A::Goal

◆ ResultType

template<typename A >
using nros::ActionServer< A >::ResultType = typename A::Result

◆ TypedAcceptedFn

template<typename A >
using nros::ActionServer< A >::TypedAcceptedFn = void (*)(const uint8_t uuid[16])

User-facing typed accepted-goal callback signature (issue 0796).

◆ TypedAcceptedFnWithCtx

template<typename A >
using nros::ActionServer< A >::TypedAcceptedFnWithCtx = void (*)(const uint8_t uuid[16], void* ctx)

User-facing typed accepted-goal callback signature with user context.

◆ TypedCancelFn

template<typename A >
using nros::ActionServer< A >::TypedCancelFn = CancelResponse (*)(const uint8_t uuid[16])

User-facing typed cancel callback signature.

◆ TypedCancelFnWithCtx

template<typename A >
using nros::ActionServer< A >::TypedCancelFnWithCtx = CancelResponse (*)(const uint8_t uuid[16], void* ctx)

User-facing typed cancel callback signature with user context (Phase 84.G9).

◆ TypedGoalFn

template<typename A >
using nros::ActionServer< A >::TypedGoalFn = GoalResponse (*)(const uint8_t uuid[16], const GoalType& goal)

User-facing typed goal callback signature.

◆ TypedGoalFnWithCtx

template<typename A >
using nros::ActionServer< A >::TypedGoalFnWithCtx = GoalResponse (*)(const uint8_t uuid[16], const GoalType& goal, void* ctx)

User-facing typed goal callback signature with user context (Phase 84.G9).

◆ TypedVisitorFn

template<typename A >
using nros::ActionServer< A >::TypedVisitorFn = void (*)(const uint8_t uuid[16], GoalStatus status)

User-facing visitor signature for for_each_active_goal.

Constructor & Destructor Documentation

◆ ~ActionServer()

template<typename A >
nros::ActionServer< A >::~ActionServer ( )
inline

Destructor — releases action server resources.

◆ ActionServer() [1/2]

template<typename A >
nros::ActionServer< A >::ActionServer ( ActionServer< A > &&  other)
inline

◆ ActionServer() [2/2]

template<typename A >
nros::ActionServer< A >::ActionServer ( )
inline

Default constructor — creates an uninitialized action server. Use Node::create_action_server() to initialize.

Member Function Documentation

◆ complete_goal() [1/2]

template<typename A >
Result nros::ActionServer< A >::complete_goal ( const uint8_t  goal_id[16],
const ResultType result 
)
inline

Terminate a goal as SUCCEEDED. Equivalent to complete_goal(goal_id, GoalStatus::Succeeded, result).

◆ complete_goal() [2/2]

template<typename A >
Result nros::ActionServer< A >::complete_goal ( const uint8_t  goal_id[16],
GoalStatus  status,
const ResultType result 
)
inline

Terminate a goal with a result and the status it terminated in.

Issue 0796 — status used to be hardcoded Succeeded inside the shim, so a server that aborted a goal reported success to the client. The parameter order matches PollingActionServer::complete_goal and the C API's nros_action_server_complete_goal_raw, so the three surfaces agree; Succeeded is defaulted because it is the common case and because that keeps existing two-argument calls compiling.

◆ for_each_active_goal()

template<typename A >
template<typename F >
Result nros::ActionServer< A >::for_each_active_goal ( f)
inline

Iterate over every currently live goal and invoke f(uuid, status).

F must be a stateless callable convertible to void (*)(const uint8_t uuid[16], GoalStatus status). The arena never stores the original goal CDR payload, so only identity + status are forwarded — if you need the goal bytes, stash them in a {uuid → state} table from inside set_goal_callback. F must be a stateless callable convertible to void(*)(const uint8_t[16], GoalStatus).

◆ is_valid()

template<typename A >
bool nros::ActionServer< A >::is_valid ( ) const
inline

Check if the action server is initialized and valid.

◆ operator=()

template<typename A >
ActionServer & nros::ActionServer< A >::operator= ( ActionServer< A > &&  other)
inline

◆ publish_feedback()

template<typename A >
Result nros::ActionServer< A >::publish_feedback ( const uint8_t  goal_id[16],
const FeedbackType feedback 
)
inline

Publish feedback for an active goal.

Parameters
goal_id16-byte goal UUID from the goal callback.
feedbackFeedback to publish.
Returns
Result indicating success or failure.

◆ set_accepted_callback()

template<typename A >
template<typename F >
Result nros::ActionServer< A >::set_accepted_callback ( f)
inline

Register a callback invoked once per ACCEPTED goal (issue 0796).

Fires after the accept reply has reached the client, for GoalResponse::AcceptAndExecute and GoalResponse::AcceptAndDefer alike. This is where a deferred goal starts executing: the goal callback answers accept/reject and must return promptly, so it is the wrong place to begin work.

Mirrors C's nros_accepted_callback_t (passed at nros_action_server_init) and Rust's third argument to create_action_server_with_callbacks(goal, cancel, accepted). Without it a C++ user who returned ACCEPT_AND_DEFER was never told the goal had been accepted.

F must be a stateless callable convertible to TypedAcceptedFn.

◆ set_accepted_callback_with_ctx()

template<typename A >
Result nros::ActionServer< A >::set_accepted_callback_with_ctx ( TypedAcceptedFnWithCtx  f,
void *  ctx 
)
inline

Register an accepted-goal callback with a user context pointer.

Mirrors set_goal_callback_with_ctx. Mutually exclusive with set_accepted_callback().

◆ set_cancel_callback()

template<typename A >
template<typename F >
Result nros::ActionServer< A >::set_cancel_callback ( f)
inline

Register a cancel callback.

F must be a stateless callable convertible to TypedCancelFn.

◆ set_cancel_callback_with_ctx()

template<typename A >
Result nros::ActionServer< A >::set_cancel_callback_with_ctx ( TypedCancelFnWithCtx  f,
void *  ctx 
)
inline

Register a cancel callback with a user context pointer.

Mirrors set_goal_callback_with_ctx — the bare function pointer receives a void* alongside each UUID so stateful cancel policies don't need captured lambdas or global state. Mutually exclusive with set_cancel_callback().

◆ set_goal_callback()

template<typename A >
template<typename F >
Result nros::ActionServer< A >::set_goal_callback ( f)
inline

Register a typed goal callback.

F must be a stateless callable that decays to TypedGoalFn (empty-capture lambda or plain function pointer). F must be a stateless callable convertible to TypedGoalFn (empty-capture lambda or plain function pointer).

◆ set_goal_callback_with_ctx()

template<typename A >
Result nros::ActionServer< A >::set_goal_callback_with_ctx ( TypedGoalFnWithCtx  f,
void *  ctx 
)
inline

Register a typed goal callback with a user context pointer.

The bare function pointer is stored alongside a void* that is forwarded to every invocation — lets callers reach stateful objects without capturing lambdas or file-scope globals. Overrides and is overridden by set_goal_callback() (the two modes are mutually exclusive).

Friends And Related Symbol Documentation

◆ Node

template<typename A >
friend class Node
friend

The documentation for this class was generated from the following files: