ROS 2 rclcpp + rcl - rolling  rolling-a919a6e5
ROS 2 C++ Client Library with ROS Client Library
node_timers.cpp
1 // Copyright 2016 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "rclcpp/node_interfaces/node_timers.hpp"
16 
17 #include <string>
18 
19 #include "tracetools/tracetools.h"
20 
22 
23 NodeTimers::NodeTimers(rclcpp::node_interfaces::NodeBaseInterface * node_base)
24 : node_base_(node_base)
25 {}
26 
27 NodeTimers::~NodeTimers()
28 {}
29 
30 void
32  rclcpp::TimerBase::SharedPtr timer,
33  rclcpp::CallbackGroup::SharedPtr callback_group)
34 {
35  if (callback_group) {
36  if (!node_base_->callback_group_in_node(callback_group)) {
38  }
39  } else {
40  callback_group = node_base_->get_default_callback_group();
41  }
42  callback_group->add_timer(timer);
43 
44  try {
45  node_base_->trigger_notify_guard_condition();
46  callback_group->trigger_notify_guard_condition();
47  } catch (const rclcpp::exceptions::RCLError & ex) {
48  throw std::runtime_error(
49  std::string("failed to notify wait set on timer creation: ") + ex.what());
50  }
51 
52  TRACETOOLS_TRACEPOINT(
53  rclcpp_timer_link_node,
54  static_cast<const void *>(timer->get_timer_handle().get()),
55  static_cast<const void *>(node_base_->get_rcl_node_handle()));
56 }
Thrown when a callback group is missing from the node, when it wants to utilize the group.
Definition: exceptions.hpp:244
Created when the return code does not match one of the other specialized exceptions.
Definition: exceptions.hpp:162
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 rcl_node_t * get_rcl_node_handle()=0
Return the rcl_node_t node handle (non-const version).
Implementation of the NodeTimers part of the Node API.
Definition: node_timers.hpp:32
RCLCPP_PUBLIC void add_timer(rclcpp::TimerBase::SharedPtr timer, rclcpp::CallbackGroup::SharedPtr callback_group) override
Add a timer to the node.
Definition: node_timers.cpp:31