ROS 2 rclcpp + rcl - kilted  kilted
ROS 2 C++ Client Library with ROS Client Library
generic_subscription.cpp
1 // Copyright 2018, Bosch Software Innovations GmbH.
2 // Copyright 2021, Apex.AI Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #include "rclcpp/generic_subscription.hpp"
17 
18 #include <memory>
19 #include <string>
20 
21 #include "rcl/subscription.h"
22 
23 #include "rclcpp/exceptions.hpp"
24 
25 namespace rclcpp
26 {
27 
28 std::shared_ptr<void>
30 {
32 }
33 
34 std::shared_ptr<rclcpp::SerializedMessage>
36 {
37  return std::make_shared<rclcpp::SerializedMessage>(0);
38 }
39 
40 void
42  std::shared_ptr<void> &,
43  const rclcpp::MessageInfo &)
44 {
46  "handle_message is not implemented for GenericSubscription");
47 }
48 
49 void
51  const std::shared_ptr<rclcpp::SerializedMessage> & message,
52  const rclcpp::MessageInfo & message_info)
53 {
54  any_callback_.dispatch(message, message_info);
55 }
56 
57 void
59  [[maybe_unused]] void * message,
60  [[maybe_unused]] const rclcpp::MessageInfo & message_info)
61 {
63  "handle_loaned_message is not implemented for GenericSubscription");
64 }
65 
66 void
67 GenericSubscription::return_message(std::shared_ptr<void> & message)
68 {
69  auto typed_message = std::static_pointer_cast<rclcpp::SerializedMessage>(message);
70  return_serialized_message(typed_message);
71 }
72 
73 void
75  std::shared_ptr<rclcpp::SerializedMessage> & message)
76 {
77  message.reset();
78 }
79 
80 
81 // DYNAMIC TYPE ====================================================================================
82 // TODO(methylDragon): Reorder later
83 rclcpp::dynamic_typesupport::DynamicMessageType::SharedPtr
84 GenericSubscription::get_shared_dynamic_message_type()
85 {
87  "get_shared_dynamic_message_type is not implemented for GenericSubscription");
88 }
89 
90 rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr
91 GenericSubscription::get_shared_dynamic_message()
92 {
94  "get_shared_dynamic_message is not implemented for GenericSubscription");
95 }
96 
97 rclcpp::dynamic_typesupport::DynamicSerializationSupport::SharedPtr
98 GenericSubscription::get_shared_dynamic_serialization_support()
99 {
101  "get_shared_dynamic_serialization_support is not implemented for GenericSubscription");
102 }
103 
104 rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr
106 {
108  "create_dynamic_message is not implemented for GenericSubscription");
109 }
110 
111 void
112 GenericSubscription::return_dynamic_message(
113  [[maybe_unused]] rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr & message)
114 {
116  "return_dynamic_message is not implemented for GenericSubscription");
117 }
118 
119 void
120 GenericSubscription::handle_dynamic_message(
121  [[maybe_unused]] const rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr & message,
122  [[maybe_unused]] const rclcpp::MessageInfo & message_info)
123 {
125  "handle_dynamic_message is not implemented for GenericSubscription");
126 }
127 
128 } // namespace rclcpp
RCLCPP_PUBLIC void return_message(std::shared_ptr< void > &message) override
Return the message borrowed in create_message.
RCLCPP_PUBLIC rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr create_dynamic_message() override
Borrow a new serialized message (this clones!)
RCLCPP_PUBLIC void return_serialized_message(std::shared_ptr< rclcpp::SerializedMessage > &message) override
Return the message borrowed in create_serialized_message.
RCLCPP_PUBLIC void handle_message(std::shared_ptr< void > &message, const rclcpp::MessageInfo &message_info) override
Cast the message to a rclcpp::SerializedMessage and call the callback.
RCLCPP_PUBLIC std::shared_ptr< rclcpp::SerializedMessage > create_serialized_message() override
Borrow a new serialized message.
RCLCPP_PUBLIC void handle_loaned_message(void *loaned_message, const rclcpp::MessageInfo &message_info) override
This function is currently not implemented.
RCLCPP_PUBLIC std::shared_ptr< void > create_message() override
Borrow a new message.
RCLCPP_PUBLIC void handle_serialized_message(const std::shared_ptr< rclcpp::SerializedMessage > &serialized_message, const rclcpp::MessageInfo &message_info) override
Handle dispatching rclcpp::SerializedMessage to user callback.
Additional meta data about messages taken from subscriptions.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.