-
Notifications
You must be signed in to change notification settings - Fork 412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dnae adas/serialized ipm #973
Open
DensoADAS
wants to merge
45
commits into
ros2:rolling
Choose a base branch
from
DensoADAS:dnae_adas/serialized_ipm
base: rolling
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
9b73845
added "SerializationBase" and "Serialization" to convert a ROS2 messa…
c8162ba
added "SerializedContainer" as container of rcl_serialized_message_t,…
f3aab4f
extended "IntraProcessManager" for serialized messages:
9f1c10f
extended "SubscriptionIntraProcess" for serialized communication by:
a300c2f
added secon communication channel for intra process communication for…
86bd3a3
extended "Publisher" for serialized messages:
9d7ef52
extended "Publisher" for serialized messages:
c8522b3
updated "LifcecylePublisher" for serialized messages
29fea92
extended "create_publisher" and "create_publisher_factory" to pass me…
f9ef2c2
extended "Subscription" for serialized messages:
56b520e
extended "create_subscription" and "create_subscriptioncreate_publish…
0292142
added unit test for serialized intra process communication
5faf8f4
changed include notation
a3db006
beautified error output
d7a84ea
changed timing
af14ee7
* fixed code style
0c83e49
updated test_intra_process_communication:
bc228ee
uncrustified file
4c80594
fixed code style
2ddbe32
added missing member from rebase
4e1e744
removed unnecessary dependency
d8f1da9
adapted to multi waitables for ipm
d74c4ed
removed unnecessary include
d4536b3
updated to rclcpp::ok
7cff1aa
Update rclcpp/include/rclcpp/experimental/subscription_intra_process.hpp
DensoADAS 657d9a0
Update rclcpp/include/rclcpp/experimental/subscription_intra_process.hpp
DensoADAS 9b65b7c
* default deleter
18181f5
changes due to review of PR
4c7506f
uncrustify
2cefdca
added backwards compatibility for publishing serialized messages
2147026
initializing variables
9b436fa
fix include guards
a2fc8bd
enabled publishing of rcl_serialized_message_t
b482164
moved serialization and serialized message out of "experimental"
93dc826
added original constructor to LifcyclePublisher
35fd490
fixed year in header
5472d36
added comment
ab73a62
updated loop signature
4fa5f09
fixed memory loss
ff7a81f
reuse constructor
408343f
renamed variable
511476c
fixed check
1f8226a
line break
2411642
fixed include order
43a8446
renamed overloaded functions:
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -28,6 +28,8 @@ | |||||
#include "rclcpp/experimental/buffers/intra_process_buffer.hpp" | ||||||
#include "rclcpp/experimental/create_intra_process_buffer.hpp" | ||||||
#include "rclcpp/experimental/subscription_intra_process_base.hpp" | ||||||
#include "rclcpp/serialization.hpp" | ||||||
#include "rclcpp/serialized_message.hpp" | ||||||
#include "rclcpp/type_support_decl.hpp" | ||||||
#include "rclcpp/waitable.hpp" | ||||||
#include "tracetools/tracetools.h" | ||||||
|
@@ -37,6 +39,8 @@ namespace rclcpp | |||||
namespace experimental | ||||||
{ | ||||||
|
||||||
class SerializedMessage; | ||||||
|
||||||
template< | ||||||
typename MessageT, | ||||||
typename Alloc = std::allocator<void>, | ||||||
|
@@ -51,6 +55,10 @@ class SubscriptionIntraProcess : public SubscriptionIntraProcessBase | |||||
using MessageAlloc = typename MessageAllocTraits::allocator_type; | ||||||
using ConstMessageSharedPtr = std::shared_ptr<const MessageT>; | ||||||
using MessageUniquePtr = std::unique_ptr<MessageT, Deleter>; | ||||||
using CallbackMessageAllocTraits = allocator::AllocRebind<CallbackMessageT, Alloc>; | ||||||
using CallbackMessageAlloc = typename CallbackMessageAllocTraits::allocator_type; | ||||||
using CallbackMessageUniquePtr = std::unique_ptr<CallbackMessageT>; | ||||||
using CallbackMessageSharedPtr = std::shared_ptr<CallbackMessageT>; | ||||||
|
||||||
using BufferUniquePtr = typename rclcpp::experimental::buffers::IntraProcessBuffer< | ||||||
MessageT, | ||||||
|
@@ -64,11 +72,15 @@ class SubscriptionIntraProcess : public SubscriptionIntraProcessBase | |||||
rclcpp::Context::SharedPtr context, | ||||||
const std::string & topic_name, | ||||||
rmw_qos_profile_t qos_profile, | ||||||
rclcpp::IntraProcessBufferType buffer_type) | ||||||
rclcpp::IntraProcessBufferType buffer_type, | ||||||
std::shared_ptr<SerializationBase> serializer) | ||||||
: SubscriptionIntraProcessBase(topic_name, qos_profile), | ||||||
any_callback_(callback) | ||||||
any_callback_(callback), serializer_(serializer) | ||||||
{ | ||||||
if (!std::is_same<MessageT, CallbackMessageT>::value) { | ||||||
if (!std::is_same<MessageT, CallbackMessageT>::value && | ||||||
!std::is_same<MessageT, rclcpp::SerializedMessage>::value && | ||||||
!std::is_same<CallbackMessageT, rcl_serialized_message_t>::value) | ||||||
{ | ||||||
throw std::runtime_error("SubscriptionIntraProcess wrong callback type"); | ||||||
} | ||||||
|
||||||
|
@@ -142,18 +154,47 @@ class SubscriptionIntraProcess : public SubscriptionIntraProcessBase | |||||
(void)ret; | ||||||
} | ||||||
|
||||||
// convert from ROS2 message to rcl_serialized_message_t (serilizatino needed) | ||||||
template<typename T> | ||||||
typename std::enable_if<std::is_same<T, rcl_serialized_message_t>::value, void>::type | ||||||
typename std::enable_if< | ||||||
std::is_same<T, rcl_serialized_message_t>::value && | ||||||
!std::is_same<MessageT, rclcpp::SerializedMessage>::value, | ||||||
void>::type | ||||||
execute_impl() | ||||||
{ | ||||||
throw std::runtime_error("Subscription intra-process can't handle serialized messages"); | ||||||
if (nullptr == serializer_) { | ||||||
throw std::runtime_error("Subscription intra-process can't handle serialized messages"); | ||||||
} | ||||||
|
||||||
rmw_message_info_t msg_info = {}; | ||||||
msg_info.from_intra_process = true; | ||||||
|
||||||
ConstMessageSharedPtr msg = buffer_->consume_shared(); | ||||||
auto serialized_msg = | ||||||
serializer_->serialize_message(reinterpret_cast<const void *>(msg.get())); | ||||||
|
||||||
if (nullptr == serialized_msg) { | ||||||
throw std::runtime_error("Subscription intra-process could not serialize message"); | ||||||
} | ||||||
|
||||||
if (any_callback_.use_take_shared_method()) { | ||||||
any_callback_.dispatch_intra_process(serialized_msg, msg_info); | ||||||
} else { | ||||||
throw std::runtime_error( | ||||||
"Subscription intra-process for serialized " | ||||||
"messages does not support unique pointers."); | ||||||
} | ||||||
} | ||||||
|
||||||
// forward from ROS2 message to ROS2 message (same type) | ||||||
template<class T> | ||||||
typename std::enable_if<!std::is_same<T, rcl_serialized_message_t>::value, void>::type | ||||||
typename std::enable_if< | ||||||
!std::is_same<T, rcl_serialized_message_t>::value && | ||||||
!std::is_same<MessageT, rclcpp::SerializedMessage>::value, | ||||||
void>::type | ||||||
execute_impl() | ||||||
{ | ||||||
rmw_message_info_t msg_info; | ||||||
rmw_message_info_t msg_info = {}; | ||||||
msg_info.publisher_gid = {0, {0}}; | ||||||
msg_info.from_intra_process = true; | ||||||
|
||||||
|
@@ -166,8 +207,80 @@ class SubscriptionIntraProcess : public SubscriptionIntraProcessBase | |||||
} | ||||||
} | ||||||
|
||||||
// forward from rcl_serialized_message_t to SerializationMessage (no conversion needed) | ||||||
template<typename T> | ||||||
typename std::enable_if< | ||||||
std::is_same<T, rcl_serialized_message_t>::value && | ||||||
std::is_same<MessageT, rclcpp::SerializedMessage>::value, | ||||||
void>::type | ||||||
execute_impl() | ||||||
{ | ||||||
rmw_message_info_t msg_info = {}; | ||||||
msg_info.from_intra_process = true; | ||||||
|
||||||
if (any_callback_.use_take_shared_method()) { | ||||||
ConstMessageSharedPtr msg = buffer_->consume_shared(); | ||||||
if (msg == nullptr) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
throw std::runtime_error("Subscription intra-process could not get serialized message"); | ||||||
} | ||||||
any_callback_.dispatch_intra_process(msg, msg_info); | ||||||
} else { | ||||||
throw std::runtime_error( | ||||||
"Subscription intra-process for serialized " | ||||||
"messages does not support unique pointers."); | ||||||
} | ||||||
} | ||||||
|
||||||
// convert from rcl_serialized_message_t to ROS2 message (deserialization needed) | ||||||
template<class T> | ||||||
typename std::enable_if< | ||||||
!std::is_same<T, rcl_serialized_message_t>::value && | ||||||
std::is_same<MessageT, rclcpp::SerializedMessage>::value, | ||||||
void>::type | ||||||
execute_impl() | ||||||
{ | ||||||
if (nullptr == serializer_) { | ||||||
throw std::runtime_error("Subscription intra-process can't handle unserialized messages"); | ||||||
} | ||||||
|
||||||
ConstMessageSharedPtr serialized_container = buffer_->consume_shared(); | ||||||
if (nullptr == serialized_container) { | ||||||
throw std::runtime_error("Subscription intra-process could not get serialized message"); | ||||||
} | ||||||
|
||||||
rmw_message_info_t msg_info = {}; | ||||||
msg_info.from_intra_process = true; | ||||||
|
||||||
if (any_callback_.use_take_shared_method()) { | ||||||
CallbackMessageSharedPtr msg = construct_unique(); | ||||||
serializer_->deserialize_message( | ||||||
serialized_container.get(), | ||||||
reinterpret_cast<void *>(msg.get())); | ||||||
any_callback_.dispatch_intra_process(msg, msg_info); | ||||||
} else { | ||||||
CallbackMessageUniquePtr msg = construct_unique(); | ||||||
serializer_->deserialize_message( | ||||||
serialized_container.get(), | ||||||
reinterpret_cast<void *>(msg.get())); | ||||||
any_callback_.dispatch_intra_process(std::move(msg), msg_info); | ||||||
} | ||||||
} | ||||||
|
||||||
CallbackMessageUniquePtr construct_unique() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be a (inline) free function (anonymous namespace) which takes the allocator as a first argument. |
||||||
{ | ||||||
CallbackMessageUniquePtr unique_msg; | ||||||
auto ptr = CallbackMessageAllocTraits::allocate(*message_allocator_.get(), 1); | ||||||
CallbackMessageAllocTraits::construct(*message_allocator_.get(), ptr); | ||||||
unique_msg = CallbackMessageUniquePtr(ptr); | ||||||
|
||||||
return unique_msg; | ||||||
} | ||||||
|
||||||
AnySubscriptionCallback<CallbackMessageT, Alloc> any_callback_; | ||||||
BufferUniquePtr buffer_; | ||||||
std::shared_ptr<SerializationBase> serializer_; | ||||||
std::shared_ptr<CallbackMessageAlloc> message_allocator_ = | ||||||
std::make_shared<CallbackMessageAlloc>(); | ||||||
}; | ||||||
|
||||||
} // namespace experimental | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do I need this overload if both methods are templated by
MessageT
? The call toconst auto type_support = *rosidl_typesupport_cpp::get_message_type_support_handle<MessageT>();
could be done in the original function or even within thecreate_publisher_factory
function, couldn't it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this allows an instantion with type "rcl_serialized_message_t" for generic publishers without previously known message type (e.g. for rosbag2)
Example:
auto publisher = rclcpp::create_publisher<rcl_serialized_message_t>( node, "/topic", *rosidl_typesupport_cpp::get_message_type_support_handle<test_msgs::msg::Strings>(), rclcpp::QoS(10));