15 #ifndef RCLCPP__ANY_SERVICE_CALLBACK_HPP_ 16 #define RCLCPP__ANY_SERVICE_CALLBACK_HPP_ 21 #include <type_traits> 30 namespace any_service_callback
33 template<
typename ServiceT>
37 using SharedPtrCallback = std::function<void(
38 const std::shared_ptr<typename ServiceT::Request>,
39 std::shared_ptr<typename ServiceT::Response>
41 using SharedPtrWithRequestHeaderCallback = std::function<void(
42 const std::shared_ptr<rmw_request_id_t>,
43 const std::shared_ptr<typename ServiceT::Request>,
44 std::shared_ptr<typename ServiceT::Response>
47 SharedPtrCallback shared_ptr_callback_;
48 SharedPtrWithRequestHeaderCallback shared_ptr_with_request_header_callback_;
52 : shared_ptr_callback_(nullptr), shared_ptr_with_request_header_callback_(nullptr)
59 typename std::enable_if<
66 void set(CallbackT callback)
68 shared_ptr_callback_ = callback;
73 typename std::enable_if<
76 SharedPtrWithRequestHeaderCallback
80 void set(CallbackT callback)
82 shared_ptr_with_request_header_callback_ = callback;
86 std::shared_ptr<rmw_request_id_t> request_header,
87 std::shared_ptr<typename ServiceT::Request> request,
88 std::shared_ptr<typename ServiceT::Response> response)
90 if (shared_ptr_callback_ !=
nullptr) {
92 shared_ptr_callback_(request, response);
93 }
else if (shared_ptr_with_request_header_callback_ !=
nullptr) {
94 shared_ptr_with_request_header_callback_(request_header, request, response);
96 throw std::runtime_error(
"unexpected request without any callback set");
104 #endif // RCLCPP__ANY_SERVICE_CALLBACK_HPP_ AnyServiceCallback()
Definition: any_service_callback.hpp:51
Definition: allocator_common.hpp:24
void dispatch(std::shared_ptr< rmw_request_id_t > request_header, std::shared_ptr< typename ServiceT::Request > request, std::shared_ptr< typename ServiceT::Response > response)
Definition: any_service_callback.hpp:85
Definition: function_traits.hpp:141
Definition: any_service_callback.hpp:34