Template Class Client

Nested Relationships

Nested Types

Class Documentation

template<typename ServiceT>
class Client

Service client for zero-copy Agnocast service communication. The service/client API is experimental and may change in future versions.

Template Parameters:

ServiceT – The ROS service type (e.g., std_srvs::srv::SetBool).

Public Types

using SharedPtr = std::shared_ptr<Client<ServiceT>>
using Future = std::future<ipc_shared_ptr<typename ServiceT::Response>>

Future that resolves to the service response. Returned by async_send_request() (no-callback overload).

using SharedFuture = std::shared_future<ipc_shared_ptr<typename ServiceT::Response>>

Shared future that resolves to the service response. Passed to the callback in async_send_request().

Public Functions

template<typename NodeT>
inline Client(NodeT *node, const std::string &service_name, const rclcpp::QoS &qos, rclcpp::CallbackGroup::SharedPtr group)
inline ipc_shared_ptr<typename ServiceT::Request> borrow_loaned_request()

Allocate a request message in shared memory.

Returns:

Owned pointer to the request message in shared memory.

inline const char *get_service_name() const

Return the resolved service name.

Returns:

Null-terminated service name string.

inline bool service_is_ready() const

Check if the service server is available.

Returns:

True if the service server is available.

template<typename RepT, typename RatioT>
inline bool wait_for_service(std::chrono::duration<RepT, RatioT> timeout = std::chrono::nanoseconds(-1)) const

Block until the service is available or the timeout expires.

Parameters:

timeout – Maximum duration to wait (-1 = wait forever).

Returns:

True if service became available, false on timeout.

inline SharedFutureAndRequestId async_send_request(ipc_shared_ptr<typename ServiceT::Request> &&request, std::function<void(SharedFuture)> callback)

Send a request asynchronously and invoke a callback when the response arrives.

Parameters:
  • request – Request from borrow_loaned_request(). Must be moved in.

  • callback – Invoked with a SharedFuture when the response arrives. Call future.get() to obtain the response.

Returns:

A SharedFutureAndRequestId containing the shared future (.future) and a sequence number (.request_id).

inline FutureAndRequestId async_send_request(ipc_shared_ptr<typename ServiceT::Request> &&request)

Send a request asynchronously and return a future for the response.

Parameters:

request – Request from borrow_loaned_request(). Must be moved in.

Returns:

A FutureAndRequestId containing the future (.future) and a sequence number (.request_id). Call .future.get() to block until the response arrives.

struct FutureAndRequestId : public rclcpp::detail::FutureAndRequestId<Future>

Return type of async_send_request() (no-callback overload). Contains a Future and the request ID. Access the future via the future member and the request ID via request_id.

Public Functions

inline SharedFuture share() noexcept

Convert to a SharedFutureAndRequestId by sharing the underlying future.

struct SharedFutureAndRequestId : public rclcpp::detail::FutureAndRequestId<SharedFuture>

Return type of async_send_request() (callback overload). Contains a SharedFuture and the request ID. Access the shared future via the future member and the request ID via request_id.