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::Service< S > Class Template Reference

#include <service.hpp>

Public Types

using RequestType = typename S::Request
 
using ResponseType = typename S::Response
 
using TypedServiceFn = void(*)(const RequestType &request, ResponseType &response)
 
using TypedServiceFnWithCtx = void(*)(const RequestType &request, ResponseType &response, void *ctx)
 

Public Member Functions

size_t handle_id () const
 
bool is_valid () const
 Check if the service is initialized and valid.
 
Serviceoperator= (Service &&other)
 
Result send_reply (int64_t seq_id, const ResponseType &resp)
 
Result send_response (int64_t seq_id, const ResponseType &resp)
 
 Service ()
 
 Service (Service &&other)
 
Result take_request (RequestType &req, int64_t &seq_id)
 
Result try_recv_request (RequestType &req, int64_t &seq_id)
 
template<size_t Cap>
Result try_recv_request_sized (RequestType &req, int64_t &seq_id)
 
 ~Service ()
 

Friends

class Node
 

Detailed Description

template<typename S>
class nros::Service< S >

Typed service server for a ROS 2 service.

Mirrors rclcpp::Service<S>. The service type S must provide nested Request and Response types with TYPE_NAME, TYPE_HASH, SERIALIZED_SIZE_MAX, ffi_serialize(), and ffi_deserialize().

Usage:

NROS_TRY(node.create_service(srv, "/add_two_ints"));
typename decltype(srv)::RequestType req;
int64_t seq;
if (srv.take_request(req, seq)) {
typename decltype(srv)::ResponseType resp;
resp.sum = req.a + req.b;
srv.send_response(seq, resp);
}
Definition service.hpp:60
Result send_response(int64_t seq_id, const ResponseType &resp)
Definition service.hpp:120
typename S::Request RequestType
Definition service.hpp:62
typename S::Response ResponseType
Definition service.hpp:63
Result take_request(RequestType &req, int64_t &seq_id)
Definition service.hpp:80
#define NROS_TRY(expr)
Definition result.hpp:128

Member Typedef Documentation

◆ RequestType

template<typename S >
using nros::Service< S >::RequestType = typename S::Request

◆ ResponseType

template<typename S >
using nros::Service< S >::ResponseType = typename S::Response

◆ TypedServiceFn

template<typename S >
using nros::Service< S >::TypedServiceFn = void (*)(const RequestType& request, ResponseType& response)

Phase 189.M3.3.e — typed request-handler signatures for the callback-style service (rclcpp dispatch model). The handler fills response from request; the executor sends the reply during spin.

◆ TypedServiceFnWithCtx

template<typename S >
using nros::Service< S >::TypedServiceFnWithCtx = void (*)(const RequestType& request, ResponseType& response, void* ctx)

Constructor & Destructor Documentation

◆ ~Service()

template<typename S >
nros::Service< S >::~Service ( )
inline

Destructor — releases service server resources.

Poll-style services own an RmwServiceServer in storage_ and free it here. Callback-style services (Phase 189.M3.3.e) are owned by the executor arena (freed when the executor drops), so the dtor must NOT touch storage_ for them.

◆ Service() [1/2]

template<typename S >
nros::Service< S >::Service ( Service< S > &&  other)
inline

◆ Service() [2/2]

template<typename S >
nros::Service< S >::Service ( )
inline

Default constructor — creates an uninitialized service server. Use Node::create_service() to initialize.

Member Function Documentation

◆ handle_id()

template<typename S >
size_t nros::Service< S >::handle_id ( ) const
inline

Executor handle for the callback-style service (Phase 189.M3.3.e); SIZE_MAX for poll-style / uninitialized.

◆ is_valid()

template<typename S >
bool nros::Service< S >::is_valid ( ) const
inline

Check if the service is initialized and valid.

◆ operator=()

template<typename S >
Service & nros::Service< S >::operator= ( Service< S > &&  other)
inline

◆ send_reply()

template<typename S >
Result nros::Service< S >::send_reply ( int64_t  seq_id,
const ResponseType resp 
)
inline
Deprecated:
Use send_response().

Phase-379 W5: rcl, rclcpp and rclrs all say send_response, and our own C already used that word. Kept as a forwarder so an out-of-tree node on the old spelling still compiles and is told what to move to.

◆ send_response()

template<typename S >
Result nros::Service< S >::send_response ( int64_t  seq_id,
const ResponseType resp 
)
inline

Send a typed reply to a previously received request.

Parameters
seq_idSequence number from take_request().
respResponse to send.
Returns
Result indicating success or failure.

◆ take_request()

template<typename S >
Result nros::Service< S >::take_request ( RequestType req,
int64_t &  seq_id 
)
inline

Try to receive a typed request (non-blocking).

Parameters
reqOutput request struct (filled on success).
seq_idOutput sequence number for reply matching.
Returns
Result::success() if a request was received and deserialized; ErrorCode::TryAgain if no data is available; ErrorCode::NotInitialized or the FFI error code otherwise; ErrorCode::Error if deserialization failed.

◆ try_recv_request()

template<typename S >
Result nros::Service< S >::try_recv_request ( RequestType req,
int64_t &  seq_id 
)
inline
Deprecated:
Use take_request(RequestType&, int64_t&).

phase-379 W6 decision 1 (2026-09-03): take -> take. rcl (rcl_take_request), rclcpp (Service::take_request) and our own RMW vtable (take_request) already said take; only this layer said take. Header-only forwarder, no ABI cost. Scheduled for removal.

◆ try_recv_request_sized()

template<typename S >
template<size_t Cap>
Result nros::Service< S >::try_recv_request_sized ( RequestType req,
int64_t &  seq_id 
)
inline

take_request with the receive buffer sized by the CALLER.

This IS a receive buffer — issue 0964's survey listed the service request under "transmit", which is true of Client<S>'s request and false here: the server deserializes out of it, so an under-estimate truncates. See Subscription::take_sized.

Friends And Related Symbol Documentation

◆ Node

template<typename S >
friend class Node
friend

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