ROS 2 rclcpp + rcl - humble  humble
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> GenericSubscription::create_message()
29 {
31 }
32 
33 std::shared_ptr<rclcpp::SerializedMessage> GenericSubscription::create_serialized_message()
34 {
35  return std::make_shared<rclcpp::SerializedMessage>(0);
36 }
37 
39  std::shared_ptr<void> &,
40  const rclcpp::MessageInfo &)
41 {
43  "handle_message is not implemented for GenericSubscription");
44 }
45 
46 void
48  const std::shared_ptr<rclcpp::SerializedMessage> & message,
49  const rclcpp::MessageInfo &)
50 {
51  callback_(message);
52 }
53 
55  void * message, const rclcpp::MessageInfo & message_info)
56 {
57  (void) message;
58  (void) message_info;
60  "handle_loaned_message is not implemented for GenericSubscription");
61 }
62 
63 void GenericSubscription::return_message(std::shared_ptr<void> & message)
64 {
65  auto typed_message = std::static_pointer_cast<rclcpp::SerializedMessage>(message);
66  return_serialized_message(typed_message);
67 }
68 
70  std::shared_ptr<rclcpp::SerializedMessage> & message)
71 {
72  message.reset();
73 }
74 
75 } // namespace rclcpp
RCLCPP_PUBLIC void return_message(std::shared_ptr< void > &message) override
Return the message borrowed in create_message.
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.