Class GenericService

Inheritance Relationships

Base Types

  • public rclcpp::ServiceBase (Class ServiceBase)

  • public std::enable_shared_from_this< GenericService >

Class Documentation

class GenericService : public rclcpp::ServiceBase, public std::enable_shared_from_this<GenericService>

Public Types

using Request = void*
using Response = void*
using SharedRequest = std::shared_ptr<void>
using SharedResponse = std::shared_ptr<void>
using CallbackType = std::function<void(const SharedRequest, SharedResponse)>
using CallbackWithHeaderType = std::function<void(const std::shared_ptr<rmw_request_id_t>, const SharedRequest, SharedResponse)>

Public Functions

GenericService(std::shared_ptr<rcl_node_t> node_handle, const std::string &service_name, const std::string &service_type, GenericServiceCallback any_callback, rcl_service_options_t &service_options)

Default constructor.

The constructor for a Service is almost never called directly. Instead, services should be instantiated through the function rclcpp::create_service().

Parameters:
  • node_handle[in] NodeBaseInterface pointer that is used in part of the setup.

  • service_name[in] Name of the topic to publish to.

  • service_type[in] The name of service type, e.g. “std_srvs/srv/SetBool”.

  • any_callback[in] User defined callback to call when a client request is received.

  • service_options[in] options for the service.

GenericService() = delete
inline virtual ~GenericService()
bool take_request(SharedRequest request_out, rmw_request_id_t &request_id_out)

Take the next request from the service.

Parameters:
  • request_out[out] The reference to a service deserialized request object into which the middleware will copy the taken request.

  • request_id_out[out] The output id for the request which can be used to associate response with this request in the future.

Throws:

rclcpp::exceptions::RCLError – based exceptions if the underlying rcl calls fail.

Returns:

true if the request was taken, otherwise false.

virtual std::shared_ptr<void> create_request() override
std::shared_ptr<void> create_response()
virtual std::shared_ptr<rmw_request_id_t> create_request_header() override
virtual void handle_request(std::shared_ptr<rmw_request_id_t> request_header, std::shared_ptr<void> request) override
void send_response(rmw_request_id_t &req_id, SharedResponse &response)