ROS 2 rclcpp + rcl - rolling  rolling-e7363f10
ROS 2 C++ Client Library with ROS Client Library
timer.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 
16 
17 #ifndef RCL__TIMER_H_
18 #define RCL__TIMER_H_
19 
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 #include <stdbool.h>
26 #include <stddef.h>
27 #include <stdint.h>
28 
29 #include "rcl/allocator.h"
30 #include "rcl/context.h"
31 #include "rcl/event_callback.h"
32 #include "rcl/guard_condition.h"
33 #include "rcl/macros.h"
34 #include "rcl/time.h"
35 #include "rcl/types.h"
36 #include "rcl/visibility_control.h"
37 
38 typedef struct rcl_timer_impl_s rcl_timer_impl_t;
39 
41 typedef struct rcl_timer_s
42 {
46 
49 {
50  rcl_event_callback_t on_reset_callback;
51  const void * user_data;
52  size_t reset_counter;
54 
56 typedef struct rcl_timer_call_info_s
57 {
58  rcl_time_point_value_t expected_call_time;
59  rcl_time_point_value_t actual_call_time;
61 
63 
77 typedef void (* rcl_timer_callback_t)(rcl_timer_t *, int64_t, uintptr_t);
78 
80 RCL_PUBLIC
81 RCL_WARN_UNUSED
84 
86 
172 RCL_PUBLIC
173 RCL_WARN_UNUSED
174 rcl_ret_t
176  rcl_timer_t * timer,
177  rcl_clock_t * clock,
178  rcl_context_t * context,
179  int64_t period,
180  const rcl_timer_callback_t callback,
181  rcl_allocator_t allocator,
182  bool autostart);
183 
185 
210 RCL_PUBLIC
211 RCL_WARN_UNUSED
212 rcl_ret_t
213 rcl_timer_fini(rcl_timer_t * timer);
214 
216 
254 RCL_PUBLIC
255 RCL_WARN_UNUSED
256 rcl_ret_t
257 rcl_timer_call(rcl_timer_t * timer);
258 
260 
282 RCL_PUBLIC
283 RCL_WARN_UNUSED
284 rcl_ret_t
286 
288 
307 RCL_PUBLIC
308 RCL_WARN_UNUSED
309 rcl_ret_t
310 rcl_timer_clock(const rcl_timer_t * timer, rcl_clock_t ** clock);
311 
313 
337 RCL_PUBLIC
338 RCL_WARN_UNUSED
339 rcl_ret_t
340 rcl_timer_is_ready(const rcl_timer_t * timer, bool * is_ready);
341 
343 
373 RCL_PUBLIC
374 RCL_WARN_UNUSED
375 rcl_ret_t
376 rcl_timer_get_time_until_next_call(const rcl_timer_t * timer, int64_t * time_until_next_call);
377 
379 
397 RCL_PUBLIC
398 RCL_WARN_UNUSED
399 rcl_ret_t
400 rcl_timer_get_next_call_time(const rcl_timer_t * timer, int64_t * next_call_time);
401 
403 
429 RCL_PUBLIC
430 RCL_WARN_UNUSED
431 rcl_ret_t
432 rcl_timer_get_time_since_last_call(const rcl_timer_t * timer, int64_t * time_since_last_call);
433 
435 
456 RCL_PUBLIC
457 RCL_WARN_UNUSED
458 rcl_ret_t
459 rcl_timer_get_period(const rcl_timer_t * timer, int64_t * period);
460 
462 
487 RCL_PUBLIC
488 RCL_WARN_UNUSED
489 rcl_ret_t
490 rcl_timer_exchange_period(const rcl_timer_t * timer, int64_t new_period, int64_t * old_period);
491 
493 
510 RCL_PUBLIC
511 RCL_WARN_UNUSED
513 rcl_timer_get_callback(const rcl_timer_t * timer);
514 
516 
533 RCL_PUBLIC
534 RCL_WARN_UNUSED
535 uintptr_t
537 
539 
560 RCL_PUBLIC
561 RCL_WARN_UNUSED
564 
566 
587 RCL_PUBLIC
588 RCL_WARN_UNUSED
589 uintptr_t
590 rcl_timer_exchange_callback_data(rcl_timer_t * timer, uintptr_t data);
591 
592 
594 
615 RCL_PUBLIC
616 RCL_WARN_UNUSED
617 rcl_ret_t
619 
621 
644 RCL_PUBLIC
645 RCL_WARN_UNUSED
646 rcl_ret_t
647 rcl_timer_is_canceled(const rcl_timer_t * timer, bool * is_canceled);
648 
650 
670 RCL_PUBLIC
671 RCL_WARN_UNUSED
672 rcl_ret_t
674 
676 
694 RCL_PUBLIC
695 RCL_WARN_UNUSED
696 const rcl_allocator_t *
697 rcl_timer_get_allocator(const rcl_timer_t * timer);
698 
700 
713 RCL_PUBLIC
714 RCL_WARN_UNUSED
717 
719 
738 RCL_PUBLIC
739 RCL_WARN_UNUSED
740 rcl_ret_t
742  const rcl_timer_t * timer,
743  rcl_event_callback_t on_reset_callback,
744  const void * user_data);
745 
746 #ifdef __cplusplus
747 }
748 #endif
749 
750 #endif // RCL__TIMER_H_
rcutils_allocator_t rcl_allocator_t
Encapsulation of an allocator.
Definition: allocator.h:31
Encapsulation of a time source.
Definition: time.h:141
Encapsulates the non-global state of an init/shutdown cycle.
Definition: context.h:117
Handle for a rcl guard condition.
Structure which encapsulates timer information when called.
Definition: timer.h:57
Structure which encapsulates the on reset callback data.
Definition: timer.h:49
Structure which encapsulates a ROS Timer.
Definition: timer.h:42
rcl_timer_impl_t * impl
Private implementation pointer.
Definition: timer.h:44
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:49
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_get_next_call_time(const rcl_timer_t *timer, int64_t *next_call_time)
Retrieve the time when the next call to rcl_timer_call() shall occur.
Definition: timer.c:326
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_get_time_since_last_call(const rcl_timer_t *timer, int64_t *time_since_last_call)
Retrieve the time since the previous call to rcl_timer_call() occurred.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_get_time_until_next_call(const rcl_timer_t *timer, int64_t *time_until_next_call)
Calculate and retrieve the time until the next call in nanoseconds.
Definition: timer.c:342
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_call(rcl_timer_t *timer)
Call the timer's callback and set the last call time.
Definition: timer.c:243
void(* rcl_timer_callback_t)(rcl_timer_t *, int64_t, uintptr_t)
User callback signature for timers.
Definition: timer.h:77
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_reset(rcl_timer_t *timer)
Reset a timer.
Definition: timer.c:464
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_get_period(const rcl_timer_t *timer, int64_t *period)
Retrieve the period of the timer.
Definition: timer.c:381
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_set_on_reset_callback(const rcl_timer_t *timer, rcl_event_callback_t on_reset_callback, const void *user_data)
Set the on reset callback function for the timer.
Definition: timer.c:514
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_exchange_period(const rcl_timer_t *timer, int64_t new_period, int64_t *old_period)
Exchange the period of the timer and return the previous period.
Definition: timer.c:391
RCL_PUBLIC RCL_WARN_UNUSED rcl_timer_callback_t rcl_timer_get_callback(const rcl_timer_t *timer)
Return the current timer callback.
Definition: timer.c:406
RCL_PUBLIC RCL_WARN_UNUSED rcl_timer_callback_t rcl_timer_exchange_callback(rcl_timer_t *timer, const rcl_timer_callback_t new_callback)
Exchange the current timer callback and return the current callback.
Definition: timer.c:422
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_init2(rcl_timer_t *timer, rcl_clock_t *clock, rcl_context_t *context, int64_t period, const rcl_timer_callback_t callback, rcl_allocator_t allocator, bool autostart)
Initialize a timer.
Definition: timer.c:109
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_cancel(rcl_timer_t *timer)
Cancel a timer.
Definition: timer.c:441
RCL_PUBLIC RCL_WARN_UNUSED uintptr_t rcl_timer_get_callback_data(const rcl_timer_t *timer)
Return the current timer callback data.
Definition: timer.c:414
struct rcl_timer_s rcl_timer_t
Structure which encapsulates a ROS Timer.
RCL_PUBLIC RCL_WARN_UNUSED rcl_guard_condition_t * rcl_timer_get_guard_condition(const rcl_timer_t *timer)
Retrieve a guard condition used by the timer to wake the waitset when using ROSTime.
Definition: timer.c:505
struct rcl_timer_call_info_s rcl_timer_call_info_t
Structure which encapsulates timer information when called.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_clock(const rcl_timer_t *timer, rcl_clock_t **clock)
Retrieve the clock of the timer.
Definition: timer.c:233
RCL_PUBLIC RCL_WARN_UNUSED uintptr_t rcl_timer_exchange_callback_data(rcl_timer_t *timer, uintptr_t data)
Set the type erased data that the timer callback will be called with.
Definition: timer.c:432
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_call_with_info(rcl_timer_t *timer, rcl_timer_call_info_t *call_info)
Same as rcl_timer_call() except that it also retrieves the actual and expected call time.
Definition: timer.c:250
struct rcl_timer_on_reset_callback_data_s rcl_timer_on_reset_callback_data_t
Structure which encapsulates the on reset callback data.
RCL_PUBLIC RCL_WARN_UNUSED rcl_timer_t rcl_get_zero_initialized_timer(void)
Return a zero initialized timer.
Definition: timer.c:37
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_fini(rcl_timer_t *timer)
Finalize a timer.
Definition: timer.c:205
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_is_canceled(const rcl_timer_t *timer, bool *is_canceled)
Retrieve the canceled state of a timer.
Definition: timer.c:454
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_is_ready(const rcl_timer_t *timer, bool *is_ready)
Calculates whether or not the timer should be called.
Definition: timer.c:307
RCL_PUBLIC RCL_WARN_UNUSED const rcl_allocator_t * rcl_timer_get_allocator(const rcl_timer_t *timer)
Return the allocator for the timer.
Definition: timer.c:497
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
Definition: types.h:25