15 #include "rclcpp/node_interfaces/node_topics.hpp"
20 #include "rclcpp/callback_group.hpp"
21 #include "rclcpp/exceptions.hpp"
22 #include "rclcpp/node_interfaces/node_base_interface.hpp"
23 #include "rclcpp/node_interfaces/node_timers_interface.hpp"
24 #include "rclcpp/publisher_base.hpp"
25 #include "rclcpp/publisher_factory.hpp"
26 #include "rclcpp/subscription_base.hpp"
27 #include "rclcpp/subscription_factory.hpp"
28 #include "rclcpp/qos.hpp"
30 using rclcpp::exceptions::throw_from_rcl_error;
34 NodeTopics::NodeTopics(
37 : node_base_(node_base), node_timers_(node_timers)
40 NodeTopics::~NodeTopics()
43 rclcpp::PublisherBase::SharedPtr
44 NodeTopics::create_publisher(
45 const std::string & topic_name,
50 return publisher_factory.create_typed_publisher(node_base_, topic_name, qos);
54 NodeTopics::add_publisher(
55 rclcpp::PublisherBase::SharedPtr publisher,
56 rclcpp::CallbackGroup::SharedPtr callback_group)
67 for (
auto & key_event_pair : publisher->get_event_handlers()) {
68 auto publisher_event = key_event_pair.second;
69 callback_group->add_waitable(publisher_event);
75 callback_group->trigger_notify_guard_condition();
77 throw std::runtime_error(
78 std::string(
"failed to notify wait set on publisher creation: ") + ex.what());
82 rclcpp::SubscriptionBase::SharedPtr
83 NodeTopics::create_subscription(
84 const std::string & topic_name,
89 return subscription_factory.create_typed_subscription(node_base_, topic_name, qos);
93 NodeTopics::add_subscription(
94 rclcpp::SubscriptionBase::SharedPtr subscription,
95 rclcpp::CallbackGroup::SharedPtr callback_group)
106 callback_group->add_subscription(subscription);
108 for (
auto & key_event_pair : subscription->get_event_handlers()) {
109 auto subscription_event = key_event_pair.second;
110 callback_group->add_waitable(subscription_event);
113 auto intra_process_waitable = subscription->get_intra_process_waitable();
114 if (
nullptr != intra_process_waitable) {
116 callback_group->add_waitable(intra_process_waitable);
122 callback_group->trigger_notify_guard_condition();
124 throw std::runtime_error(
125 std::string(
"failed to notify wait set on subscription creation: ") + ex.what());
130 NodeTopics::get_node_base_interface()
const
136 NodeTopics::get_node_timers_interface()
const
Encapsulation of Quality of Service settings.
Thrown when a callback group is missing from the node, when it wants to utilize the group.
Created when the return code does not match one of the other specialized exceptions.
Pure virtual interface class for the NodeBase part of the Node API.
virtual RCLCPP_PUBLIC void trigger_notify_guard_condition()=0
Trigger the guard condition that notifies of internal node state changes.
virtual RCLCPP_PUBLIC bool callback_group_in_node(rclcpp::CallbackGroup::SharedPtr group)=0
Return true if the given callback group is associated with this node.
virtual RCLCPP_PUBLIC rclcpp::CallbackGroup::SharedPtr get_default_callback_group()=0
Return the default callback group.
virtual RCLCPP_PUBLIC std::string resolve_topic_or_service_name(const std::string &name, bool is_service, bool only_expand=false) const =0
Expand and remap a given topic or service name.
Pure virtual interface class for the NodeTimers part of the Node API.
Implementation of the NodeTopics part of the Node API.
RCLCPP_PUBLIC std::string resolve_topic_name(const std::string &name, bool only_expand=false) const override
Get a remapped and expanded topic name given an input name.
Factory with functions used to create a MessageT specific PublisherT.
Factory containing a function used to create a Subscription<MessageT>.