Skip to content

Client#

agnocast::Client<ServiceT>#

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

Example:

using SrvT = example_interfaces::srv::AddTwoInts;

auto client = agnocast::create_client<SrvT>(this, "add_two_ints");
client->wait_for_service();

// Send a request with a callback
auto req = client->borrow_loaned_request();
req->a = 1;
req->b = 2;
client->async_send_request(std::move(req),
  [this](agnocast::Client<SrvT>::SharedFuture future) {
    RCLCPP_INFO(get_logger(), "Result: %ld", future.get()->sum);
  });

// Or send a request and get a future
auto req2 = client->borrow_loaned_request();
req2->a = 3;
req2->b = 4;
auto future = client->async_send_request(std::move(req2));
RCLCPP_INFO(get_logger(), "Result: %ld", future.get()->sum);

FutureAndRequestId#

struct FutureAndRequestId

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.


SharedFutureAndRequestId#

struct SharedFutureAndRequestId

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.


Future#

Future

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


SharedFuture#

SharedFuture

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


borrow_loaned_request()#

agnocast::ipc_shared_ptr<typename ServiceT::Request> Client::borrow_loaned_request()

Allocate a request message in shared memory.

Template Parameter Description
ServiceT ROS service type.
Returns Owned pointer to the request message in shared memory.

get_service_name()#

char * Client::get_service_name() const

Return the resolved service name.

Returns Null-terminated service name string.

service_is_ready()#

bool Client::service_is_ready() const

Check if the service server is available.

Returns True if the service server is available.

wait_for_service()#

bool Client::wait_for_service(std::chrono::duration<RepT, RatioT> timeout) const

Block until the service is available or the timeout expires.

Parameter Default Description
timeout std::chrono::nanoseconds(-1) Maximum duration to wait (-1 = wait forever).
Returns True if service became available, false on timeout.

async_send_request()#

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

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

Template Parameter Description
ServiceT ROS service type.
Parameter Description
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).

async_send_request() [overload 2]#

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

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

Template Parameter Description
ServiceT ROS service type.
Parameter Description
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.