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)
61 throw std::runtime_error(
"Cannot create publisher, callback group not in node.");
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);
76 callback_group->trigger_notify_guard_condition();
78 throw std::runtime_error(
79 std::string(
"failed to notify wait set on publisher creation: ") + ex.what());
83 rclcpp::SubscriptionBase::SharedPtr
84 NodeTopics::create_subscription(
85 const std::string & topic_name,
90 return subscription_factory.create_typed_subscription(node_base_, topic_name, qos);
94 NodeTopics::add_subscription(
95 rclcpp::SubscriptionBase::SharedPtr subscription,
96 rclcpp::CallbackGroup::SharedPtr callback_group)
102 throw std::runtime_error(
"Cannot create subscription, callback group not in node.");
108 callback_group->add_subscription(subscription);
110 for (
auto & key_event_pair : subscription->get_event_handlers()) {
111 auto subscription_event = key_event_pair.second;
112 callback_group->add_waitable(subscription_event);
115 auto intra_process_waitable = subscription->get_intra_process_waitable();
116 if (
nullptr != intra_process_waitable) {
118 callback_group->add_waitable(intra_process_waitable);
125 callback_group->trigger_notify_guard_condition();
127 throw std::runtime_error(
128 std::string(
"failed to notify wait set on subscription creation: ") + ex.what());
133 NodeTopics::get_node_base_interface()
const
139 NodeTopics::get_node_timers_interface()
const
RCLCPP_PUBLIC void trigger()
Notify the wait set waiting on this condition, if any, that the condition had been met.
Encapsulation of Quality of Service settings.
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 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.
virtual RCLCPP_PUBLIC rclcpp::GuardCondition & get_notify_guard_condition()=0
Return a guard condition that should be notified when the internal node state changes.
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>.