-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New interfaces for incoming QoS features #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
|
||
#include "rclcpp/client.hpp" | ||
#include "rclcpp/service.hpp" | ||
#include "rclcpp/publisher.hpp" | ||
#include "rclcpp/subscription.hpp" | ||
#include "rclcpp/timer.hpp" | ||
#include "rclcpp/visibility_control.hpp" | ||
|
@@ -61,6 +62,10 @@ class CallbackGroup | |
RCLCPP_PUBLIC | ||
explicit CallbackGroup(CallbackGroupType group_type); | ||
|
||
RCLCPP_PUBLIC | ||
const std::vector<rclcpp::PublisherBase::WeakPtr> & | ||
get_publisher_ptrs() const; | ||
|
||
RCLCPP_PUBLIC | ||
const std::vector<rclcpp::SubscriptionBase::WeakPtr> & | ||
get_subscription_ptrs() const; | ||
|
@@ -92,6 +97,10 @@ class CallbackGroup | |
protected: | ||
RCLCPP_DISABLE_COPY(CallbackGroup) | ||
|
||
RCLCPP_PUBLIC | ||
void | ||
add_publisher(const rclcpp::PublisherBase::SharedPtr publisher_ptr); | ||
|
||
RCLCPP_PUBLIC | ||
void | ||
add_subscription(const rclcpp::SubscriptionBase::SharedPtr subscription_ptr); | ||
|
@@ -119,6 +128,7 @@ class CallbackGroup | |
CallbackGroupType type_; | ||
// Mutex to protect the subsequent vectors of pointers. | ||
mutable std::mutex mutex_; | ||
std::vector<rclcpp::PublisherBase::WeakPtr> publisher_ptrs_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (minor) We should either add TSA here or add a TODO referencing a ticket to get this in our backlog. |
||
std::vector<rclcpp::SubscriptionBase::WeakPtr> subscription_ptrs_; | ||
std::vector<rclcpp::TimerBase::WeakPtr> timer_ptrs_; | ||
std::vector<rclcpp::ServiceBase::WeakPtr> service_ptrs_; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,7 +139,7 @@ class Node : public std::enable_shared_from_this<Node> | |
const std::vector<rclcpp::callback_group::CallbackGroup::WeakPtr> & | ||
get_callback_groups() const; | ||
|
||
/// Create and return a Publisher. | ||
/// Create and return a Publisher. Note: This constructor is deprecated | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We target C++14 so we can use https://en.cppreference.com/w/cpp/language/attributes/deprecated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this cause a warning from the compiler if the deprecated function is used? If so it would cause the builds to be unstable until we got all the usages switched over. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is my primary concern with that as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point (yes - it'll emit a warning). Wondering if something like that could be a solution: // TODO(ros2/rmw#1234): replace the following line by
// # define RMW_DEPRECATED(x) [[deprecated(x)]]
// on 2019-XX-YY.
# define RMW_NODE_CTOR_DEPRECATED(x) and switch later to: // TODO(ros2/rmw#56768): remove all code annotated with this on 20XX-YY-ZZ.
# define RMW_NODE_CTOR_DEPRECATED(x) [[deprecated(x)]] |
||
/** | ||
* \param[in] topic_name The topic for this publisher to publish on. | ||
* \param[in] qos_history_depth The depth of the publisher message queue. | ||
|
@@ -151,10 +151,11 @@ class Node : public std::enable_shared_from_this<Node> | |
typename PublisherT = ::rclcpp::Publisher<MessageT, Alloc>> | ||
std::shared_ptr<PublisherT> | ||
create_publisher( | ||
const std::string & topic_name, size_t qos_history_depth, | ||
const std::string & topic_name, | ||
size_t qos_history_depth, | ||
thomas-moulard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
std::shared_ptr<Alloc> allocator = nullptr); | ||
|
||
/// Create and return a Publisher. | ||
/// Create and return a Publisher. Note: this constructor is deprecated | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto here |
||
/** | ||
* \param[in] topic_name The topic for this publisher to publish on. | ||
* \param[in] qos_profile The quality of service profile to pass on to the rmw implementation. | ||
|
@@ -170,7 +171,23 @@ class Node : public std::enable_shared_from_this<Node> | |
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_default, | ||
std::shared_ptr<Alloc> allocator = nullptr); | ||
|
||
/// Create and return a Subscription. | ||
/// Create and return a Publisher. | ||
/** | ||
* \param[in] topic_name The topic for this publisher to publish on. | ||
* \param[in] options Additional options for the created Publisher | ||
* \return Shared pointer to the created publisher. | ||
*/ | ||
template< | ||
typename MessageT, | ||
typename Alloc = std::allocator<void>, | ||
typename PublisherT = ::rclcpp::Publisher<MessageT, Alloc>> | ||
std::shared_ptr<PublisherT> | ||
create_publisher( | ||
const std::string & topic_name, | ||
const PublisherOptions<Alloc> & options, | ||
rclcpp::callback_group::CallbackGroup::SharedPtr callback_group = nullptr); | ||
|
||
/// Create and return a Subscription. Note: this constructor is deprecated | ||
/** | ||
* \param[in] topic_name The topic to subscribe on. | ||
* \param[in] callback The user-defined callback function. | ||
|
@@ -203,7 +220,7 @@ class Node : public std::enable_shared_from_this<Node> | |
msg_mem_strat = nullptr, | ||
std::shared_ptr<Alloc> allocator = nullptr); | ||
|
||
/// Create and return a Subscription. | ||
/// Create and return a Subscription. Note: this constructor is deprecated | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
/** | ||
* \param[in] topic_name The topic to subscribe on. | ||
* \param[in] qos_history_depth The depth of the subscription's incoming message queue. | ||
|
@@ -236,6 +253,34 @@ class Node : public std::enable_shared_from_this<Node> | |
msg_mem_strat = nullptr, | ||
std::shared_ptr<Alloc> allocator = nullptr); | ||
|
||
/// Create and return a Subscription. | ||
/** | ||
* \param[in] topic_name The topic to subscribe on. | ||
* \param[in] callback The user-defined callback function to receive a message | ||
* \param[in] options Additional options for the creation of the Subscription | ||
* \param[in] msg_mem_strat The message memory strategy to use for allocating messages. | ||
* \return Shared pointer to the created subscription. | ||
*/ | ||
/* TODO(jacquelinekay): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is copied and paste from somewhere, but it's better to reference tickets than people there if we want to actually fix those items at some point. It's up to you but I'd open a bug and change this into: |
||
Windows build breaks when static member function passed as default | ||
argument to msg_mem_strat, nullptr is a workaround. | ||
*/ | ||
template< | ||
typename MessageT, | ||
typename CallbackT, | ||
typename Alloc = std::allocator<void>, | ||
typename SubscriptionT = rclcpp::Subscription< | ||
typename rclcpp::subscription_traits::has_message_type<CallbackT>::type, Alloc>> | ||
std::shared_ptr<SubscriptionT> | ||
create_subscription( | ||
const std::string & topic_name, | ||
CallbackT && callback, | ||
const SubscriptionOptions<Alloc> & options, | ||
rclcpp::callback_group::CallbackGroup::SharedPtr callback_group = nullptr, | ||
typename rclcpp::message_memory_strategy::MessageMemoryStrategy< | ||
typename rclcpp::subscription_traits::has_message_type<CallbackT>::type, Alloc>::SharedPtr | ||
msg_mem_strat = nullptr); | ||
|
||
/// Create a timer. | ||
/** | ||
* \param[in] period Time interval between triggers of the callback. | ||
|
@@ -600,6 +645,16 @@ class Node : public std::enable_shared_from_this<Node> | |
const NodeOptions & | ||
get_node_options() const; | ||
|
||
/// Manually assert that this Node is alive (for RMW_QOS_POLICY_MANUAL_BY_NODE) | ||
/** | ||
* If the rmw Liveliness policy is set to RMW_QOS_POLICY_MANUAL_BY_NODE, the creator of this | ||
* Node must manually call `assert_liveliness` periodically to signal that this Node | ||
* is still alive. Must be called at least as often as qos_profile's Liveliness lease_duration | ||
*/ | ||
RCLCPP_PUBLIC | ||
void | ||
assert_liveliness() {} | ||
|
||
protected: | ||
/// Construct a sub-node, which will extend the namespace of all entities created with it. | ||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,8 @@ namespace rclcpp | |
template<typename MessageT, typename Alloc, typename PublisherT> | ||
std::shared_ptr<PublisherT> | ||
Node::create_publisher( | ||
const std::string & topic_name, size_t qos_history_depth, | ||
const std::string & topic_name, | ||
size_t qos_history_depth, | ||
thomas-moulard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
std::shared_ptr<Alloc> allocator) | ||
{ | ||
if (!allocator) { | ||
|
@@ -80,7 +81,8 @@ extend_name_with_sub_namespace(const std::string & name, const std::string & sub | |
template<typename MessageT, typename Alloc, typename PublisherT> | ||
std::shared_ptr<PublisherT> | ||
Node::create_publisher( | ||
const std::string & topic_name, const rmw_qos_profile_t & qos_profile, | ||
const std::string & topic_name, | ||
const rmw_qos_profile_t & qos_profile, | ||
std::shared_ptr<Alloc> allocator) | ||
{ | ||
if (!allocator) { | ||
|
@@ -91,6 +93,30 @@ Node::create_publisher( | |
this->node_topics_.get(), | ||
extend_name_with_sub_namespace(topic_name, this->get_sub_namespace()), | ||
qos_profile, | ||
PublisherEventCallbacks(), | ||
nullptr, | ||
this->get_node_options().use_intra_process_comms(), | ||
allocator); | ||
} | ||
|
||
template<typename MessageT, typename Alloc, typename PublisherT> | ||
std::shared_ptr<PublisherT> | ||
Node::create_publisher( | ||
const std::string & topic_name, | ||
const PublisherOptions<Alloc> & options, | ||
rclcpp::callback_group::CallbackGroup::SharedPtr group) | ||
{ | ||
std::shared_ptr<Alloc> allocator = options.allocator(); | ||
if (!allocator) { | ||
allocator = std::make_shared<Alloc>(); | ||
} | ||
|
||
return rclcpp::create_publisher<MessageT, Alloc, PublisherT>( | ||
this->node_topics_.get(), | ||
extend_name_with_sub_namespace(topic_name, this->get_sub_namespace()), | ||
options.qos_profile(), | ||
options.event_callbacks(), | ||
group, | ||
this->get_node_options().use_intra_process_comms(), | ||
allocator); | ||
} | ||
|
@@ -128,13 +154,54 @@ Node::create_subscription( | |
extend_name_with_sub_namespace(topic_name, this->get_sub_namespace()), | ||
std::forward<CallbackT>(callback), | ||
qos_profile, | ||
SubscriptionEventCallbacks(), | ||
group, | ||
ignore_local_publications, | ||
this->get_node_options().use_intra_process_comms(), | ||
msg_mem_strat, | ||
allocator); | ||
} | ||
|
||
template< | ||
typename MessageT, | ||
typename CallbackT, | ||
typename Alloc, | ||
typename SubscriptionT> | ||
std::shared_ptr<SubscriptionT> | ||
Node::create_subscription( | ||
const std::string & topic_name, | ||
CallbackT && callback, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The style states the output args must be placed after input args.
https://google.github.io/styleguide/cppguide.html#Output_Parameters I.e. all const args should be placed before the other ones. |
||
const SubscriptionOptions<Alloc> & options, | ||
rclcpp::callback_group::CallbackGroup::SharedPtr group, | ||
typename rclcpp::message_memory_strategy::MessageMemoryStrategy< | ||
typename rclcpp::subscription_traits::has_message_type<CallbackT>::type, Alloc>::SharedPtr | ||
msg_mem_strat) | ||
{ | ||
using CallbackMessageT = typename rclcpp::subscription_traits::has_message_type<CallbackT>::type; | ||
|
||
std::shared_ptr<Alloc> allocator = options.allocator(); | ||
if (!allocator) { | ||
allocator = std::make_shared<Alloc>(); | ||
} | ||
|
||
if (!msg_mem_strat) { | ||
using rclcpp::message_memory_strategy::MessageMemoryStrategy; | ||
msg_mem_strat = MessageMemoryStrategy<CallbackMessageT, Alloc>::create_default(); | ||
} | ||
|
||
return rclcpp::create_subscription<MessageT, CallbackT, Alloc, CallbackMessageT, SubscriptionT>( | ||
this->node_topics_.get(), | ||
extend_name_with_sub_namespace(topic_name, this->get_sub_namespace()), | ||
std::forward<CallbackT>(callback), | ||
options.qos_profile(), | ||
options.event_callbacks(), | ||
group, | ||
options.ignore_local_publications(), | ||
this->get_node_options().use_intra_process_comms(), | ||
msg_mem_strat, | ||
allocator); | ||
} | ||
|
||
template< | ||
typename MessageT, | ||
typename CallbackT, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,17 +31,21 @@ | |
|
||
#include "rclcpp/allocator/allocator_common.hpp" | ||
#include "rclcpp/allocator/allocator_deleter.hpp" | ||
#include "rclcpp/exceptions.hpp" | ||
#include "rclcpp/macros.hpp" | ||
#include "rclcpp/node_interfaces/node_base_interface.hpp" | ||
#include "rclcpp/publisher_options.hpp" | ||
#include "rclcpp/type_support_decl.hpp" | ||
#include "rclcpp/visibility_control.hpp" | ||
|
||
namespace rclcpp | ||
{ | ||
|
||
// Forward declaration is used for friend statement. | ||
namespace node_interfaces | ||
{ | ||
// NOTE(emersonknapp) Forward declaration avoids including node_base_interface.hpp which causes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this format |
||
// circular inclusion from callback_group.hpp | ||
class NodeBaseInterface; | ||
// Forward declaration is used for friend statement. | ||
class NodeTopicsInterface; | ||
} | ||
|
||
|
@@ -128,6 +132,16 @@ class PublisherBase | |
size_t | ||
get_intra_process_subscription_count() const; | ||
|
||
/// Manually assert that this Publisher is alive (for RMW_QOS_POLICY_MANUAL_BY_TOPIC) | ||
/** | ||
* If the rmw Liveliness policy is set to RMW_QOS_POLICY_MANUAL_BY_TOPIC, the creator of this | ||
* Publisher must manually call `assert_liveliness` periodically to signal that this Publisher | ||
* is still alive. Must be called at least as often as qos_profile's Liveliness lease_duration | ||
*/ | ||
RCLCPP_PUBLIC | ||
void | ||
assert_liveliness() {} | ||
|
||
/// Compare this publisher to a gid. | ||
/** | ||
* Note that this function calls the next function. | ||
|
@@ -194,6 +208,7 @@ class Publisher : public PublisherBase | |
rclcpp::node_interfaces::NodeBaseInterface * node_base, | ||
const std::string & topic, | ||
const rcl_publisher_options_t & publisher_options, | ||
const PublisherEventCallbacks & /* event_callbacks */, | ||
const std::shared_ptr<MessageAlloc> & allocator) | ||
: PublisherBase( | ||
node_base, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs doc to explain why we pass a WeakPtr here - when can the pointer be dead? if the node is dying?