15 #ifndef RCLCPP__SERVICE_HPP_ 16 #define RCLCPP__SERVICE_HPP_ 36 #include "tracetools/tracetools.h" 88 template<
typename ServiceT>
106 const
std::
string & service_name,
109 :
ServiceBase(node_handle), any_callback_(any_callback)
111 using rosidl_typesupport_cpp::get_service_type_support_handle;
112 auto service_type_support_handle = get_service_type_support_handle<ServiceT>();
117 new rcl_service_t, [weak_node_handle](rcl_service_t * service)
119 auto handle = weak_node_handle.lock();
124 "Error in destruction of rcl service handle: %s",
131 "Error in destruction of rcl service handle: " 132 "the Node Handle was destructed too early. You will leak memory");
141 service_type_support_handle,
142 service_name.c_str(),
159 rclcpp_service_callback_added,
161 (
const void *)&any_callback_);
169 any_callback_(any_callback)
175 std::string(
"rcl_service_t in constructor argument must be initialized beforehand."));
181 rclcpp_service_callback_added,
183 (
const void *)&any_callback_);
191 any_callback_(any_callback)
197 std::string(
"rcl_service_t in constructor argument must be initialized beforehand."));
205 rclcpp_service_callback_added,
207 (
const void *)&any_callback_);
234 any_callback_.dispatch(request_header, typed_request, response);
235 send_response(request_header, response);
257 #endif // RCLCPP__SERVICE_HPP_ bool rcl_service_is_valid(const rcl_service_t *service)
Service(std::shared_ptr< rcl_node_t > node_handle, std::shared_ptr< rcl_service_t > service_handle, AnyServiceCallback< ServiceT > any_callback)
Definition: service.hpp:164
#define rcl_get_error_string
void send_response(std::shared_ptr< rmw_request_id_t > req_id, std::shared_ptr< typename ServiceT::Response > response)
Definition: service.hpp:238
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)
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
Logger get_logger(const std::string &name)
Return a named logger.
struct rcl_service_impl_t * impl
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
std::shared_ptr< rcl_service_t > get_service_handle()
bool owns_rcl_handle_
Definition: service.hpp:85
Definition: service.hpp:89
virtual void handle_request(std::shared_ptr< rmw_request_id_t > request_header, std::shared_ptr< void > request)=0
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.
ServiceBase(std::shared_ptr< rcl_node_t > node_handle)
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_ret_t rcl_send_response(const rcl_service_t *service, rmw_request_id_t *response_header, void *ros_response)
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
#define RCLCPP_ERROR(logger,...)
Definition: logging.hpp:1418
T static_pointer_cast(T... args)
const char * get_service_name()
std::shared_ptr< rcl_node_t > node_handle_
Definition: service.hpp:82
rcl_ret_t rcl_service_fini(rcl_service_t *service, rcl_node_t *node)
std::shared_ptr< void > create_request()
Definition: service.hpp:216
#define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(...)
Definition: macros.hpp:51
virtual ~Service()
Definition: service.hpp:212
Logger get_node_logger(const rcl_node_t *node)
Return a named logger using an rcl_node_t.
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
virtual std::shared_ptr< rmw_request_id_t > create_request_header()=0
#define RCL_RET_SERVICE_NAME_INVALID
Definition: service.hpp:41
const char * rcl_node_get_name(const rcl_node_t *node)
const char * rcl_node_get_namespace(const rcl_node_t *node)
Service(std::shared_ptr< rcl_node_t > node_handle, rcl_service_t *service_handle, AnyServiceCallback< ServiceT > any_callback)
Definition: service.hpp:186
rcl_service_t rcl_get_zero_initialized_service(void)
rcl_node_t * get_rcl_node_handle()
void handle_request(std::shared_ptr< rmw_request_id_t > request_header, std::shared_ptr< void > request)
Definition: service.hpp:228
virtual std::shared_ptr< void > create_request()=0
std::shared_ptr< rmw_request_id_t > create_request_header()
Definition: service.hpp:221
std::shared_ptr< rcl_service_t > service_handle_
Definition: service.hpp:84
Definition: any_service_callback.hpp:32