rclcpp  master
C++ ROS Client Library API
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
rclcpp::ServiceBase Class Referenceabstract

#include <service.hpp>

Inheritance diagram for rclcpp::ServiceBase:
Inheritance graph
[legend]
Collaboration diagram for rclcpp::ServiceBase:
Collaboration graph
[legend]

Public Member Functions

 ServiceBase (std::shared_ptr< rcl_node_t > node_handle)
 
virtual ~ServiceBase ()
 
const char * get_service_name ()
 Return the name of the service. More...
 
std::shared_ptr< rcl_service_tget_service_handle ()
 Return the rcl_service_t service handle in a std::shared_ptr. More...
 
std::shared_ptr< const rcl_service_tget_service_handle () const
 Return the rcl_service_t service handle in a std::shared_ptr. More...
 
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...
 
virtual std::shared_ptr< void > create_request ()=0
 
virtual std::shared_ptr< rmw_request_id_tcreate_request_header ()=0
 
virtual void handle_request (std::shared_ptr< rmw_request_id_t > request_header, std::shared_ptr< void > request)=0
 
bool exchange_in_use_by_wait_set_state (bool in_use_state)
 Exchange the "in use by wait set" state for this service. More...
 

Protected Member Functions

rcl_node_tget_rcl_node_handle ()
 
const rcl_node_tget_rcl_node_handle () const
 

Protected Attributes

std::shared_ptr< rcl_node_tnode_handle_
 
std::shared_ptr< rcl_service_tservice_handle_
 
bool owns_rcl_handle_ = true
 
std::atomic< bool > in_use_by_wait_set_ {false}
 

Constructor & Destructor Documentation

◆ ServiceBase()

rclcpp::ServiceBase::ServiceBase ( std::shared_ptr< rcl_node_t node_handle)
explicit

◆ ~ServiceBase()

virtual rclcpp::ServiceBase::~ServiceBase ( )
virtual

Member Function Documentation

◆ get_service_name()

const char* rclcpp::ServiceBase::get_service_name ( )

Return the name of the service.

Returns
The name of the service.

◆ get_service_handle() [1/2]

std::shared_ptr<rcl_service_t> rclcpp::ServiceBase::get_service_handle ( )

Return the rcl_service_t service handle in a std::shared_ptr.

This handle remains valid after the Service is destroyed. The actual rcl service is not finalized until it is out of scope everywhere.

◆ get_service_handle() [2/2]

std::shared_ptr<const rcl_service_t> rclcpp::ServiceBase::get_service_handle ( ) const

Return the rcl_service_t service handle in a std::shared_ptr.

This handle remains valid after the Service is destroyed. The actual rcl service is not finalized until it is out of scope everywhere.

◆ take_type_erased_request()

bool rclcpp::ServiceBase::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.

This type erased version of

See also
Service::take_request() is useful when using the service in a type agnostic way with methods like ServiceBase::create_request(), ServiceBase::create_request_header(), and ServiceBase::handle_request().
Parameters
[out]request_outThe type erased pointer to a service 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.

◆ create_request()

virtual std::shared_ptr<void> rclcpp::ServiceBase::create_request ( )
pure virtual

◆ create_request_header()

virtual std::shared_ptr<rmw_request_id_t> rclcpp::ServiceBase::create_request_header ( )
pure virtual

◆ handle_request()

virtual void rclcpp::ServiceBase::handle_request ( std::shared_ptr< rmw_request_id_t request_header,
std::shared_ptr< void >  request 
)
pure virtual

◆ exchange_in_use_by_wait_set_state()

bool rclcpp::ServiceBase::exchange_in_use_by_wait_set_state ( bool  in_use_state)

Exchange the "in use by wait set" state for this service.

This is used to ensure this service is not used by multiple wait sets at the same time.

Parameters
[in]in_use_statethe new state to exchange into the state, true indicates it is now in use by a wait set, and false is that it is no longer in use by a wait set.
Returns
the previous state.

◆ get_rcl_node_handle() [1/2]

rcl_node_t* rclcpp::ServiceBase::get_rcl_node_handle ( )
protected

◆ get_rcl_node_handle() [2/2]

const rcl_node_t* rclcpp::ServiceBase::get_rcl_node_handle ( ) const
protected

Member Data Documentation

◆ node_handle_

std::shared_ptr<rcl_node_t> rclcpp::ServiceBase::node_handle_
protected

◆ service_handle_

std::shared_ptr<rcl_service_t> rclcpp::ServiceBase::service_handle_
protected

◆ owns_rcl_handle_

bool rclcpp::ServiceBase::owns_rcl_handle_ = true
protected

◆ in_use_by_wait_set_

std::atomic<bool> rclcpp::ServiceBase::in_use_by_wait_set_ {false}
protected

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