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..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,12 +139,26 @@ public: typename rclcpp::message_memory_strategy::MessageMemoryStrategy::SharedPtr msg_mem_strat = nullptr); - template + /// 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_with_unique_ptr_callback( + create_subscription( const std::string & topic_name, - const rmw_qos_profile_t & qos_profile, - typename rclcpp::subscription::AnySubscriptionCallback::UniquePtrCallback callback, + 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 @@ -273,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 fabaa50..f854ada 100644 --- a/rclcpp/include/rclcpp/node_impl.hpp +++ b/rclcpp/include/rclcpp/node_impl.hpp @@ -205,30 +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) -{ - 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( - topic_name, - qos, - any_subscription_callback, - group, - ignore_local_publications, - msg_mem_strat); -} - template typename rclcpp::subscription::Subscription::SharedPtr Node::create_subscription( @@ -242,47 +218,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 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( - 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) { @@ -308,7 +244,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. @@ -370,6 +306,28 @@ Node::create_subscription_internal( 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,