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 #include <vector>
22 
23 #include "rclcpp/macros.hpp"
24 #include "rclcpp/time.hpp"
26 
27 #include "rcl/time.h"
28 
29 namespace rclcpp
30 {
31 
32 class TimeSource;
33 
35 {
36 public:
41  const rcl_jump_threshold_t & threshold);
42 
46 };
47 
48 class Clock
49 {
50 public:
52 
54  explicit Clock(rcl_clock_type_t clock_type = RCL_SYSTEM_TIME);
55 
57  ~Clock();
58 
60  Time
61  now();
62 
64  bool
65  ros_time_is_active();
66 
68  rcl_clock_t *
69  get_clock_handle();
70 
73  get_clock_type();
74 
75  // Add a callback to invoke if the jump threshold is exceeded.
81  JumpHandler::SharedPtr
82  create_jump_callback(
85  const rcl_jump_threshold_t & threshold);
86 
87 private:
88  // Invoke time jump callback
90  static void
91  on_time_jump(
92  const struct rcl_time_jump_t * time_jump,
93  bool before_jump,
94  void * user_data);
95 
97  rcl_clock_t rcl_clock_;
98  friend TimeSource;
99  rcl_allocator_t allocator_;
100 };
101 
102 } // namespace rclcpp
103 
104 #endif // RCLCPP__CLOCK_HPP_
rcl_clock_type_t
Definition: allocator_common.hpp:24
JumpHandler(std::function< void()> pre_callback, std::function< void(const rcl_time_jump_t &)> post_callback, const rcl_jump_threshold_t &threshold)
std::function< void()> pre_callback
Definition: clock.hpp:43
Definition: clock.hpp:34
RCL_SYSTEM_TIME
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
std::function< void(const rcl_time_jump_t &)> post_callback
Definition: clock.hpp:44
Definition: clock.hpp:48
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
Definition: time_source.hpp:36
Definition: time.hpp:31
rcl_jump_threshold_t notice_threshold
Definition: clock.hpp:45