rclcpp  master
C++ ROS Client Library API
clock.hpp
Go to the documentation of this file.
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__CLOCK_HPP_
16 #define RCLCPP__CLOCK_HPP_
17 
18 #include <functional>
19 #include <memory>
20 #include <mutex>
21 
22 #include "rclcpp/macros.hpp"
23 #include "rclcpp/time.hpp"
25 
26 #include "rcl/time.h"
27 #include "rcutils/time.h"
29 
30 namespace rclcpp
31 {
32 
33 class TimeSource;
34 
36 {
37 public:
39 
40  using pre_callback_t = std::function<void ()>;
41  using post_callback_t = std::function<void (const rcl_time_jump_t &)>;
42 
46  const rcl_jump_threshold_t & threshold);
47 
51 };
52 
53 class Clock
54 {
55 public:
57 
58 
59 
66  explicit Clock(rcl_clock_type_t clock_type = RCL_SYSTEM_TIME);
67 
69  ~Clock();
70 
78  Time
79  now();
80 
89  bool
90  ros_time_is_active();
91 
94  rcl_clock_t *
95  get_clock_handle() noexcept;
96 
98  rcl_clock_type_t
99  get_clock_type() const noexcept;
100 
103  std::mutex &
104  get_clock_mutex() noexcept;
105 
106  // Add a callback to invoke if the jump threshold is exceeded.
128  JumpHandler::SharedPtr
129  create_jump_callback(
132  const rcl_jump_threshold_t & threshold);
133 
134 private:
135  // Invoke time jump callback
137  static void
138  on_time_jump(
139  const struct rcl_time_jump_t * time_jump,
140  bool before_jump,
141  void * user_data);
142 
144  class Impl;
145 
146  std::shared_ptr<Impl> impl_;
147 };
148 
149 } // namespace rclcpp
150 
151 #endif // RCLCPP__CLOCK_HPP_
std::shared_ptr< Impl >
time.h
rclcpp::Time
Definition: time.hpp:31
std::function< void()>
rclcpp::JumpHandler::post_callback
post_callback_t post_callback
Definition: clock.hpp:49
rcutils_ret.h
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
RCLCPP_PUBLIC
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
rclcpp::JumpHandler
Definition: clock.hpp:35
RCLCPP_SMART_PTR_DEFINITIONS
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
rcl_time_jump_t
macros.hpp
rclcpp::JumpHandler::pre_callback
pre_callback_t pre_callback
Definition: clock.hpp:48
rcl_jump_threshold_t
rcl_clock_t
rclcpp::Clock
Definition: clock.hpp:53
visibility_control.hpp
std
rclcpp::JumpHandler::notice_threshold
rcl_jump_threshold_t notice_threshold
Definition: clock.hpp:50
std::mutex
time.hpp