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)
 
 Service ()
 
 Service (Service &&other)
 
Result try_recv_request (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;
if (srv.try_recv_request(req, seq)) {
typename decltype(srv)::ResponseType resp;
resp.sum = req.a + req.b;
srv.send_reply(seq, resp);
}
Definition future.hpp:40
typename S::Request RequestType
Definition service.hpp:61
typename S::Response ResponseType
Definition service.hpp:62
#define NROS_TRY(expr)
Definition result.hpp:90

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

Send a typed reply to a previously received request.

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

◆ try_recv_request()

template<typename S >
Result nros::Service< S >::try_recv_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.

Friends And Related Symbol Documentation

◆ Node

template<typename S >
friend class Node
friend

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