ROS 2 rclcpp + rcl - lyrical  lyrical
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 
27 #include "rcl/allocator.h"
28 #include "rcl/context.h"
29 #include "rcl/event_callback.h"
30 #include "rcl/guard_condition.h"
31 #include "rcl/macros.h"
32 #include "rcl/time.h"
33 #include "rcl/types.h"
34 #include "rcutils/logging_macros.h"
35 #include "rmw/rmw.h"
36 
37 typedef struct rcl_timer_impl_s rcl_timer_impl_t;
38 
40 typedef struct rcl_timer_s
41 {
45 
48 {
49  rcl_event_callback_t on_reset_callback;
50  const void * user_data;
51  size_t reset_counter;
53 
55 typedef struct rcl_timer_call_info_s
56 {
57  rcl_time_point_value_t expected_call_time;
58  rcl_time_point_value_t actual_call_time;
60 
62 
76 typedef void (* rcl_timer_callback_t)(rcl_timer_t *, int64_t, uintptr_t);
77 
79 RCL_PUBLIC
80 RCL_WARN_UNUSED
83 
85 
171 RCL_PUBLIC
172 RCL_WARN_UNUSED
173 rcl_ret_t
175  rcl_timer_t * timer,
176  rcl_clock_t * clock,
177  rcl_context_t * context,
178  int64_t period,
179  const rcl_timer_callback_t callback,
180  rcl_allocator_t allocator,
181  bool autostart);
182 
184 
209 RCL_PUBLIC
210 RCL_WARN_UNUSED
211 rcl_ret_t
212 rcl_timer_fini(rcl_timer_t * timer);
213 
215 
253 RCL_PUBLIC
254 RCL_WARN_UNUSED
255 rcl_ret_t
256 rcl_timer_call(rcl_timer_t * timer);
257 
259 
281 RCL_PUBLIC
282 RCL_WARN_UNUSED
283 rcl_ret_t
285 
287 
306 RCL_PUBLIC
307 RCL_WARN_UNUSED
308 rcl_ret_t
309 rcl_timer_clock(const rcl_timer_t * timer, rcl_clock_t ** clock);
310 
312 
336 RCL_PUBLIC
337 RCL_WARN_UNUSED
338 rcl_ret_t
339 rcl_timer_is_ready(const rcl_timer_t * timer, bool * is_ready);
340 
342 
372 RCL_PUBLIC
373 RCL_WARN_UNUSED
374 rcl_ret_t
375 rcl_timer_get_time_until_next_call(const rcl_timer_t * timer, int64_t * time_until_next_call);
376 
378 
396 RCL_PUBLIC
397 RCL_WARN_UNUSED
398 rcl_ret_t
399 rcl_timer_get_next_call_time(const rcl_timer_t * timer, int64_t * next_call_time);
400 
402 
428 RCL_PUBLIC
429 RCL_WARN_UNUSED
430 rcl_ret_t
431 rcl_timer_get_time_since_last_call(const rcl_timer_t * timer, int64_t * time_since_last_call);
432 
434 
455 RCL_PUBLIC
456 RCL_WARN_UNUSED
457 rcl_ret_t
458 rcl_timer_get_period(const rcl_timer_t * timer, int64_t * period);
459 
461 
486 RCL_PUBLIC
487 RCL_WARN_UNUSED
488 rcl_ret_t
489 rcl_timer_exchange_period(const rcl_timer_t * timer, int64_t new_period, int64_t * old_period);
490 
492 
509 RCL_PUBLIC
510 RCL_WARN_UNUSED
512 rcl_timer_get_callback(const rcl_timer_t * timer);
513 
515 
532 RCL_PUBLIC
533 RCL_WARN_UNUSED
534 uintptr_t
536 
538 
559 RCL_PUBLIC
560 RCL_WARN_UNUSED
563 
565 
586 RCL_PUBLIC
587 RCL_WARN_UNUSED
588 uintptr_t
589 rcl_timer_exchange_callback_data(rcl_timer_t * timer, uintptr_t data);
590 
591 
593 
614 RCL_PUBLIC
615 RCL_WARN_UNUSED
616 rcl_ret_t
618 
620 
643 RCL_PUBLIC
644 RCL_WARN_UNUSED
645 rcl_ret_t
646 rcl_timer_is_canceled(const rcl_timer_t * timer, bool * is_canceled);
647 
649 
669 RCL_PUBLIC
670 RCL_WARN_UNUSED
671 rcl_ret_t
673 
675 
693 RCL_PUBLIC
694 RCL_WARN_UNUSED
695 const rcl_allocator_t *
696 rcl_timer_get_allocator(const rcl_timer_t * timer);
697 
699 
712 RCL_PUBLIC
713 RCL_WARN_UNUSED
716 
718 
737 RCL_PUBLIC
738 RCL_WARN_UNUSED
739 rcl_ret_t
741  const rcl_timer_t * timer,
742  rcl_event_callback_t on_reset_callback,
743  const void * user_data);
744 
745 #ifdef __cplusplus
746 }
747 #endif
748 
749 #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:138
Encapsulates the non-global state of an init/shutdown cycle.
Definition: context.h:114
Handle for a rcl guard condition.
Structure which encapsulates timer information when called.
Definition: timer.h:56
Structure which encapsulates the on reset callback data.
Definition: timer.h:48
Structure which encapsulates a ROS Timer.
Definition: timer.h:41
rcl_timer_impl_t * impl
Private implementation pointer.
Definition: timer.h:43
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:46
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:321
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:337
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:238
void(* rcl_timer_callback_t)(rcl_timer_t *, int64_t, uintptr_t)
User callback signature for timers.
Definition: timer.h:76
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_reset(rcl_timer_t *timer)
Reset a timer.
Definition: timer.c:459
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:376
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:509
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:386
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:401
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:417
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:104
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_cancel(rcl_timer_t *timer)
Cancel a timer.
Definition: timer.c:436
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:409
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:500
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:228
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:427
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:245
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:32
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_fini(rcl_timer_t *timer)
Finalize a timer.
Definition: timer.c:200
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:449
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:302
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:492
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
Definition: types.h:24