Function rcl_send_response

Function Documentation

rcl_ret_t rcl_send_response(const rcl_service_t *service, rmw_request_id_t *response_header, void *ros_response)

Send a ROS response to a client using a service.

It is the job of the caller to ensure that the type of the ros_response parameter and the type associate with the service (via the type support) match. Passing a different type to send_response produces undefined behavior and cannot be checked by this function and therefore no deliberate error will occur.

send_response() is an non-blocking call.

The ROS response message given by the ros_response void pointer is always owned by the calling code, but should remain constant during rcl_send_response().

This function is thread safe so long as access to both the service and the ros_response is synchronized. That means that calling rcl_send_response() from multiple threads is allowed, but calling rcl_send_response() at the same time as non-thread safe service functions is not, e.g. calling rcl_send_response() and rcl_service_fini() concurrently is not allowed. The message cannot change during the rcl_send_response() call. Before calling rcl_send_response() the message can change but after calling rcl_send_response() it depends on RMW implementation behavior. The same ros_response, however, can be passed to multiple calls of rcl_send_response() simultaneously, even if the services differ. The ros_response is unmodified by rcl_send_response().

Attribute

Adherence

Allocates Memory

No

Thread-Safe

Yes [1]

Uses Atomics

No

Lock-Free

Yes

[1] for unique pairs of services and responses, see above for more

Parameters:
  • service[in] handle to the service which will make the response

  • response_header[inout] ptr to the struct holding metadata about the request ID

  • ros_response[in] type-erased pointer to the ROS response message

Returns:

RCL_RET_OK if the response was sent successfully, or

Returns:

RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or

Returns:

RCL_RET_SERVICE_INVALID if the service is invalid, or

Returns:

RCL_RET_TIMEOUT if a response reader is not ready yet, or

Returns:

RCL_RET_ERROR if an unspecified error occurs.