comply to new subscription template (#500)

This commit is contained in:
Karsten Knese 2018-06-19 00:20:55 +02:00 committed by GitHub
parent bfbb263f3c
commit d33a46c3b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 6 deletions

View file

@ -188,7 +188,8 @@ public:
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_default, const rmw_qos_profile_t & qos_profile = rmw_qos_profile_default,
rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr, rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr,
bool ignore_local_publications = false, bool ignore_local_publications = false,
typename rclcpp::message_memory_strategy::MessageMemoryStrategy<MessageT, Alloc>::SharedPtr typename rclcpp::message_memory_strategy::MessageMemoryStrategy<
typename rclcpp::subscription_traits::has_message_type<CallbackT>::type, Alloc>::SharedPtr
msg_mem_strat = nullptr, msg_mem_strat = nullptr,
std::shared_ptr<Alloc> allocator = nullptr); std::shared_ptr<Alloc> allocator = nullptr);

View file

@ -76,22 +76,23 @@ LifecycleNode::create_subscription(
const rmw_qos_profile_t & qos_profile, const rmw_qos_profile_t & qos_profile,
rclcpp::callback_group::CallbackGroup::SharedPtr group, rclcpp::callback_group::CallbackGroup::SharedPtr group,
bool ignore_local_publications, bool ignore_local_publications,
typename rclcpp::message_memory_strategy::MessageMemoryStrategy<MessageT, Alloc>::SharedPtr typename rclcpp::message_memory_strategy::MessageMemoryStrategy<
typename rclcpp::subscription_traits::has_message_type<CallbackT>::type, Alloc>::SharedPtr
msg_mem_strat, msg_mem_strat,
std::shared_ptr<Alloc> allocator) std::shared_ptr<Alloc> allocator)
{ {
using CallbackMessageT = typename rclcpp::subscription_traits::has_message_type<CallbackT>::type;
if (!allocator) { if (!allocator) {
allocator = std::make_shared<Alloc>(); allocator = std::make_shared<Alloc>();
} }
if (!msg_mem_strat) { if (!msg_mem_strat) {
using rclcpp::message_memory_strategy::MessageMemoryStrategy; using rclcpp::message_memory_strategy::MessageMemoryStrategy;
msg_mem_strat = MessageMemoryStrategy<MessageT, Alloc>::create_default(); msg_mem_strat = MessageMemoryStrategy<CallbackMessageT, Alloc>::create_default();
} }
return rclcpp::create_subscription< return rclcpp::create_subscription<MessageT, CallbackT, Alloc, CallbackMessageT, SubscriptionT>(
MessageT, CallbackT, Alloc,
rclcpp::Subscription<MessageT, Alloc>>(
this->node_topics_.get(), this->node_topics_.get(),
topic_name, topic_name,
std::forward<CallbackT>(callback), std::forward<CallbackT>(callback),

View file

@ -203,3 +203,12 @@ TEST_F(TestDefaultStateMachine, bad_mood) {
// check if all callbacks were successfully overwritten // check if all callbacks were successfully overwritten
EXPECT_EQ(static_cast<size_t>(1), test_node->number_of_callbacks); EXPECT_EQ(static_cast<size_t>(1), test_node->number_of_callbacks);
} }
TEST_F(TestDefaultStateMachine, lifecycle_subscriber) {
auto test_node = std::make_shared<MoodyLifecycleNode<GoodMood>>("testnode");
auto cb = [](const std::shared_ptr<lifecycle_msgs::msg::State> msg) {(void) msg;};
auto lifecycle_sub = test_node->create_subscription<lifecycle_msgs::msg::State>("~/empty", cb);
SUCCEED();
}