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 
20 #include "rclcpp/macros.hpp"
21 #include "rclcpp/time.hpp"
23 
24 #include "rcl/time.h"
25 
26 namespace rclcpp
27 {
28 
29 class TimeSource;
30 
32 {
33 public:
35 
36  using pre_callback_t = std::function<void ()>;
37  using post_callback_t = std::function<void (const rcl_time_jump_t &)>;
38 
42  const rcl_jump_threshold_t & threshold);
43 
44  pre_callback_t pre_callback;
45  post_callback_t post_callback;
47 };
48 
49 class Clock
50 {
51 public:
53 
54 
55 
62  explicit Clock(rcl_clock_type_t clock_type = RCL_SYSTEM_TIME);
63 
65  ~Clock();
66 
74  Time
75  now();
76 
85  bool
86  ros_time_is_active();
87 
89  rcl_clock_t *
90  get_clock_handle() noexcept;
91 
94  get_clock_type() const noexcept;
95 
96  // Add a callback to invoke if the jump threshold is exceeded.
118  JumpHandler::SharedPtr
119  create_jump_callback(
120  JumpHandler::pre_callback_t pre_callback,
121  JumpHandler::post_callback_t post_callback,
122  const rcl_jump_threshold_t & threshold);
123 
124 private:
125  // Invoke time jump callback
127  static void
128  on_time_jump(
129  const struct rcl_time_jump_t * time_jump,
130  bool before_jump,
131  void * user_data);
132 
134  rcl_clock_t rcl_clock_;
135  friend TimeSource;
136  rcl_allocator_t allocator_;
137 };
138 
139 } // namespace rclcpp
140 
141 #endif // RCLCPP__CLOCK_HPP_
rcl_clock_type_t
This header provides the get_node_topics_interface() template function.
Definition: allocator_common.hpp:24
Definition: clock.hpp:31
RCL_SYSTEM_TIME
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
Definition: clock.hpp:49
post_callback_t post_callback
Definition: clock.hpp:45
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
Definition: time_source.hpp:34
Definition: time.hpp:31
rcl_jump_threshold_t notice_threshold
Definition: clock.hpp:46
pre_callback_t pre_callback
Definition: clock.hpp:44