15 #include "rclcpp/service.hpp"
23 #include "rclcpp/any_service_callback.hpp"
24 #include "rclcpp/macros.hpp"
25 #include "rmw/error_handling.h"
30 ServiceBase::ServiceBase(std::shared_ptr<rcl_node_t> node_handle)
31 : node_handle_(node_handle),
35 ServiceBase::~ServiceBase()
50 rclcpp::exceptions::throw_from_rcl_error(ret);
61 std::shared_ptr<rcl_service_t>
64 return service_handle_;
67 std::shared_ptr<const rcl_service_t>
70 return service_handle_;
74 ServiceBase::get_rcl_node_handle()
76 return node_handle_.get();
80 ServiceBase::get_rcl_node_handle()
const
82 return node_handle_.get();
88 return in_use_by_wait_set_.exchange(in_use_state);
94 const rmw_qos_profile_t * qos =
98 std::string(
"failed to get service's response publisher qos settings: ") +
99 rcl_get_error_string().str;
101 throw std::runtime_error(msg);
107 return response_publisher_qos;
113 const rmw_qos_profile_t * qos =
117 std::string(
"failed to get service's request subscription qos settings: ") +
118 rcl_get_error_string().str;
120 throw std::runtime_error(msg);
126 return request_subscription_qos;
133 service_handle_.get(),
138 using rclcpp::exceptions::throw_from_rcl_error;
139 throw_from_rcl_error(ret,
"failed to set the on new request callback for service");
Encapsulation of Quality of Service settings.
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.
RCLCPP_PUBLIC rclcpp::QoS get_request_subscription_actual_qos() const
Get the actual request subscription QoS settings, after the defaults have been determined.
RCLCPP_PUBLIC rclcpp::QoS get_response_publisher_actual_qos() const
Get the actual response publisher QoS settings, after the defaults have been determined.
void set_on_new_request_callback(std::function< void(size_t)> callback)
Set a callback to be called when each new request is received.
void clear_on_new_request_callback()
Unset the callback registered for new requests, if any.
RCLCPP_PUBLIC std::shared_ptr< rcl_service_t > get_service_handle()
Return the rcl_service_t service handle in a std::shared_ptr.
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.
RCLCPP_PUBLIC const char * get_service_name()
Return the name of the service.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
RCLCPP_PUBLIC Logger get_node_logger(const rcl_node_t *node)
Return a named logger using an rcl_node_t.
RCL_PUBLIC RCL_WARN_UNUSED const rmw_qos_profile_t * rcl_service_request_subscription_get_actual_qos(const rcl_service_t *service)
Get the actual qos settings of the service's request subscription.
RCL_PUBLIC RCL_WARN_UNUSED const char * rcl_service_get_service_name(const rcl_service_t *service)
Get the topic name for the service.
RCL_PUBLIC RCL_WARN_UNUSED const rmw_qos_profile_t * rcl_service_response_publisher_get_actual_qos(const rcl_service_t *service)
Get the actual qos settings of the service's response publisher.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_service_set_on_new_request_callback(const rcl_service_t *service, rcl_event_callback_t callback, const void *user_data)
Set the on new request callback function for the service.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_take_request(const rcl_service_t *service, rmw_request_id_t *request_header, void *ros_request)
Backwards compatibility function to take a pending ROS request using a rcl service.
Structure which encapsulates a ROS Node.
static QoSInitialization from_rmw(const rmw_qos_profile_t &rmw_qos)
Create a QoSInitialization from an existing rmw_qos_profile_t, using its history and depth.
#define RCL_RET_OK
Success return code.
#define RCL_RET_SERVICE_TAKE_FAILED
Failed to take a request from the service return code.
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.