From 09dc78eafad234516a9edcebae94311e325f6e21 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Wed, 14 Oct 2015 13:53:18 -0700 Subject: [PATCH] add version of create_subscription which just takes queue size and not a qos profile --- rclcpp/include/rclcpp/node.hpp | 25 +++++++++++++++++++++++++ rclcpp/include/rclcpp/node_impl.hpp | 24 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/rclcpp/include/rclcpp/node.hpp b/rclcpp/include/rclcpp/node.hpp index 96b1663..50c1b6c 100644 --- a/rclcpp/include/rclcpp/node.hpp +++ b/rclcpp/include/rclcpp/node.hpp @@ -114,6 +114,31 @@ 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. diff --git a/rclcpp/include/rclcpp/node_impl.hpp b/rclcpp/include/rclcpp/node_impl.hpp index 09bbbc3..fabaa50 100644 --- a/rclcpp/include/rclcpp/node_impl.hpp +++ b/rclcpp/include/rclcpp/node_impl.hpp @@ -205,6 +205,30 @@ 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(