ROS 2 rclcpp + rcl - kilted  kilted
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 
74 typedef void (* rcl_timer_callback_t)(rcl_timer_t *, int64_t);
75 
77 RCL_PUBLIC
78 RCL_WARN_UNUSED
81 
83 
169 RCL_PUBLIC
170 RCL_WARN_UNUSED
171 rcl_ret_t
173  rcl_timer_t * timer,
174  rcl_clock_t * clock,
175  rcl_context_t * context,
176  int64_t period,
177  const rcl_timer_callback_t callback,
178  rcl_allocator_t allocator,
179  bool autostart);
180 
182 
207 RCL_PUBLIC
208 RCL_WARN_UNUSED
209 rcl_ret_t
210 rcl_timer_fini(rcl_timer_t * timer);
211 
213 
251 RCL_PUBLIC
252 RCL_WARN_UNUSED
253 rcl_ret_t
254 rcl_timer_call(rcl_timer_t * timer);
255 
257 
279 RCL_PUBLIC
280 RCL_WARN_UNUSED
281 rcl_ret_t
283 
285 
304 RCL_PUBLIC
305 RCL_WARN_UNUSED
306 rcl_ret_t
307 rcl_timer_clock(const rcl_timer_t * timer, rcl_clock_t ** clock);
308 
310 
334 RCL_PUBLIC
335 RCL_WARN_UNUSED
336 rcl_ret_t
337 rcl_timer_is_ready(const rcl_timer_t * timer, bool * is_ready);
338 
340 
370 RCL_PUBLIC
371 RCL_WARN_UNUSED
372 rcl_ret_t
373 rcl_timer_get_time_until_next_call(const rcl_timer_t * timer, int64_t * time_until_next_call);
374 
376 
394 RCL_PUBLIC
395 RCL_WARN_UNUSED
396 rcl_ret_t
397 rcl_timer_get_next_call_time(const rcl_timer_t * timer, int64_t * next_call_time);
398 
400 
426 RCL_PUBLIC
427 RCL_WARN_UNUSED
428 rcl_ret_t
429 rcl_timer_get_time_since_last_call(const rcl_timer_t * timer, int64_t * time_since_last_call);
430 
432 
453 RCL_PUBLIC
454 RCL_WARN_UNUSED
455 rcl_ret_t
456 rcl_timer_get_period(const rcl_timer_t * timer, int64_t * period);
457 
459 
484 RCL_PUBLIC
485 RCL_WARN_UNUSED
486 rcl_ret_t
487 rcl_timer_exchange_period(const rcl_timer_t * timer, int64_t new_period, int64_t * old_period);
488 
490 
507 RCL_PUBLIC
508 RCL_WARN_UNUSED
510 rcl_timer_get_callback(const rcl_timer_t * timer);
511 
513 
534 RCL_PUBLIC
535 RCL_WARN_UNUSED
538 
540 
561 RCL_PUBLIC
562 RCL_WARN_UNUSED
563 rcl_ret_t
565 
567 
590 RCL_PUBLIC
591 RCL_WARN_UNUSED
592 rcl_ret_t
593 rcl_timer_is_canceled(const rcl_timer_t * timer, bool * is_canceled);
594 
596 
616 RCL_PUBLIC
617 RCL_WARN_UNUSED
618 rcl_ret_t
620 
622 
640 RCL_PUBLIC
641 RCL_WARN_UNUSED
642 const rcl_allocator_t *
643 rcl_timer_get_allocator(const rcl_timer_t * timer);
644 
646 
659 RCL_PUBLIC
660 RCL_WARN_UNUSED
663 
665 
684 RCL_PUBLIC
685 RCL_WARN_UNUSED
686 rcl_ret_t
688  const rcl_timer_t * timer,
689  rcl_event_callback_t on_reset_callback,
690  const void * user_data);
691 
692 #ifdef __cplusplus
693 }
694 #endif
695 
696 #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:342
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.
void(* rcl_timer_callback_t)(rcl_timer_t *, int64_t)
User callback signature for timers.
Definition: timer.h:74
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:358
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:262
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_reset(rcl_timer_t *timer)
Reset a timer.
Definition: timer.c:461
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:395
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:510
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:405
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:420
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:428
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:131
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_cancel(rcl_timer_t *timer)
Cancel a timer.
Definition: timer.c:438
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:501
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:252
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:269
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:59
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_fini(rcl_timer_t *timer)
Finalize a timer.
Definition: timer.c:224
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:451
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:324
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:493
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
Definition: types.h:24