From b0a2b7610d5b5a2955058774bfd8d36787634e7e Mon Sep 17 00:00:00 2001 From: Esteve Fernandez Date: Wed, 14 Oct 2015 15:12:57 -0700 Subject: [PATCH 1/3] Replaced create_subscription_with_unique_ptr_callback with create_subscription --- .../rclcpp/any_subscription_callback.hpp | 30 +++++++------------ rclcpp/include/rclcpp/node.hpp | 11 ------- rclcpp/include/rclcpp/node_impl.hpp | 22 -------------- 3 files changed, 11 insertions(+), 52 deletions(-) diff --git a/rclcpp/include/rclcpp/any_subscription_callback.hpp b/rclcpp/include/rclcpp/any_subscription_callback.hpp index ba4c51c..7f8ed15 100644 --- a/rclcpp/include/rclcpp/any_subscription_callback.hpp +++ b/rclcpp/include/rclcpp/any_subscription_callback.hpp @@ -114,35 +114,28 @@ struct AnySubscriptionCallback { const_shared_ptr_with_info_callback = callback; } -/* - template::arity == 1 - >::type * = nullptr, - typename std::enable_if< - std::is_same< - typename function_traits::template argument_type<0>, + rclcpp::check_argument_types< + CallbackT, typename std::unique_ptr >::value >::type * = nullptr > void set(CallbackT callback) { - static_assert(std::is_same< - typename function_traits::template argument_type<0>, - typename std::unique_ptr - >::value, "Not a unique pointer"); unique_ptr_callback = callback; } - template::arity == 2 - >::type * = nullptr, - typename std::enable_if< - std::is_same< - typename function_traits::template argument_type<0>, - typename std::unique_ptr + rclcpp::check_argument_types< + CallbackT, + typename std::unique_ptr, + const rmw_message_info_t & >::value >::type * = nullptr > @@ -150,7 +143,6 @@ struct AnySubscriptionCallback { unique_ptr_with_info_callback = callback; } - */ }; } /* namespace any_subscription_callback */ diff --git a/rclcpp/include/rclcpp/node.hpp b/rclcpp/include/rclcpp/node.hpp index 816d263..5c65b63 100644 --- a/rclcpp/include/rclcpp/node.hpp +++ b/rclcpp/include/rclcpp/node.hpp @@ -164,17 +164,6 @@ public: typename rclcpp::message_memory_strategy::MessageMemoryStrategy::SharedPtr msg_mem_strat = nullptr); - template - typename rclcpp::subscription::Subscription::SharedPtr - create_subscription_with_unique_ptr_callback( - const std::string & topic_name, - const rmw_qos_profile_t & qos_profile, - typename rclcpp::subscription::AnySubscriptionCallback::UniquePtrCallback callback, - rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr, - bool ignore_local_publications = false, - typename rclcpp::message_memory_strategy::MessageMemoryStrategy::SharedPtr - msg_mem_strat = nullptr); - /// Create a timer. /** * \param[in] period Time interval between triggers of the callback. diff --git a/rclcpp/include/rclcpp/node_impl.hpp b/rclcpp/include/rclcpp/node_impl.hpp index fabaa50..1c0a94a 100644 --- a/rclcpp/include/rclcpp/node_impl.hpp +++ b/rclcpp/include/rclcpp/node_impl.hpp @@ -251,28 +251,6 @@ Node::create_subscription( msg_mem_strat); } -template -typename rclcpp::subscription::Subscription::SharedPtr -Node::create_subscription_with_unique_ptr_callback( - const std::string & topic_name, - const rmw_qos_profile_t & qos_profile, - typename rclcpp::subscription::AnySubscriptionCallback::UniquePtrCallback callback, - rclcpp::callback_group::CallbackGroup::SharedPtr group, - bool ignore_local_publications, - typename rclcpp::message_memory_strategy::MessageMemoryStrategy::SharedPtr - msg_mem_strat) -{ - rclcpp::subscription::AnySubscriptionCallback any_subscription_callback; - any_subscription_callback.unique_ptr_callback = callback; - return this->create_subscription_internal( - topic_name, - qos_profile, - any_subscription_callback, - group, - ignore_local_publications, - msg_mem_strat); -} - template typename subscription::Subscription::SharedPtr Node::create_subscription_internal( From 07746c6834756f7795f315e64fdabd89636a9971 Mon Sep 17 00:00:00 2001 From: Esteve Fernandez Date: Wed, 14 Oct 2015 16:10:49 -0700 Subject: [PATCH 2/3] Removed create_subscription_internal --- rclcpp/include/rclcpp/node.hpp | 60 ++++++++++++----------------- rclcpp/include/rclcpp/node_impl.hpp | 26 ++----------- 2 files changed, 28 insertions(+), 58 deletions(-) diff --git a/rclcpp/include/rclcpp/node.hpp b/rclcpp/include/rclcpp/node.hpp index 5c65b63..9c57c8c 100644 --- a/rclcpp/include/rclcpp/node.hpp +++ b/rclcpp/include/rclcpp/node.hpp @@ -114,31 +114,6 @@ public: create_publisher( const std::string & topic_name, const rmw_qos_profile_t & qos_profile); - /// Create and return a Subscription. - /** - * \param[in] topic_name The topic to subscribe on. - * \param[in] qos_history_depth The depth of the subscription's incoming message queue. - * \param[in] callback The user-defined callback function. - * \param[in] group The callback group for this subscription. NULL for no callback group. - * \param[in] ignore_local_publications True to ignore local publications. - * \param[in] msg_mem_strat The message memory strategy to use for allocating messages. - * \return Shared pointer to the created subscription. - */ - /* TODO(jacquelinekay): - Windows build breaks when static member function passed as default - argument to msg_mem_strat, nullptr is a workaround. - */ - template - typename rclcpp::subscription::Subscription::SharedPtr - create_subscription( - const std::string & topic_name, - size_t qos_history_depth, - CallbackT callback, - rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr, - bool ignore_local_publications = false, - typename rclcpp::message_memory_strategy::MessageMemoryStrategy::SharedPtr - msg_mem_strat = nullptr); - /// Create and return a Subscription. /** * \param[in] topic_name The topic to subscribe on. @@ -164,6 +139,31 @@ public: typename rclcpp::message_memory_strategy::MessageMemoryStrategy::SharedPtr msg_mem_strat = nullptr); + /// Create and return a Subscription. + /** + * \param[in] topic_name The topic to subscribe on. + * \param[in] qos_history_depth The depth of the subscription's incoming message queue. + * \param[in] callback The user-defined callback function. + * \param[in] group The callback group for this subscription. NULL for no callback group. + * \param[in] ignore_local_publications True to ignore local publications. + * \param[in] msg_mem_strat The message memory strategy to use for allocating messages. + * \return Shared pointer to the created subscription. + */ + /* TODO(jacquelinekay): + Windows build breaks when static member function passed as default + argument to msg_mem_strat, nullptr is a workaround. + */ + template + typename rclcpp::subscription::Subscription::SharedPtr + create_subscription( + const std::string & topic_name, + size_t qos_history_depth, + CallbackT callback, + rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr, + bool ignore_local_publications = false, + typename rclcpp::message_memory_strategy::MessageMemoryStrategy::SharedPtr + msg_mem_strat = nullptr); + /// Create a timer. /** * \param[in] period Time interval between triggers of the callback. @@ -262,16 +262,6 @@ private: publisher::Publisher::SharedPtr events_publisher_; - template - typename subscription::Subscription::SharedPtr - create_subscription_internal( - const std::string & topic_name, - const rmw_qos_profile_t & qos_profile, - rclcpp::subscription::AnySubscriptionCallback callback, - rclcpp::callback_group::CallbackGroup::SharedPtr group, - bool ignore_local_publications, - typename message_memory_strategy::MessageMemoryStrategy::SharedPtr msg_mem_strat); - template< typename ServiceT, typename FunctorT, diff --git a/rclcpp/include/rclcpp/node_impl.hpp b/rclcpp/include/rclcpp/node_impl.hpp index 1c0a94a..5f92369 100644 --- a/rclcpp/include/rclcpp/node_impl.hpp +++ b/rclcpp/include/rclcpp/node_impl.hpp @@ -216,14 +216,12 @@ Node::create_subscription( typename rclcpp::message_memory_strategy::MessageMemoryStrategy::SharedPtr msg_mem_strat) { - rclcpp::subscription::AnySubscriptionCallback any_subscription_callback; - any_subscription_callback.set(callback); rmw_qos_profile_t qos = rmw_qos_profile_default; qos.depth = qos_history_depth; - return this->create_subscription_internal( + return this->create_subscription( topic_name, qos, - any_subscription_callback, + callback, group, ignore_local_publications, msg_mem_strat); @@ -242,25 +240,7 @@ Node::create_subscription( { rclcpp::subscription::AnySubscriptionCallback any_subscription_callback; any_subscription_callback.set(callback); - return this->create_subscription_internal( - topic_name, - qos_profile, - any_subscription_callback, - group, - ignore_local_publications, - msg_mem_strat); -} -template -typename subscription::Subscription::SharedPtr -Node::create_subscription_internal( - const std::string & topic_name, - const rmw_qos_profile_t & qos_profile, - rclcpp::subscription::AnySubscriptionCallback callback, - rclcpp::callback_group::CallbackGroup::SharedPtr group, - bool ignore_local_publications, - typename message_memory_strategy::MessageMemoryStrategy::SharedPtr msg_mem_strat) -{ using rosidl_generator_cpp::get_message_type_support_handle; if (!msg_mem_strat) { @@ -286,7 +266,7 @@ Node::create_subscription_internal( subscriber_handle, topic_name, ignore_local_publications, - callback, + any_subscription_callback, msg_mem_strat); auto sub_base_ptr = std::dynamic_pointer_cast(sub); // Setup intra process. From 3061ec0ad58678359c2c241410f7a5d9fc24c65b Mon Sep 17 00:00:00 2001 From: Esteve Fernandez Date: Thu, 15 Oct 2015 11:37:28 -0700 Subject: [PATCH 3/3] Qualify template --- rclcpp/include/rclcpp/node_impl.hpp | 44 ++++++++++++++--------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/rclcpp/include/rclcpp/node_impl.hpp b/rclcpp/include/rclcpp/node_impl.hpp index 5f92369..f854ada 100644 --- a/rclcpp/include/rclcpp/node_impl.hpp +++ b/rclcpp/include/rclcpp/node_impl.hpp @@ -205,28 +205,6 @@ Node::group_in_node(callback_group::CallbackGroup::SharedPtr group) return group_belongs_to_this_node; } -template -typename rclcpp::subscription::Subscription::SharedPtr -Node::create_subscription( - const std::string & topic_name, - size_t qos_history_depth, - CallbackT callback, - rclcpp::callback_group::CallbackGroup::SharedPtr group, - bool ignore_local_publications, - typename rclcpp::message_memory_strategy::MessageMemoryStrategy::SharedPtr - msg_mem_strat) -{ - rmw_qos_profile_t qos = rmw_qos_profile_default; - qos.depth = qos_history_depth; - return this->create_subscription( - topic_name, - qos, - callback, - group, - ignore_local_publications, - msg_mem_strat); -} - template typename rclcpp::subscription::Subscription::SharedPtr Node::create_subscription( @@ -328,6 +306,28 @@ Node::create_subscription( return sub; } +template +typename rclcpp::subscription::Subscription::SharedPtr +Node::create_subscription( + const std::string & topic_name, + size_t qos_history_depth, + CallbackT callback, + rclcpp::callback_group::CallbackGroup::SharedPtr group, + bool ignore_local_publications, + typename rclcpp::message_memory_strategy::MessageMemoryStrategy::SharedPtr + msg_mem_strat) +{ + rmw_qos_profile_t qos = rmw_qos_profile_default; + qos.depth = qos_history_depth; + return this->create_subscription( + topic_name, + qos, + callback, + group, + ignore_local_publications, + msg_mem_strat); +} + rclcpp::timer::WallTimer::SharedPtr Node::create_wall_timer( std::chrono::nanoseconds period,