diff --git a/rclcpp/include/rclcpp/create_generic_publisher.hpp b/rclcpp/include/rclcpp/create_generic_publisher.hpp index 296446f7b9..9fac1cec7f 100644 --- a/rclcpp/include/rclcpp/create_generic_publisher.hpp +++ b/rclcpp/include/rclcpp/create_generic_publisher.hpp @@ -39,7 +39,8 @@ namespace rclcpp * \param qos %QoS settings * \param options %Publisher options. * Not all publisher options are currently respected, the only relevant options for this - * publisher are `event_callbacks`, `use_default_callbacks`, and `%callback_group`. + * publisher are `event_callbacks` and `use_default_callbacks`. + * \param group Callback group to execute this publisher's callback(e.g. QoS Events). */ template> std::shared_ptr create_generic_publisher( @@ -49,7 +50,8 @@ std::shared_ptr create_generic_publisher( const rclcpp::QoS & qos, const rclcpp::PublisherOptionsWithAllocator & options = ( rclcpp::PublisherOptionsWithAllocator() - ) + ), + rclcpp::CallbackGroup::SharedPtr group = nullptr ) { auto ts_lib = rclcpp::get_typesupport_library(topic_type, "rosidl_typesupport_cpp"); @@ -60,7 +62,24 @@ std::shared_ptr create_generic_publisher( topic_type, qos, options); - topics_interface->add_publisher(pub, options.callback_group); + +#ifndef _WIN32 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#else +# pragma warning(push) +# pragma warning(disable: 4996) +#endif + if (group == nullptr) { + group = options.callback_group; + } +#ifndef _WIN32 +# pragma GCC diagnostic pop +#else +# pragma warning(pop) +#endif + + topics_interface->add_publisher(pub, group); return pub; } diff --git a/rclcpp/include/rclcpp/create_publisher.hpp b/rclcpp/include/rclcpp/create_publisher.hpp index c633c74e2e..de5da6c5d2 100644 --- a/rclcpp/include/rclcpp/create_publisher.hpp +++ b/rclcpp/include/rclcpp/create_publisher.hpp @@ -50,7 +50,8 @@ create_publisher( const rclcpp::QoS & qos, const rclcpp::PublisherOptionsWithAllocator & options = ( rclcpp::PublisherOptionsWithAllocator() - ) + ), + rclcpp::CallbackGroup::SharedPtr group = nullptr ) { auto node_topics_interface = rclcpp::node_interfaces::get_node_topics_interface(node_topics); @@ -68,8 +69,23 @@ create_publisher( actual_qos ); +#ifndef _WIN32 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#else +# pragma warning(push) +# pragma warning(disable: 4996) +#endif + if (group == nullptr) { + group = options.callback_group; + } +#ifndef _WIN32 +# pragma GCC diagnostic pop +#else +# pragma warning(pop) +#endif // Add the publisher to the node topics interface. - node_topics_interface->add_publisher(pub, options.callback_group); + node_topics_interface->add_publisher(pub, group); return std::dynamic_pointer_cast(pub); } @@ -97,11 +113,12 @@ create_publisher( const rclcpp::QoS & qos, const rclcpp::PublisherOptionsWithAllocator & options = ( rclcpp::PublisherOptionsWithAllocator() - ) + ), + rclcpp::CallbackGroup::SharedPtr group = nullptr ) { return detail::create_publisher( - node, node, topic_name, qos, options); + node, node, topic_name, qos, options, group); } /// Create and return a publisher of the given MessageT type. @@ -117,11 +134,12 @@ create_publisher( const rclcpp::QoS & qos, const rclcpp::PublisherOptionsWithAllocator & options = ( rclcpp::PublisherOptionsWithAllocator() - ) + ), + rclcpp::CallbackGroup::SharedPtr group = nullptr ) { return detail::create_publisher( - node_parameters, node_topics, topic_name, qos, options); + node_parameters, node_topics, topic_name, qos, options, group); } } // namespace rclcpp diff --git a/rclcpp/include/rclcpp/generic_publisher.hpp b/rclcpp/include/rclcpp/generic_publisher.hpp index 7cadda5d1d..2fc63b4ff4 100644 --- a/rclcpp/include/rclcpp/generic_publisher.hpp +++ b/rclcpp/include/rclcpp/generic_publisher.hpp @@ -63,7 +63,7 @@ class GenericPublisher : public rclcpp::PublisherBase * \param callback Callback for new messages of serialized form * \param options %Publisher options. * Not all publisher options are currently respected, the only relevant options for this - * publisher are `event_callbacks`, `use_default_callbacks`, and `%callback_group`. + * publisher are `event_callbacks` and `use_default_callbacks`. */ template> GenericPublisher( diff --git a/rclcpp/include/rclcpp/node.hpp b/rclcpp/include/rclcpp/node.hpp index 7e5f402f8a..c9ec244976 100644 --- a/rclcpp/include/rclcpp/node.hpp +++ b/rclcpp/include/rclcpp/node.hpp @@ -185,6 +185,7 @@ class Node : public std::enable_shared_from_this * \param[in] topic_name The topic for this publisher to publish on. * \param[in] qos The Quality of Service settings for the publisher. * \param[in] options Additional options for the created Publisher. + * \param[in] group Callback group to execute this publisher's callback(e.g. QoS Events). * \return Shared pointer to the created publisher. */ template< @@ -196,7 +197,8 @@ class Node : public std::enable_shared_from_this const std::string & topic_name, const rclcpp::QoS & qos, const PublisherOptionsWithAllocator & options = - PublisherOptionsWithAllocator() + PublisherOptionsWithAllocator(), + rclcpp::CallbackGroup::SharedPtr group = nullptr ); /// Create and return a Subscription. @@ -278,9 +280,10 @@ class Node : public std::enable_shared_from_this * \param[in] topic_name Topic name * \param[in] topic_type Topic type * \param[in] qos %QoS settings - * \param options %Publisher options. + * \param[in] options %Publisher options. + * \param[in] group %Publisher group. * Not all publisher options are currently respected, the only relevant options for this - * publisher are `event_callbacks`, `use_default_callbacks`, and `%callback_group`. + * publisher are `event_callbacks` and `use_default_callbacks`. * \return Shared pointer to the created generic publisher. */ template> @@ -290,7 +293,8 @@ class Node : public std::enable_shared_from_this const rclcpp::QoS & qos, const rclcpp::PublisherOptionsWithAllocator & options = ( rclcpp::PublisherOptionsWithAllocator() - ) + ), + rclcpp::CallbackGroup::SharedPtr group = nullptr ); /// Create and return a GenericSubscription. diff --git a/rclcpp/include/rclcpp/node_impl.hpp b/rclcpp/include/rclcpp/node_impl.hpp index 46f54aa054..bfa99ab52e 100644 --- a/rclcpp/include/rclcpp/node_impl.hpp +++ b/rclcpp/include/rclcpp/node_impl.hpp @@ -73,13 +73,15 @@ std::shared_ptr Node::create_publisher( const std::string & topic_name, const rclcpp::QoS & qos, - const PublisherOptionsWithAllocator & options) + const PublisherOptionsWithAllocator & options, + rclcpp::CallbackGroup::SharedPtr group) { return rclcpp::create_publisher( *this, extend_name_with_sub_namespace(topic_name, this->get_sub_namespace()), qos, - options); + options, + group); } template< @@ -159,14 +161,16 @@ Node::create_generic_publisher( const std::string & topic_name, const std::string & topic_type, const rclcpp::QoS & qos, - const rclcpp::PublisherOptionsWithAllocator & options) + const rclcpp::PublisherOptionsWithAllocator & options, + rclcpp::CallbackGroup::SharedPtr group) { return rclcpp::create_generic_publisher( node_topics_, extend_name_with_sub_namespace(topic_name, this->get_sub_namespace()), topic_type, qos, - options + options, + group ); } diff --git a/rclcpp/include/rclcpp/publisher_options.hpp b/rclcpp/include/rclcpp/publisher_options.hpp index 48250307e9..95ec5dd6f6 100644 --- a/rclcpp/include/rclcpp/publisher_options.hpp +++ b/rclcpp/include/rclcpp/publisher_options.hpp @@ -34,6 +34,13 @@ namespace rclcpp class CallbackGroup; +#ifndef _WIN32 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#else +# pragma warning(push) +# pragma warning(disable: 4996) +#endif /// Non-templated part of PublisherOptionsWithAllocator. struct PublisherOptionsBase { @@ -52,6 +59,7 @@ struct PublisherOptionsBase RMW_UNIQUE_NETWORK_FLOW_ENDPOINTS_NOT_REQUIRED; /// Callback group in which the waitable items from the publisher should be placed. + [[deprecated("use create_publisher with a dedicated callback_group instead")]] std::shared_ptr callback_group; /// Optional RMW implementation specific payload to be used during creation of the publisher. @@ -60,6 +68,11 @@ struct PublisherOptionsBase QosOverridingOptions qos_overriding_options; }; +#ifndef _WIN32 +# pragma GCC diagnostic pop +#else +# pragma warning(pop) +#endif /// Structure containing optional configuration for Publishers. template diff --git a/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node.hpp b/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node.hpp index 4442304c0c..9e5c64f796 100644 --- a/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node.hpp +++ b/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node.hpp @@ -203,6 +203,7 @@ class LifecycleNode : public node_interfaces::LifecycleNodeInterface, * \param[in] topic_name The topic for this publisher to publish on. * \param[in] qos The Quality of Service settings for this publisher. * \param[in] options The publisher options for this publisher. + * \param[in] group Callback group to execute this publisher's callback(e.g. QoS Events). * \return Shared pointer to the created lifecycle publisher. */ template> @@ -212,7 +213,8 @@ class LifecycleNode : public node_interfaces::LifecycleNodeInterface, const rclcpp::QoS & qos, const PublisherOptionsWithAllocator & options = ( create_default_publisher_options() - ) + ), + rclcpp::CallbackGroup::SharedPtr group = nullptr ); /// Create and return a Subscription. @@ -289,7 +291,8 @@ class LifecycleNode : public node_interfaces::LifecycleNodeInterface, const rclcpp::QoS & qos, const rclcpp::PublisherOptionsWithAllocator & options = ( rclcpp::PublisherOptionsWithAllocator() - ) + ), + rclcpp::CallbackGroup::SharedPtr group = nullptr ); /// Create and return a GenericSubscription. diff --git a/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node_impl.hpp b/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node_impl.hpp index a7f1c686bc..1ce7c1e7fd 100644 --- a/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node_impl.hpp +++ b/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node_impl.hpp @@ -46,14 +46,16 @@ std::shared_ptr> LifecycleNode::create_publisher( const std::string & topic_name, const rclcpp::QoS & qos, - const rclcpp::PublisherOptionsWithAllocator & options) + const rclcpp::PublisherOptionsWithAllocator & options, + rclcpp::CallbackGroup::SharedPtr group) { using PublisherT = rclcpp_lifecycle::LifecyclePublisher; return rclcpp::create_publisher( *this, topic_name, qos, - options); + options, + group); } // TODO(karsten1987): Create LifecycleSubscriber @@ -137,7 +139,8 @@ LifecycleNode::create_generic_publisher( const std::string & topic_name, const std::string & topic_type, const rclcpp::QoS & qos, - const rclcpp::PublisherOptionsWithAllocator & options) + const rclcpp::PublisherOptionsWithAllocator & options, + rclcpp::CallbackGroup::SharedPtr group) { return rclcpp::create_generic_publisher( node_topics_, @@ -146,7 +149,8 @@ LifecycleNode::create_generic_publisher( topic_name, topic_type, qos, - options + options, + group ); }