Skip to content
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/generic subscriber and publisher #1077

Open
wants to merge 25 commits into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9d88f0e
* updated interface to SubscriptionIntraProcessBase
Apr 21, 2020
1dad3ad
added support for SerializedMessage in Intraprocessmanger, so:
Apr 21, 2020
c552c0b
updated unit test for intraprocess manager to match new interface
Apr 21, 2020
2513cc2
updated is_serialized_message_class traits
Apr 22, 2020
fd6a20e
renamed provide_serialized_intra_process_message to provide_intra_pro…
Apr 22, 2020
f0c8dd3
fixed Serialization class for non-supported type (yes this is actuall…
Apr 22, 2020
facb43d
updated to (de)seriaizle method
Apr 22, 2020
08a3251
fix build regression (#1078)
dirk-thomas Apr 21, 2020
0577f39
Reflect changes in rclcpp API (#1079)
Apr 21, 2020
9ae2da1
extended publisher:
Apr 21, 2020
9490d9f
added create_generic_subscription and create_generic_publisher
Apr 21, 2020
3b430bf
added test for intra process communication with generic publishers an…
Apr 21, 2020
88a6927
fixed date
Apr 21, 2020
63ad2fe
fixed unintended change
Apr 22, 2020
86f8ef9
replaced generic_publisher
Apr 22, 2020
62635ab
removed unneeded template typename
Apr 22, 2020
d676d12
renamed create_generic_... to create_
Apr 22, 2020
aeb69bf
updated to new SerializedMessage
Apr 22, 2020
8d2de84
* added get_type_support_handle to rclcpp::Serialization
Apr 29, 2020
e2c19bb
extended subscription_intra_process(_base):
Apr 29, 2020
370061b
update unit test for subscription_intra_process(_base)
Apr 29, 2020
50334ba
extended intra_process_manager for serialized messages:
Apr 29, 2020
2e5a7bd
simplified code
Apr 29, 2020
6b3d9c7
fixed modifier
Apr 29, 2020
f5c3362
updated comments
Apr 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions rclcpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,18 @@ if(BUILD_TESTING)
"test_msgs"
)
target_link_libraries(test_loaned_message ${PROJECT_NAME})
ament_add_gtest(test_intra_process_communication test/test_intra_process_communication.cpp
TIMEOUT 120)
if(TARGET test_intra_process_communication)
ament_target_dependencies(test_intra_process_communication
"rcl"
"rcl_interfaces"
"rmw"
"rosidl_typesupport_cpp"
"test_msgs"
)
endif()
target_link_libraries(test_intra_process_communication ${PROJECT_NAME})

ament_add_gtest(test_node test/test_node.cpp TIMEOUT 240)
if(TARGET test_node)
Expand Down
40 changes: 40 additions & 0 deletions rclcpp/include/rclcpp/create_publisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,46 @@
namespace rclcpp
{

/// Create and return a publisher of the given MessageT type.
/**
* The NodeT type only needs to have a method called get_node_topics_interface()
* which returns a shared_ptr to a NodeTopicsInterface.
*/
template<
typename MessageT = SerializedMessage,
typename AllocatorT = std::allocator<void>,
typename PublisherT = rclcpp::Publisher<MessageT, AllocatorT>,
typename NodeT>
std::shared_ptr<PublisherT>
create_publisher(
NodeT & node,
const std::string & topic_name,
const rosidl_message_type_support_t & type_support,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why both MessageT template parameter and the type_support argument are needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming should also be more clear.
Maybe, just an override of create_publisher?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think MessageT is used for the allocator

const rclcpp::QoS & qos,
const rclcpp::PublisherOptionsWithAllocator<AllocatorT> & options = (
rclcpp::PublisherOptionsWithAllocator<AllocatorT>()
)
)
{
// Extract the NodeTopicsInterface from the NodeT.
using rclcpp::node_interfaces::get_node_topics_interface;
auto node_topics = get_node_topics_interface(node);

// Create the publisher.
auto pub = node_topics->create_publisher(
topic_name,
rclcpp::create_publisher_factory<AllocatorT, PublisherT>(
options,
type_support),
qos
);

// Add the publisher to the node topics interface.
node_topics->add_publisher(pub, options.callback_group);

return std::dynamic_pointer_cast<PublisherT>(pub);
}

/// Create and return a publisher of the given MessageT type.
/**
* The NodeT type only needs to have a method called get_node_topics_interface()
Expand Down
46 changes: 46 additions & 0 deletions rclcpp/include/rclcpp/create_subscription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,52 @@
namespace rclcpp
{

/// Create and return a subscription of the given MessageT type.
/**
* The NodeT type only needs to have a method called get_node_topics_interface()
* which returns a shared_ptr to a NodeTopicsInterface, or be a
* NodeTopicsInterface pointer itself.
*/
template<
typename CallbackT,
typename AllocatorT = std::allocator<void>,
typename CallbackMessageT =
typename rclcpp::subscription_traits::has_message_type<CallbackT>::type,
typename SubscriptionT = rclcpp::Subscription<CallbackMessageT, AllocatorT>,
typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy<
CallbackMessageT,
AllocatorT
>,
typename NodeT>
typename std::shared_ptr<SubscriptionT>
create_subscription(
NodeT && node,
const std::string & topic_name,
const rosidl_message_type_support_t & type_support,
const rclcpp::QoS & qos,
CallbackT && callback,
const rclcpp::SubscriptionOptionsWithAllocator<AllocatorT> & options =
rclcpp::SubscriptionOptionsWithAllocator<AllocatorT>(),
typename MessageMemoryStrategyT::SharedPtr msg_mem_strat =
MessageMemoryStrategyT::create_default()
)
{
using rclcpp::node_interfaces::get_node_topics_interface;
auto node_topics = get_node_topics_interface(std::forward<NodeT>(node));

auto factory = rclcpp::create_subscription_factory(
std::forward<CallbackT>(callback),
options,
msg_mem_strat,
type_support
);

auto sub = node_topics->create_subscription(topic_name, factory, qos);
node_topics->add_subscription(sub, options.callback_group);

return std::dynamic_pointer_cast<SubscriptionT>(sub);
}

/// Create and return a subscription of the given MessageT type.
/**
* The NodeT type only needs to have a method called get_node_topics_interface()
Expand Down
Loading