ROS 2 rclcpp + rcl - rolling  rolling-a919a6e5
ROS 2 C++ Client Library with ROS Client Library
Public Types | Public Member Functions | List of all members
rclcpp::GenericService Class Reference
Inheritance diagram for rclcpp::GenericService:
Inheritance graph
[legend]
Collaboration diagram for rclcpp::GenericService:
Collaboration graph
[legend]

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 Member Functions

RCLCPP_PUBLIC 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. More...
 
RCLCPP_PUBLIC bool take_request (SharedRequest request_out, rmw_request_id_t &request_id_out)
 Take the next request from the service. More...
 
RCLCPP_PUBLIC std::shared_ptr< void > create_request () override
 
RCLCPP_PUBLIC std::shared_ptr< void > create_response ()
 
RCLCPP_PUBLIC std::shared_ptr< rmw_request_id_t > create_request_header () override
 
RCLCPP_PUBLIC void handle_request (std::shared_ptr< rmw_request_id_t > request_header, std::shared_ptr< void > request) override
 
RCLCPP_PUBLIC void send_response (rmw_request_id_t &req_id, SharedResponse &response)
 
- Public Member Functions inherited from rclcpp::ServiceBase
RCLCPP_PUBLIC ServiceBase (std::shared_ptr< rcl_node_t > node_handle)
 
RCLCPP_PUBLIC const char * get_service_name ()
 Return the name of the service. More...
 
RCLCPP_PUBLIC std::shared_ptr< rcl_service_tget_service_handle ()
 Return the rcl_service_t service handle in a std::shared_ptr. More...
 
RCLCPP_PUBLIC std::shared_ptr< const rcl_service_tget_service_handle () const
 Return the rcl_service_t service handle in a std::shared_ptr. More...
 
RCLCPP_PUBLIC bool take_type_erased_request (void *request_out, rmw_request_id_t &request_id_out)
 Take the next request from the service as a type erased pointer. More...
 
RCLCPP_PUBLIC bool exchange_in_use_by_wait_set_state (bool in_use_state)
 Exchange the "in use by wait set" state for this service. More...
 
RCLCPP_PUBLIC rclcpp::QoS get_response_publisher_actual_qos () const
 Get the actual response publisher QoS settings, after the defaults have been determined. More...
 
RCLCPP_PUBLIC rclcpp::QoS get_request_subscription_actual_qos () const
 Get the actual request subscription QoS settings, after the defaults have been determined. More...
 
void set_on_new_request_callback (std::function< void(size_t)> callback)
 Set a callback to be called when each new request is received. More...
 
void clear_on_new_request_callback ()
 Unset the callback registered for new requests, if any.
 

Additional Inherited Members

- Protected Member Functions inherited from rclcpp::ServiceBase
RCLCPP_PUBLIC rcl_node_tget_rcl_node_handle ()
 
RCLCPP_PUBLIC const rcl_node_tget_rcl_node_handle () const
 
RCLCPP_PUBLIC void set_on_new_request_callback (rcl_event_callback_t callback, const void *user_data)
 
- Protected Attributes inherited from rclcpp::ServiceBase
std::shared_ptr< rcl_node_tnode_handle_
 
std::recursive_mutex callback_mutex_
 
std::function< void(size_t)> on_new_request_callback_ {nullptr}
 
std::shared_ptr< rcl_service_tservice_handle_
 
bool owns_rcl_handle_ = true
 
rclcpp::Logger node_logger_
 
std::atomic< bool > in_use_by_wait_set_ {false}
 

Detailed Description

Definition at line 216 of file generic_service.hpp.

Constructor & Destructor Documentation

◆ GenericService()

rclcpp::GenericService::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
[in]node_handleNodeBaseInterface pointer that is used in part of the setup.
[in]service_nameName of the topic to publish to.
[in]service_typeThe name of service type, e.g. "std_srvs/srv/SetBool".
[in]any_callbackUser defined callback to call when a client request is received.
[in]service_optionsoptions for the service.

Definition at line 19 of file generic_service.cpp.

References rclcpp::expand_topic_or_service_name(), rclcpp::Logger::get_child(), rclcpp::get_message_typesupport_handle(), rclcpp::get_node_logger(), rclcpp::ServiceBase::get_service_handle(), rclcpp::get_service_typesupport_handle(), rclcpp::get_typesupport_library(), rcl_get_zero_initialized_service(), rcl_node_get_name(), rcl_node_get_namespace(), RCL_RET_OK, RCL_RET_SERVICE_NAME_INVALID, rcl_service_fini(), and rcl_service_init().

Here is the call graph for this function:

Member Function Documentation

◆ take_request()

bool rclcpp::GenericService::take_request ( SharedRequest  request_out,
rmw_request_id_t &  request_id_out 
)

Take the next request from the service.

See also
ServiceBase::take_type_erased_request().
Parameters
[out]request_outThe reference to a service deserialized request object into which the middleware will copy the taken request.
[out]request_id_outThe output id for the request which can be used to associate response with this request in the future.
Returns
true if the request was taken, otherwise false.
Exceptions
rclcpp::exceptions::RCLErrorbased exceptions if the underlying rcl calls fail.

Definition at line 100 of file generic_service.cpp.

References rclcpp::ServiceBase::take_type_erased_request().

Here is the call graph for this function:

The documentation for this class was generated from the following files: