|
4 | 4 | #ifndef ROS_BABEL_FISH_BABEL_FISH_ANY_SERVICE_CALLBACK_HPP |
5 | 5 | #define ROS_BABEL_FISH_BABEL_FISH_ANY_SERVICE_CALLBACK_HPP |
6 | 6 |
|
| 7 | +#include "ros_babel_fish/messages/compound_message.hpp" |
| 8 | + |
7 | 9 | #include <rclcpp/any_service_callback.hpp> |
8 | 10 |
|
9 | 11 | namespace ros_babel_fish |
10 | 12 | { |
11 | 13 | class BabelFishService; |
12 | | -class CompoundMessage; |
13 | 14 |
|
14 | 15 | /** |
15 | 16 | * Designed to be compatible with rclcpp::AnyServiceCallback compatible callbacks with equivalent tracing support. |
@@ -53,26 +54,38 @@ class AnyServiceCallback |
53 | 54 | } |
54 | 55 | } |
55 | 56 |
|
56 | | - void dispatch( const std::shared_ptr<BabelFishService> &service_handle, |
57 | | - const std::shared_ptr<rmw_request_id_t> &request_header, |
58 | | - std::shared_ptr<CompoundMessage> request, std::shared_ptr<CompoundMessage> response ) |
| 57 | + //! Dispatches the request to the registered callback. |
| 58 | + //! @return The filled response which the caller should send, or nullptr if the callback deferred |
| 59 | + //! the response (a defer variant), in which case the caller must not send. |
| 60 | + std::shared_ptr<CompoundMessage> dispatch( const std::shared_ptr<BabelFishService> &service_handle, |
| 61 | + const std::shared_ptr<rmw_request_id_t> &request_header, |
| 62 | + std::shared_ptr<CompoundMessage> request, |
| 63 | + const MessageMembersIntrospection &response_type ) |
59 | 64 | { |
60 | 65 | TRACEPOINT( callback_start, static_cast<const void *>( this ), false ); |
| 66 | + if ( std::holds_alternative<SharedPtrDeferResponseCallback>( callback_ ) ) { |
| 67 | + const auto &cb = std::get<SharedPtrDeferResponseCallback>( callback_ ); |
| 68 | + cb( request_header, std::move( request ) ); |
| 69 | + TRACEPOINT( callback_end, static_cast<const void *>( this ) ); |
| 70 | + return nullptr; |
| 71 | + } |
| 72 | + if ( std::holds_alternative<SharedPtrDeferResponseCallbackWithServiceHandle>( callback_ ) ) { |
| 73 | + const auto &cb = std::get<SharedPtrDeferResponseCallbackWithServiceHandle>( callback_ ); |
| 74 | + cb( service_handle, request_header, std::move( request ) ); |
| 75 | + TRACEPOINT( callback_end, static_cast<const void *>( this ) ); |
| 76 | + return nullptr; |
| 77 | + } |
| 78 | + auto response = CompoundMessage::make_shared( response_type ); |
61 | 79 | if ( std::holds_alternative<SharedPtrCallback>( callback_ ) ) { |
62 | 80 | (void)request_header; |
63 | 81 | const auto &cb = std::get<SharedPtrCallback>( callback_ ); |
64 | 82 | cb( std::move( request ), response ); |
65 | 83 | } else if ( std::holds_alternative<SharedPtrWithRequestHeaderCallback>( callback_ ) ) { |
66 | 84 | const auto &cb = std::get<SharedPtrWithRequestHeaderCallback>( callback_ ); |
67 | 85 | cb( request_header, std::move( request ), response ); |
68 | | - } else if ( std::holds_alternative<SharedPtrDeferResponseCallback>( callback_ ) ) { |
69 | | - const auto &cb = std::get<SharedPtrDeferResponseCallback>( callback_ ); |
70 | | - cb( request_header, std::move( request ) ); |
71 | | - } else if ( std::holds_alternative<SharedPtrDeferResponseCallbackWithServiceHandle>( callback_ ) ) { |
72 | | - const auto &cb = std::get<SharedPtrDeferResponseCallbackWithServiceHandle>( callback_ ); |
73 | | - cb( service_handle, request_header, std::move( request ) ); |
74 | 86 | } |
75 | 87 | TRACEPOINT( callback_end, static_cast<const void *>( this ) ); |
| 88 | + return response; |
76 | 89 | } |
77 | 90 |
|
78 | 91 | void register_callback_for_tracing() |
|
0 commit comments