Template Class Client

Nested Relationships

Nested Types

Class Documentation

template<typename ServiceT>
class Client

Service client for zero-copy Agnocast service communication.

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

inline Client(rclcpp::Node *node, const std::string &service_name, const rclcpp::QoS &qos_arg, rclcpp::CallbackGroup::SharedPtr group)
inline Client(agnocast::Node *node, const std::string &service_name, const rclcpp::QoS &qos_arg, rclcpp::CallbackGroup::SharedPtr group)
inline AGNOCAST_PUBLIC 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 AGNOCAST_PUBLIC const char * get_service_name () const

Return the resolved service name.

Returns:

Null-terminated service name string.

inline AGNOCAST_PUBLIC 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 AGNOCAST_PUBLIC 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 AGNOCAST_PUBLIC 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 AGNOCAST_PUBLIC 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 AGNOCAST_PUBLIC 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.