rclcpp
master
C++ ROS Client Library API
|
Go to the documentation of this file.
15 #ifndef RCLCPP__SERVICE_HPP_
16 #define RCLCPP__SERVICE_HPP_
25 #include "rcl/error_handling.h"
37 #include "tracetools/tracetools.h"
143 template<
typename ServiceT>
172 const
std::
string & service_name,
175 :
ServiceBase(node_handle), any_callback_(any_callback)
177 using rosidl_typesupport_cpp::get_service_type_support_handle;
178 auto service_type_support_handle = get_service_type_support_handle<ServiceT>();
186 rclcpp::get_node_logger(handle.get()).get_child(
"rclcpp"),
187 "Error in destruction of rcl service handle: %s",
188 rcl_get_error_string().str);
198 service_type_support_handle,
199 service_name.c_str(),
216 rclcpp_service_callback_added,
218 static_cast<const void *
>(&any_callback_));
219 #ifndef TRACETOOLS_DISABLED
220 any_callback_.register_callback_for_tracing();
239 any_callback_(any_callback)
245 std::string(
"rcl_service_t in constructor argument must be initialized beforehand."));
251 rclcpp_service_callback_added,
253 static_cast<const void *
>(&any_callback_));
254 #ifndef TRACETOOLS_DISABLED
255 any_callback_.register_callback_for_tracing();
274 any_callback_(any_callback)
280 std::string(
"rcl_service_t in constructor argument must be initialized beforehand."));
288 rclcpp_service_callback_added,
290 static_cast<const void *
>(&any_callback_));
291 #ifndef TRACETOOLS_DISABLED
292 any_callback_.register_callback_for_tracing();
323 return std::make_shared<typename ServiceT::Request>();
329 return std::make_shared<rmw_request_id_t>();
337 auto typed_request = std::static_pointer_cast<typename ServiceT::Request>(request);
338 auto response = std::make_shared<typename ServiceT::Response>();
339 any_callback_.dispatch(request_header, typed_request, response);
361 #endif // RCLCPP__SERVICE_HPP_
virtual void handle_request(std::shared_ptr< rmw_request_id_t > request_header, std::shared_ptr< void > request)=0
const char * rcl_node_get_name(const rcl_node_t *node)
#define RCL_RET_SERVICE_NAME_INVALID
Definition: any_service_callback.hpp:33
struct rcl_service_impl_t * impl
const char * rcl_node_get_namespace(const rcl_node_t *node)
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
bool owns_rcl_handle_
Definition: service.hpp:138
rcl_ret_t rcl_service_init(rcl_service_t *service, const rcl_node_t *node, const rosidl_service_type_support_t *type_support, const char *service_name, const rcl_service_options_t *options)
Definition: service.hpp:144
void send_response(rmw_request_id_t &req_id, typename ServiceT::Response &response)
Definition: service.hpp:344
Service(std::shared_ptr< rcl_node_t > node_handle, std::shared_ptr< rcl_service_t > service_handle, AnyServiceCallback< ServiceT > any_callback)
Default constructor.
Definition: service.hpp:234
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
std::shared_ptr< rcl_service_t > service_handle_
Definition: service.hpp:137
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
std::shared_ptr< void > create_request() override
Definition: service.hpp:321
virtual std::shared_ptr< rmw_request_id_t > create_request_header()=0
virtual ~Service()
Definition: service.hpp:298
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
const char * get_service_name()
Return the name of the service.
std::string expand_topic_or_service_name(const std::string &name, const std::string &node_name, const std::string &namespace_, bool is_service=false)
Expand a topic or service name and throw if it is not valid.
rcl_ret_t rcl_send_response(const rcl_service_t *service, rmw_request_id_t *response_header, void *ros_response)
ServiceBase(std::shared_ptr< rcl_node_t > node_handle)
bool exchange_in_use_by_wait_set_state(bool in_use_state)
Exchange the "in use by wait set" state for this service.
rcl_ret_t rcl_service_fini(rcl_service_t *service, rcl_node_t *node)
Service(std::shared_ptr< rcl_node_t > node_handle, rcl_service_t *service_handle, AnyServiceCallback< ServiceT > any_callback)
Default constructor.
Definition: service.hpp:269
std::shared_ptr< rcl_service_t > get_service_handle()
Return the rcl_service_t service handle in a std::shared_ptr.
void handle_request(std::shared_ptr< rmw_request_id_t > request_header, std::shared_ptr< void > request) override
Definition: service.hpp:333
virtual std::shared_ptr< void > create_request()=0
std::atomic< bool > in_use_by_wait_set_
Definition: service.hpp:140
std::shared_ptr< rcl_node_t > node_handle_
Definition: service.hpp:135
rcl_node_t * get_rcl_node_handle()
std::shared_ptr< rmw_request_id_t > create_request_header() override
Definition: service.hpp:327
#define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(...)
Definition: macros.hpp:51
void throw_from_rcl_error(rcl_ret_t ret, const std::string &prefix="", const rcl_error_state_t *error_state=nullptr, void(*reset_error)()=rcl_reset_error)
Throw a C++ std::exception which was created based on an rcl error.
rcl_service_t rcl_get_zero_initialized_service(void)
Definition: service.hpp:42
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.
bool rcl_service_is_valid(const rcl_service_t *service)
bool take_request(typename ServiceT::Request &request_out, rmw_request_id_t &request_id_out)
Take the next request from the service.
Definition: service.hpp:315