Skip to content

Commit

Permalink
Style fixes for the linters. (ros2#9)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
  • Loading branch information
clalancette committed Dec 8, 2021
1 parent 2708d54 commit ce7ecfb
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 69 deletions.
15 changes: 6 additions & 9 deletions rclcpp/include/rclcpp/any_subscription_callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#define RCLCPP__ANY_SUBSCRIPTION_CALLBACK_HPP_

#include <functional>
#include <iostream> //TODO remove when removed std::cout s
#include <memory>
#include <stdexcept>
#include <type_traits>
Expand Down Expand Up @@ -726,14 +725,14 @@ class AnySubscriptionCallback
callback(message, message_info);
}
// conditions for ros message type
else if constexpr (std::is_same_v<T, ConstRefROSMessageCallback>) { // NOLINT
else if constexpr (std::is_same_v<T, ConstRefROSMessageCallback>) { // NOLINT[readability/braces]
if constexpr (is_ta) {
auto local = convert_custom_type_to_ros_message_unique_ptr(*message);
callback(*local);
} else {
callback(*message);
}
} else if constexpr (std::is_same_v<T, ConstRefWithInfoROSMessageCallback>) {
} else if constexpr (std::is_same_v<T, ConstRefWithInfoROSMessageCallback>) { // NOLINT[readability/braces]
if constexpr (is_ta) {
auto local = convert_custom_type_to_ros_message_unique_ptr(*message);
callback(*local, message_info);
Expand Down Expand Up @@ -802,12 +801,11 @@ class AnySubscriptionCallback
TRACEPOINT(callback_end, static_cast<const void *>(this));
}

void
void
dispatch_intra_process(
std::unique_ptr<SubscribedType, SubscribedTypeDeleter> message,
const rclcpp::MessageInfo & message_info)
{

TRACEPOINT(callback_start, static_cast<const void *>(this), true);
// Check if the variant is "unset", throw if it is.
if (callback_variant_.index() == 0) {
Expand All @@ -830,8 +828,7 @@ class AnySubscriptionCallback
} else if constexpr ( // NOLINT[readability/braces]
is_ta && (
std::is_same_v<T, UniquePtrCallback>||
std::is_same_v<T, SharedPtrCallback>)
)
std::is_same_v<T, SharedPtrCallback>))
{
callback(std::move(message));
} else if constexpr ( // NOLINT[readability/braces]
Expand All @@ -857,14 +854,14 @@ class AnySubscriptionCallback
callback(std::move(message), message_info);
}
// conditions for ros message type
else if constexpr (std::is_same_v<T, ConstRefROSMessageCallback>) { // NOLINT
else if constexpr (std::is_same_v<T, ConstRefROSMessageCallback>) { // NOLINT[readability/braces]
if constexpr (is_ta) {
auto local = convert_custom_type_to_ros_message_unique_ptr(*message);
callback(*local);
} else {
callback(*message);
}
} else if constexpr (std::is_same_v<T, ConstRefWithInfoROSMessageCallback>) {
} else if constexpr (std::is_same_v<T, ConstRefWithInfoROSMessageCallback>) { // NOLINT[readability/braces]
if constexpr (is_ta) {
auto local = convert_custom_type_to_ros_message_unique_ptr(*message);
callback(*local, message_info);
Expand Down
74 changes: 37 additions & 37 deletions rclcpp/include/rclcpp/experimental/intra_process_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class IntraProcessManager
std::shared_ptr<PublishedType> msg = std::move(message);

this->template add_shared_msg_to_buffers<MessageT, PublishedType, ROSMessageType, Alloc,
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator>(
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator>(
msg,
sub_ids.take_shared_subscriptions,
ros_message_type_allocator);
Expand All @@ -231,8 +231,8 @@ class IntraProcessManager
sub_ids.take_ownership_subscriptions.end());

this->template add_owned_msg_to_buffers<MessageT, PublishedType, ROSMessageType, Alloc,
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator, ROSMessageTypeDeleter,
PublishedTypeAllocator>(
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator, ROSMessageTypeDeleter,
PublishedTypeAllocator>(
std::move(message),
concatenated_vector,
published_type_allocator,
Expand All @@ -241,16 +241,18 @@ class IntraProcessManager
} else {
// Construct a new shared pointer from the message
// for the buffers that do not require ownership
auto shared_msg = std::allocate_shared<PublishedType, PublishedTypeAllocator>(published_type_allocator, *message);
auto shared_msg = std::allocate_shared<PublishedType, PublishedTypeAllocator>(
published_type_allocator,
*message);

this->template add_shared_msg_to_buffers<MessageT, PublishedType, ROSMessageType, Alloc,
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator>(
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator>(
shared_msg,
sub_ids.take_shared_subscriptions,
ros_message_type_allocator);
this->template add_owned_msg_to_buffers<MessageT, PublishedType, ROSMessageType, Alloc, Deleter,
ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator, ROSMessageTypeDeleter,
PublishedTypeAllocator>(
this->template add_owned_msg_to_buffers<MessageT, PublishedType, ROSMessageType, Alloc,
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator, ROSMessageTypeDeleter,
PublishedTypeAllocator>(
std::move(message),
sub_ids.take_ownership_subscriptions,
published_type_allocator,
Expand Down Expand Up @@ -301,7 +303,7 @@ class IntraProcessManager
std::shared_ptr<PublishedType> shared_msg = std::move(message);
if (!sub_ids.take_shared_subscriptions.empty()) {
this->template add_shared_msg_to_buffers<MessageT, PublishedType, ROSMessageType, Alloc,
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator>(
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator>(
shared_msg,
sub_ids.take_shared_subscriptions,
ros_message_type_allocator);
Expand All @@ -310,19 +312,21 @@ class IntraProcessManager
} else {
// Construct a new shared pointer from the message for the buffers that
// do not require ownership and to return.
auto shared_msg = std::allocate_shared<PublishedType, PublishedTypeAllocator>(published_type_allocator, *message);
auto shared_msg = std::allocate_shared<PublishedType, PublishedTypeAllocator>(
published_type_allocator,
*message);

if (!sub_ids.take_shared_subscriptions.empty()) {
this->template add_shared_msg_to_buffers<MessageT, PublishedType, ROSMessageType, Alloc,
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator>(
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator>(
shared_msg,
sub_ids.take_shared_subscriptions,
ros_message_type_allocator);
}

this->template add_owned_msg_to_buffers<MessageT, PublishedType, ROSMessageType, Alloc,
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator, ROSMessageTypeDeleter,
PublishedTypeAllocator>(
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator, ROSMessageTypeDeleter,
PublishedTypeAllocator>(
std::move(message),
sub_ids.take_ownership_subscriptions,
published_type_allocator,
Expand Down Expand Up @@ -359,7 +363,9 @@ class IntraProcessManager
{
auto ptr = ROSMessageTypeAllocatorTraits::allocate(ros_message_type_allocator, 1);
ROSMessageTypeAllocatorTraits::construct(ros_message_type_allocator, ptr);
auto unique_ros_msg = std::unique_ptr<ROSMessageType, ROSMessageTypeDeleter>(ptr, ros_message_type_deleter);
auto unique_ros_msg = std::unique_ptr<ROSMessageType, ROSMessageTypeDeleter>(
ptr,
ros_message_type_deleter);
rclcpp::TypeAdapter<MessageT>::convert_to_ros_message(*message, *unique_ros_msg);

std::shared_lock<std::shared_timed_mutex> lock(mutex_);
Expand All @@ -379,27 +385,29 @@ class IntraProcessManager
std::shared_ptr<PublishedType> shared_msg = std::move(message);
if (!sub_ids.take_shared_subscriptions.empty()) {
this->template add_shared_msg_to_buffers<MessageT, PublishedType, ROSMessageType, Alloc,
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator>(
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator>(
shared_msg,
sub_ids.take_shared_subscriptions,
ros_message_type_allocator);
}
} else {
// Construct a new shared pointer from the message for the buffers that
// do not require ownership and to return.
auto shared_msg = std::allocate_shared<PublishedType, PublishedTypeAllocator>(published_type_allocator, *message);
auto shared_msg = std::allocate_shared<PublishedType, PublishedTypeAllocator>(
published_type_allocator,
*message);

if (!sub_ids.take_shared_subscriptions.empty()) {
this->template add_shared_msg_to_buffers<MessageT, PublishedType, ROSMessageType, Alloc,
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator>(
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator>(
shared_msg,
sub_ids.take_shared_subscriptions,
ros_message_type_allocator);
}

this->template add_owned_msg_to_buffers<MessageT, PublishedType, ROSMessageType, Alloc,
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator, ROSMessageTypeDeleter,
PublishedTypeAllocator>(
Deleter, ROSMessageTypeAllocatorTraits, ROSMessageTypeAllocator, ROSMessageTypeDeleter,
PublishedTypeAllocator>(
std::move(message),
sub_ids.take_ownership_subscriptions,
published_type_allocator,
Expand Down Expand Up @@ -482,18 +490,17 @@ class IntraProcessManager
auto subscription_base = subscription_it->second.lock();
if (subscription_base) {
auto subscription = std::dynamic_pointer_cast<
rclcpp::experimental::SubscriptionIntraProcessBuffer<MessageT, PublishedType, Alloc, Deleter>
>(subscription_base);
rclcpp::experimental::SubscriptionIntraProcessBuffer<MessageT, PublishedType, Alloc,
Deleter>>(subscription_base);
if (nullptr == subscription) {

auto ros_message_subscription = std::dynamic_pointer_cast<
rclcpp::experimental::ROSMessageIntraProcessBuffer<ROSMessageType, Alloc, Deleter>
>(subscription_base);

if (nullptr == ros_message_subscription) {
throw std::runtime_error(
"failed to dynamic cast SubscriptionIntraProcessBase to "
"SubscriptionIntraProcessBuffer<MessageT, PublishedType, Alloc, Deleter>, which "
"SubscriptionIntraProcessBuffer, which "
"can happen when the publisher and subscription use different "
"allocator types, which is not supported");
} else {
Expand All @@ -506,13 +513,10 @@ class IntraProcessManager
} else {
ros_message_subscription->provide_intra_process_message(message);
}

}
} else {
subscription->provide_intra_process_data(message);
}


} else {
subscriptions_.erase(id);
}
Expand All @@ -538,7 +542,6 @@ class IntraProcessManager
ROSMessageTypeAllocator & ros_message_type_allocator,
ROSMessageTypeDeleter & ros_message_type_deleter)
{

std::cout << "add owned msg to buffers" << std::endl;

std::cout << "message has type : " << typeid(message).name() << std::endl;
Expand All @@ -554,15 +557,13 @@ class IntraProcessManager
auto subscription_base = subscription_it->second.lock();
std::cout << "Subscription Base?" << std::endl;
if (subscription_base) {

std::cout << "Typed Subscription" << std::endl;

auto subscription = std::dynamic_pointer_cast<
rclcpp::experimental::SubscriptionIntraProcessBuffer<MessageT, PublishedType, Alloc, Deleter>
>(subscription_base);
rclcpp::experimental::SubscriptionIntraProcessBuffer<MessageT, PublishedType, Alloc,
Deleter>>(subscription_base);
if (nullptr == subscription) {

std::cout << "ROSMessage Subscription" << std::endl;
std::cout << "ROSMessage Subscription" << std::endl;

auto ros_message_subscription = std::dynamic_pointer_cast<
rclcpp::experimental::ROSMessageIntraProcessBuffer<ROSMessageType, Alloc, Deleter>
Expand All @@ -571,17 +572,18 @@ class IntraProcessManager
if (nullptr == ros_message_subscription) {
throw std::runtime_error(
"failed to dynamic cast SubscriptionIntraProcessBase to "
"SubscriptionIntraProcessBuffer<MessageT, PublishedType, Alloc, Deleter>, which "
"SubscriptionIntraProcessBuffer, which "
"can happen when the publisher and subscription use different "
"allocator types, which is not supported");
} else {

std::cout << "ROSMessage TypeAdapted Subscription" << std::endl;

if constexpr (rclcpp::TypeAdapter<MessageT>::is_specialized::value) {
auto ptr = ROSMessageTypeAllocatorTraits::allocate(ros_message_type_allocator, 1);
ROSMessageTypeAllocatorTraits::construct(ros_message_type_allocator, ptr);
auto ros_msg = std::unique_ptr<ROSMessageType, ROSMessageTypeDeleter>(ptr, ros_message_type_deleter);
auto ros_msg = std::unique_ptr<ROSMessageType, ROSMessageTypeDeleter>(
ptr,
ros_message_type_deleter);
rclcpp::TypeAdapter<MessageT>::convert_to_ros_message(*message, *ros_msg);
ros_message_subscription->provide_intra_process_message(std::move(ros_msg));
} else {
Expand All @@ -600,7 +602,6 @@ class IntraProcessManager
ros_message_subscription->provide_intra_process_message(std::move(copy_message));
}
}

}
} else {
std::cout << "Typed Subscription" << std::endl;
Expand All @@ -618,7 +619,6 @@ class IntraProcessManager
subscription->provide_intra_process_data(std::move(copy_message));
}
}

} else {
std::cout << "Erasing subscription" << std::endl;
subscriptions_.erase(subscription_it);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class ROSMessageIntraProcessBuffer : public SubscriptionIntraProcessBase

virtual void
provide_intra_process_message(MessageUniquePtr message) = 0;

};

} // namespace experimental
Expand Down
18 changes: 10 additions & 8 deletions rclcpp/include/rclcpp/experimental/subscription_intra_process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ template<
typename SubscribedType,
typename SubscribedTypeAlloc = std::allocator<void>,
typename SubscribedTypeDeleter = std::default_delete<SubscribedType>
>
>
class SubscriptionIntraProcess
: public SubscriptionIntraProcessBuffer<
MessageT,
SubscribedType,
SubscribedTypeAlloc,
SubscribedTypeDeleter
>
MessageT,
SubscribedType,
SubscribedTypeAlloc,
SubscribedTypeDeleter
>
{
using SubscriptionIntraProcessBufferT = SubscriptionIntraProcessBuffer<
MessageT,
Expand All @@ -62,7 +62,8 @@ class SubscriptionIntraProcess
public:
RCLCPP_SMART_PTR_DEFINITIONS(SubscriptionIntraProcess)

using MessageAllocTraits = typename SubscriptionIntraProcessBufferT::SubscribedTypeAllocatorTraits;
using MessageAllocTraits =
typename SubscriptionIntraProcessBufferT::SubscribedTypeAllocatorTraits;
using MessageAlloc = typename SubscriptionIntraProcessBufferT::SubscribedTypeAllocator;
using ConstMessageSharedPtr = typename SubscriptionIntraProcessBufferT::ConstMessageSharedPtr;
using MessageUniquePtr = typename SubscriptionIntraProcessBufferT::MessageUniquePtr;
Expand All @@ -75,7 +76,8 @@ class SubscriptionIntraProcess
const std::string & topic_name,
const rclcpp::QoS & qos_profile,
rclcpp::IntraProcessBufferType buffer_type)
: SubscriptionIntraProcessBuffer<MessageT, SubscribedType, SubscribedTypeAlloc, SubscribedTypeDeleter>(
: SubscriptionIntraProcessBuffer<MessageT, SubscribedType, SubscribedTypeAlloc,
SubscribedTypeDeleter>(
allocator,
context,
topic_name,
Expand Down
Loading

0 comments on commit ce7ecfb

Please sign in to comment.