rcl  master
C API providing common ROS client library functionality.
time.h
Go to the documentation of this file.
1 // Copyright 2015 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 RCL__TIME_H_
16 #define RCL__TIME_H_
17 
18 #ifdef __cplusplus
19 extern "C"
20 {
21 #endif
22 
23 #include "rcl/allocator.h"
24 #include "rcl/macros.h"
25 #include "rcl/types.h"
26 #include "rcl/visibility_control.h"
27 #include "rcutils/time.h"
28 
30 #define RCL_S_TO_NS RCUTILS_S_TO_NS
31 #define RCL_MS_TO_NS RCUTILS_MS_TO_NS
33 #define RCL_US_TO_NS RCUTILS_US_TO_NS
35 
37 #define RCL_NS_TO_S RCUTILS_NS_TO_S
38 #define RCL_NS_TO_MS RCUTILS_NS_TO_MS
40 #define RCL_NS_TO_US RCUTILS_NS_TO_US
42 
47 
49 typedef enum rcl_clock_type_t
50 {
56 
58 typedef struct rcl_duration_t
59 {
60  rcl_duration_value_t nanoseconds;
62 
64 typedef enum rcl_clock_change_t
65 {
75 
77 typedef struct rcl_time_jump_t
78 {
84 
90 typedef void (* rcl_jump_callback_t)(
91  const struct rcl_time_jump_t * time_jump,
92  bool before_jump,
93  void * user_data);
94 
96 typedef struct rcl_jump_threshold_t
97 {
107 
110 {
113  void * user_data;
115 
117 typedef struct rcl_clock_t
118 {
119  enum rcl_clock_type_t type;
124  rcl_ret_t (* get_now)(void * data, rcl_time_point_value_t * now);
125  // void (*set_now) (rcl_time_point_value_t);
126  void * data;
128 } rcl_clock_t;
129 
131 typedef struct rcl_time_point_t
132 {
133  rcl_time_point_value_t nanoseconds;
134  rcl_clock_type_t clock_type;
136 
137 // typedef struct rcl_rate_t
138 // {
139 // rcl_time_point_value_t trigger_time;
140 // int64_t period;
141 // rcl_clock_type_t clock;;
142 // } rcl_rate_t;
143 // TODO(tfoote) integrate rate and timer implementations
144 
146 
157 bool
159 
161 
173 rcl_ret_t
175  enum rcl_clock_type_t clock_type, rcl_clock_t * clock,
176  rcl_allocator_t * allocator);
177 
179 
193 rcl_ret_t
195  rcl_clock_t * clock);
196 
198 
210 rcl_ret_t
212  rcl_clock_t * clock,
213  rcl_allocator_t * allocator);
214 
216 
228 rcl_ret_t
230  rcl_clock_t * clock);
231 
233 
245 rcl_ret_t
247  rcl_clock_t * clock,
248  rcl_allocator_t * allocator);
249 
251 
265 rcl_ret_t
267  rcl_clock_t * clock);
268 
270 
284 rcl_ret_t
286  rcl_clock_t * clock,
287  rcl_allocator_t * allocator);
288 
290 
304 rcl_ret_t
306  rcl_clock_t * clock);
307 
309 
326 rcl_ret_t
328  rcl_time_point_t * start, rcl_time_point_t * finish, rcl_duration_t * delta);
329 
331 
342 rcl_ret_t
343 rcl_clock_get_now(rcl_clock_t * clock, rcl_time_point_value_t * time_point_value);
344 
345 
347 
359 rcl_ret_t
361 
363 
375 rcl_ret_t
377 
378 
380 
393 rcl_ret_t
395  rcl_clock_t * clock, bool * is_enabled);
396 
398 
412 rcl_ret_t
414  rcl_clock_t * clock, rcl_time_point_value_t time_value);
415 
417 
433 rcl_ret_t
435  rcl_clock_t * clock, rcl_jump_threshold_t threshold, rcl_jump_callback_t callback,
436  void * user_data);
437 
439 
450 rcl_ret_t
452  rcl_clock_t * clock, rcl_jump_callback_t callback, void * user_data);
453 
454 #ifdef __cplusplus
455 }
456 #endif
457 
458 #endif // RCL__TIME_H_
struct rcl_time_jump_t rcl_time_jump_t
Struct to describe a jump in time.
rcl_allocator_t allocator
Definition: time.h:127
rcl_ret_t rcl_set_ros_time_override(rcl_clock_t *clock, rcl_time_point_value_t time_value)
Set the current time for this RCL_ROS_TIME time source.
A single point in time, measured in nanoseconds, the reference point is based on the source...
Definition: time.h:131
rcl_ret_t rcl_disable_ros_time_override(rcl_clock_t *clock)
Disable the ROS time abstraction override.
rcl_duration_value_t nanoseconds
Definition: time.h:60
rcl_ret_t rcl_steady_clock_init(rcl_clock_t *clock, rcl_allocator_t *allocator)
Initialize a clock as a RCL_STEADY_TIME time source.
bool rcl_clock_valid(rcl_clock_t *clock)
Check if the clock has valid values.
rcl_jump_threshold_t threshold
Definition: time.h:112
void * user_data
Definition: time.h:113
rcl_clock_type_t clock_type
Definition: time.h:134
rcl_clock_change_t clock_change
Indicate whether or not the source of time changed.
Definition: time.h:80
rmw_ret_t rcl_ret_t
Definition: types.h:20
rcl_ret_t rcl_clock_fini(rcl_clock_t *clock)
Finalize a clock.
struct rcl_time_point_t rcl_time_point_t
A single point in time, measured in nanoseconds, the reference point is based on the source...
rcl_clock_type_t
Time source type, used to indicate the source of a time measurement.
Definition: time.h:49
rcl_time_point_value_t nanoseconds
Definition: time.h:133
rcl_jump_callback_info_t * jump_callbacks
An array of added jump callbacks.
Definition: time.h:121
Definition: time.h:51
rcl_ret_t rcl_enable_ros_time_override(rcl_clock_t *clock)
Enable the ROS time abstraction override.
rcl_ret_t rcl_system_clock_fini(rcl_clock_t *clock)
Finalize a clock as a RCL_SYSTEM_TIME time source.
Describe the prerequisites for calling a time jump callback.
Definition: time.h:96
rcl_ret_t rcl_clock_get_now(rcl_clock_t *clock, rcl_time_point_value_t *time_point_value)
Fill the time point value with the current value of the associated clock.
rcl_duration_t min_backward
Definition: time.h:105
int64_t rcutils_time_point_value_t
bool on_clock_change
True to call callback when the clock type changes.
Definition: time.h:99
rcl_duration_t min_forward
Definition: time.h:102
rcl_ret_t rcl_ros_clock_init(rcl_clock_t *clock, rcl_allocator_t *allocator)
Initialize a clock as a RCL_ROS_TIME time source.
int64_t rcutils_duration_value_t
rcutils_time_point_value_t rcl_time_point_value_t
A single point in time, measured in nanoseconds since the Unix epoch.
Definition: time.h:44
The source switched to ROS_TIME from SYSTEM_TIME.
Definition: time.h:69
The source switched to SYSTEM_TIME from ROS_TIME.
Definition: time.h:71
Definition: time.h:53
rcl_ret_t rcl_steady_clock_fini(rcl_clock_t *clock)
Finalize a clock as a RCL_STEADY_TIME time source.
void(* rcl_jump_callback_t)(const struct rcl_time_jump_t *time_jump, bool before_jump, void *user_data)
Definition: time.h:90
#define RCL_WARN_UNUSED
Ignored return values of functions with this macro will emit a warning.
Definition: macros.h:25
Definition: time.h:54
rcl_clock_change_t
Enumeration to describe the type of time jump.
Definition: time.h:64
rcutils_duration_value_t rcl_duration_value_t
A duration of time, measured in nanoseconds.
Definition: time.h:46
rcl_duration_t delta
The new time minus the last time before the jump.
Definition: time.h:82
struct rcl_clock_t rcl_clock_t
Encapsulation of a time source.
Struct to describe an added callback.
Definition: time.h:109
Encapsulation of a time source.
Definition: time.h:117
#define RCL_PUBLIC
Definition: visibility_control.h:48
struct rcl_jump_callback_info_t rcl_jump_callback_info_t
Struct to describe an added callback.
struct rcl_duration_t rcl_duration_t
A duration of time, measured in nanoseconds and its source.
rcl_ret_t rcl_clock_init(enum rcl_clock_type_t clock_type, rcl_clock_t *clock, rcl_allocator_t *allocator)
Initialize a clock based on the passed type.
A duration of time, measured in nanoseconds and its source.
Definition: time.h:58
Definition: time.h:52
rcl_jump_callback_t callback
Definition: time.h:111
rcl_ret_t rcl_clock_add_jump_callback(rcl_clock_t *clock, rcl_jump_threshold_t threshold, rcl_jump_callback_t callback, void *user_data)
Add a callback to be called when a time jump exceeds a threshold.
The source before and after the jump is SYSTEM_TIME.
Definition: time.h:73
size_t num_jump_callbacks
Number of callbacks in jump_callbacks.
Definition: time.h:123
rcl_ret_t rcl_is_enabled_ros_time_override(rcl_clock_t *clock, bool *is_enabled)
Check if the RCL_ROS_TIME time source has the override enabled.
rcl_ret_t rcl_difference_times(rcl_time_point_t *start, rcl_time_point_t *finish, rcl_duration_t *delta)
Compute the difference between two time points.
The source before and after the jump is ROS_TIME.
Definition: time.h:67
rcl_ret_t rcl_ros_clock_fini(rcl_clock_t *clock)
Finalize a clock as a RCL_ROS_TIME time source.
rcl_ret_t rcl_clock_remove_jump_callback(rcl_clock_t *clock, rcl_jump_callback_t callback, void *user_data)
Remove a previously added time jump callback.
rcl_ret_t rcl_system_clock_init(rcl_clock_t *clock, rcl_allocator_t *allocator)
Initialize a clock as a RCL_SYSTEM_TIME time source.
struct rcl_jump_threshold_t rcl_jump_threshold_t
Describe the prerequisites for calling a time jump callback.
Struct to describe a jump in time.
Definition: time.h:77
void * data
Definition: time.h:126