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

#include <client.hpp>

Public Types

using RequestType = typename S::Request
 
using ResponseType = typename S::Response
 
using TypedResponseFn = void(*)(const ResponseType &response)
 
using TypedResponseFnWithCtx = void(*)(const ResponseType &response, void *ctx)
 

Public Member Functions

Result async_send_request (const RequestType &req)
 
Result call (const RequestType &req, ResponseType &resp, uint32_t timeout_ms=5000)
 
 Client ()
 
 Client (Client &&other)
 
size_t handle_id () const
 
bool is_valid () const
 Check if the client is initialized and valid.
 
Clientoperator= (Client &&other)
 
Future< ResponseTypesend_request (const RequestType &req)
 
int server_available () const
 
 ~Client ()
 

Friends

class Node
 

Detailed Description

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

Typed service client for a ROS 2 service.

Mirrors rclcpp::Client<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 (async – preferred):

NROS_TRY(node.create_client(client, "/add_two_ints"));
auto fut = client.send_request(req);
NROS_TRY(fut.wait(executor.handle(), 5000, resp));
typename S::Response ResponseType
Definition client.hpp:57
Definition future.hpp:40
Result wait(void *executor_handle, uint32_t timeout_ms, T &out, uint32_t poll_ms=10)
Definition future.hpp:84
#define NROS_TRY(expr)
Definition result.hpp:90

Member Typedef Documentation

◆ RequestType

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

◆ ResponseType

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

◆ TypedResponseFn

template<typename S >
using nros::Client< S >::TypedResponseFn = void (*)(const ResponseType& response)

Phase 189.M3.3.f — typed response-handler signatures for the callback-style client (rclcpp async dispatch). The handler runs during spin_once when a reply arrives for a request sent via async_send_request.

◆ TypedResponseFnWithCtx

template<typename S >
using nros::Client< S >::TypedResponseFnWithCtx = void (*)(const ResponseType& response, void* ctx)

Constructor & Destructor Documentation

◆ ~Client()

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

Destructor – releases service client resources.

Future-style clients own an RmwServiceClient in storage_; callback-style clients (M3.3.f) are owned by the executor arena, so the dtor must NOT touch storage_ for them.

◆ Client() [1/2]

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

◆ Client() [2/2]

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

Default constructor – creates an uninitialized service client. Use Node::create_client() to initialize.

Member Function Documentation

◆ async_send_request()

template<typename S >
Result nros::Client< S >::async_send_request ( const RequestType req)
inline

Phase 189.M3.3.f — callback-style async send. Only valid on a callback-style client (created via the create_client(out, name, callback, ...) overload); the reply is delivered to the registered response handler during spin_once (no Future). Returns immediately after sending.

◆ call()

template<typename S >
Result nros::Client< S >::call ( const RequestType req,
ResponseType resp,
uint32_t  timeout_ms = 5000 
)
inline

Send a request and block until a reply is received.

Spins the executor internally (like the runtime's Promise::wait). Never calls zpico_get — all I/O is driven by spin_once.

Parameters
reqRequest to send.
respOutput response struct (filled on success).
timeout_msMaximum wait time (default 5000ms).
Returns
Result indicating success, timeout, or failure.

◆ handle_id()

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

Executor handle for the callback-style client (Phase 189.M3.3.f); SIZE_MAX for future-style / uninitialized.

◆ is_valid()

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

Check if the client is initialized and valid.

◆ operator=()

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

◆ send_request()

template<typename S >
Future< ResponseType > nros::Client< S >::send_request ( const RequestType req)
inline

Send a request and return a Future for the response (non-blocking).

Call wait() on the returned future to block until the response arrives, or poll with is_ready() / try_take().

Parameters
reqRequest to send.
Returns
Future that resolves to the response. Returns a consumed (empty) future on serialization or send failure.

◆ server_available()

template<typename S >
int nros::Client< S >::server_available ( ) const
inline

Phase 124.C.3 — graph-aware "is the matching server up?" probe.

Returns the count from the RMW backend's matched-server view:

  • 1 — at least one matching server is currently visible.
  • 0 — no matching server discovered yet.
  • -1 — backend cannot answer (e.g. XRCE without participant enumeration); caller must fall back to a timed wait_for_service or assume reachability.

Never spins the executor — synchronous, safe to call from inside callbacks. Mirrors rclcpp::ClientBase::service_is_ready but with a tri-state result instead of collapsing "don't know" and "no" into the same false.

Friends And Related Symbol Documentation

◆ Node

template<typename S >
friend class Node
friend

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