ROS 2 rclcpp + rcl - rolling  rolling-20536064
ROS 2 C++ Client Library with ROS Client Library
time_source.hpp
1 // Copyright 2017 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 #ifndef RCLCPP__TIME_SOURCE_HPP_
16 #define RCLCPP__TIME_SOURCE_HPP_
17 
18 #include <memory>
19 #include <vector>
20 
21 #include "rcl/time.h"
22 
23 #include "builtin_interfaces/msg/time.hpp"
24 #include "rosgraph_msgs/msg/clock.hpp"
25 #include "rcl_interfaces/msg/parameter_event.hpp"
26 
27 #include "rclcpp/node.hpp"
28 #include "rclcpp/node_interfaces/node_parameters_interface.hpp"
29 
30 
31 namespace rclcpp
32 {
33 class Clock;
34 
50 {
51 public:
53 
60  RCLCPP_PUBLIC
61  explicit TimeSource(
62  const rclcpp::Node::SharedPtr & node,
63  const rclcpp::QoS & qos = rclcpp::ClockQoS(),
64  bool use_clock_thread = true);
65 
67 
73  RCLCPP_PUBLIC
74  explicit TimeSource(
75  const rclcpp::QoS & qos = rclcpp::ClockQoS(),
76  bool use_clock_thread = true);
77 
78  // The TimeSource is uncopyable
79  TimeSource(const TimeSource &) = delete;
80  TimeSource & operator=(const TimeSource &) = delete;
81 
82  // The TimeSource is moveable
83  TimeSource(TimeSource &&) = default;
84  TimeSource & operator=(TimeSource &&) = default;
85 
87 
90  RCLCPP_PUBLIC
91  void attachNode(const rclcpp::Node::SharedPtr & node);
92 
94 
106  RCLCPP_PUBLIC
107  void attachNode(
108  rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_interface,
109  rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_interface,
110  rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_interface,
111  rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services_interface,
112  rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging_interface,
113  rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock_interface,
114  rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_parameters_interface);
115 
117  RCLCPP_PUBLIC
118  void detachNode();
119 
121 
125  RCLCPP_PUBLIC
126  void attachClock(const rclcpp::Clock::SharedPtr & clock);
127 
129  RCLCPP_PUBLIC
130  void detachClock(const rclcpp::Clock::SharedPtr & clock);
131 
133  RCLCPP_PUBLIC
134  bool get_use_clock_thread();
135 
137  RCLCPP_PUBLIC
138  void set_use_clock_thread(bool use_clock_thread);
139 
141  RCLCPP_PUBLIC
143 
145  RCLCPP_PUBLIC
146  ~TimeSource();
147 
148 private:
149  class NodeState;
150  std::shared_ptr<NodeState> node_state_;
151 
152  // Preserve the arguments received by the constructor for reuse at runtime
153  bool constructed_use_clock_thread_;
154  rclcpp::QoS constructed_qos_;
155 };
156 
157 } // namespace rclcpp
158 
159 #endif // RCLCPP__TIME_SOURCE_HPP_
Encapsulation of Quality of Service settings.
Definition: qos.hpp:114
RCLCPP_PUBLIC bool get_use_clock_thread()
Get whether a separate clock thread is used or not.
RCLCPP_PUBLIC void attachNode(const rclcpp::Node::SharedPtr &node)
Attach node to the time source.
RCLCPP_PUBLIC void set_use_clock_thread(bool use_clock_thread)
Set whether to use a separate clock thread or not.
RCLCPP_PUBLIC bool clock_thread_is_joinable()
Check if the clock thread is joinable.
RCLCPP_PUBLIC ~TimeSource()
TimeSource Destructor.
RCLCPP_PUBLIC void attachClock(const rclcpp::Clock::SharedPtr &clock)
Attach a clock to the time source to be updated.
RCLCPP_PUBLIC void detachNode()
Detach the node from the time source.
RCLCPP_PUBLIC TimeSource(const rclcpp::Node::SharedPtr &node, const rclcpp::QoS &qos=rclcpp::ClockQoS(), bool use_clock_thread=true)
Constructor.
RCLCPP_PUBLIC void detachClock(const rclcpp::Clock::SharedPtr &clock)
Detach a clock from the time source.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.