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 #include "rcutils/time.h"
27 
28 namespace rclcpp
29 {
30 
31 class TimeSource;
32 
34 {
35 public:
37 
38  using pre_callback_t = std::function<void ()>;
39  using post_callback_t = std::function<void (const rcl_time_jump_t &)>;
40 
44  const rcl_jump_threshold_t & threshold);
45 
46  pre_callback_t pre_callback;
47  post_callback_t post_callback;
49 };
50 
51 class Clock
52 {
53 public:
55 
56 
57 
64  explicit Clock(rcl_clock_type_t clock_type = RCL_SYSTEM_TIME);
65 
67  ~Clock();
68 
76  Time
77  now();
78 
87  bool
88  ros_time_is_active();
89 
91  rcl_clock_t *
92  get_clock_handle() noexcept;
93 
96  get_clock_type() const noexcept;
97 
98  // Add a callback to invoke if the jump threshold is exceeded.
121  create_jump_callback(
122  JumpHandler::pre_callback_t pre_callback,
123  JumpHandler::post_callback_t post_callback,
124  const rcl_jump_threshold_t & threshold);
125 
126 private:
127  // Invoke time jump callback
129  static void
130  on_time_jump(
131  const struct rcl_time_jump_t * time_jump,
132  bool before_jump,
133  void * user_data);
134 
136  rcl_clock_t rcl_clock_;
137  friend TimeSource;
138  rcl_allocator_t allocator_;
139 };
140 
141 } // namespace rclcpp
142 
143 #endif // RCLCPP__CLOCK_HPP_
rcl_clock_type_t
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
Definition: clock.hpp:33
RCL_SYSTEM_TIME
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
Definition: clock.hpp:51
post_callback_t post_callback
Definition: clock.hpp:47
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
Set the data type used in the intra-process buffer as std::shared_ptr<MessageT>
Definition: time_source.hpp:35
Definition: time.hpp:31
rcl_jump_threshold_t notice_threshold
Definition: clock.hpp:48
pre_callback_t pre_callback
Definition: clock.hpp:46