ROS 2 rclcpp + rcl - lyrical  lyrical
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 {
44  any_callback_.disable();
45  for (const auto & [_, event_ptr] : event_handlers_) {
46  if (event_ptr) {
47  event_ptr->disable();
48  }
49  }
50 }
51 
52 void
54 {
56  any_callback_.enable();
57  for (const auto & [_, event_ptr] : event_handlers_) {
58  if (event_ptr) {
59  event_ptr->enable();
60  }
61  }
62 }
63 
64 void
66  std::shared_ptr<void> &,
67  const rclcpp::MessageInfo &)
68 {
70  "handle_message is not implemented for GenericSubscription");
71 }
72 
73 void
75  const std::shared_ptr<rclcpp::SerializedMessage> & message,
76  const rclcpp::MessageInfo & message_info)
77 {
78  any_callback_.dispatch(message, message_info);
79 }
80 
81 void
83  [[maybe_unused]] void * message,
84  [[maybe_unused]] const rclcpp::MessageInfo & message_info)
85 {
87  "handle_loaned_message is not implemented for GenericSubscription");
88 }
89 
90 void
91 GenericSubscription::return_message(std::shared_ptr<void> & message)
92 {
93  auto typed_message = std::static_pointer_cast<rclcpp::SerializedMessage>(message);
94  return_serialized_message(typed_message);
95 }
96 
97 void
99  std::shared_ptr<rclcpp::SerializedMessage> & message)
100 {
101  message.reset();
102 }
103 
104 
105 // DYNAMIC TYPE ====================================================================================
106 // TODO(methylDragon): Reorder later
107 rclcpp::dynamic_typesupport::DynamicMessageType::SharedPtr
108 GenericSubscription::get_shared_dynamic_message_type()
109 {
111  "get_shared_dynamic_message_type is not implemented for GenericSubscription");
112 }
113 
114 rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr
115 GenericSubscription::get_shared_dynamic_message()
116 {
118  "get_shared_dynamic_message is not implemented for GenericSubscription");
119 }
120 
121 rclcpp::dynamic_typesupport::DynamicSerializationSupport::SharedPtr
122 GenericSubscription::get_shared_dynamic_serialization_support()
123 {
125  "get_shared_dynamic_serialization_support is not implemented for GenericSubscription");
126 }
127 
128 rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr
130 {
132  "create_dynamic_message is not implemented for GenericSubscription");
133 }
134 
135 void
136 GenericSubscription::return_dynamic_message(
137  [[maybe_unused]] rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr & message)
138 {
140  "return_dynamic_message is not implemented for GenericSubscription");
141 }
142 
143 void
144 GenericSubscription::handle_dynamic_message(
145  [[maybe_unused]] const rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr & message,
146  [[maybe_unused]] const rclcpp::MessageInfo & message_info)
147 {
149  "handle_dynamic_message is not implemented for GenericSubscription");
150 }
151 
152 } // namespace rclcpp
void disable()
Disable the callback from being called during dispatch.
void enable()
Enable the callback to be called during dispatch.
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 void disable_callbacks() override
Disable callbacks from being called.
RCLCPP_PUBLIC void enable_callbacks() override
Enable the callbacks to be called.
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.
virtual RCLCPP_PUBLIC void enable_callbacks()
Enable the callbacks to be called.
virtual RCLCPP_PUBLIC void disable_callbacks()
Disable callbacks from being called.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.