rcl  master
C API providing common ROS client library functionality.
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/guard_condition.h"
30 #include "rcl/macros.h"
31 #include "rcl/time.h"
32 #include "rcl/types.h"
33 #include "rmw/rmw.h"
34 
35 struct rcl_clock_t;
36 struct rcl_timer_impl_t;
37 
39 typedef struct rcl_timer_t
40 {
42  struct rcl_timer_impl_t * impl;
43 } rcl_timer_t;
44 
46 
58 typedef void (* rcl_timer_callback_t)(rcl_timer_t *, int64_t);
59 
61 RCL_PUBLIC
62 RCL_WARN_UNUSED
65 
67 
152 RCL_PUBLIC
153 RCL_WARN_UNUSED
154 rcl_ret_t
156  rcl_timer_t * timer,
157  rcl_clock_t * clock,
158  rcl_context_t * context,
159  int64_t period,
160  const rcl_timer_callback_t callback,
161  rcl_allocator_t allocator);
162 
164 
189 RCL_PUBLIC
190 RCL_WARN_UNUSED
191 rcl_ret_t
192 rcl_timer_fini(rcl_timer_t * timer);
193 
195 
233 RCL_PUBLIC
234 RCL_WARN_UNUSED
235 rcl_ret_t
236 rcl_timer_call(rcl_timer_t * timer);
237 
239 
259 RCL_PUBLIC
260 RCL_WARN_UNUSED
261 rcl_ret_t
262 rcl_timer_clock(rcl_timer_t * timer, rcl_clock_t ** clock);
263 
265 
289 RCL_PUBLIC
290 RCL_WARN_UNUSED
291 rcl_ret_t
292 rcl_timer_is_ready(const rcl_timer_t * timer, bool * is_ready);
293 
295 
324 RCL_PUBLIC
325 RCL_WARN_UNUSED
326 rcl_ret_t
327 rcl_timer_get_time_until_next_call(const rcl_timer_t * timer, int64_t * time_until_next_call);
328 
330 
356 RCL_PUBLIC
357 RCL_WARN_UNUSED
358 rcl_ret_t
359 rcl_timer_get_time_since_last_call(const rcl_timer_t * timer, int64_t * time_since_last_call);
360 
362 
382 RCL_PUBLIC
383 RCL_WARN_UNUSED
384 rcl_ret_t
385 rcl_timer_get_period(const rcl_timer_t * timer, int64_t * period);
386 
388 
412 RCL_PUBLIC
413 RCL_WARN_UNUSED
414 rcl_ret_t
415 rcl_timer_exchange_period(const rcl_timer_t * timer, int64_t new_period, int64_t * old_period);
416 
418 
435 RCL_PUBLIC
436 RCL_WARN_UNUSED
438 rcl_timer_get_callback(const rcl_timer_t * timer);
439 
441 
462 RCL_PUBLIC
463 RCL_WARN_UNUSED
466 
468 
490 RCL_PUBLIC
491 RCL_WARN_UNUSED
492 rcl_ret_t
494 
496 
518 RCL_PUBLIC
519 RCL_WARN_UNUSED
520 rcl_ret_t
521 rcl_timer_is_canceled(const rcl_timer_t * timer, bool * is_canceled);
522 
524 
544 RCL_PUBLIC
545 RCL_WARN_UNUSED
546 rcl_ret_t
548 
550 
568 RCL_PUBLIC
569 RCL_WARN_UNUSED
570 const rcl_allocator_t *
571 rcl_timer_get_allocator(const rcl_timer_t * timer);
572 
574 
587 RCL_PUBLIC
588 RCL_WARN_UNUSED
591 
592 #ifdef __cplusplus
593 }
594 #endif
595 
596 #endif // RCL__TIMER_H_
rcl_timer_t
Structure which encapsulates a ROS Timer.
Definition: timer.h:39
rcl_timer_get_guard_condition
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.
rcl_timer_t::impl
struct rcl_timer_impl_t * impl
Private implementation pointer.
Definition: timer.h:42
rcl_timer_is_canceled
rcl_ret_t rcl_timer_is_canceled(const rcl_timer_t *timer, bool *is_canceled)
Retrieve the canceled state of a timer.
rcl_timer_get_allocator
const rcl_allocator_t * rcl_timer_get_allocator(const rcl_timer_t *timer)
Return the allocator for the timer.
types.h
rmw.h
rcl_ret_t
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
Definition: types.h:23
rcl_timer_call
rcl_ret_t rcl_timer_call(rcl_timer_t *timer)
Call the timer's callback and set the last call time.
rcl_timer_cancel
rcl_ret_t rcl_timer_cancel(rcl_timer_t *timer)
Cancel a timer.
rcl_timer_get_time_until_next_call
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.
rcl_guard_condition_t
Handle for a rcl guard condition.
Definition: guard_condition.h:35
rcl_timer_fini
rcl_ret_t rcl_timer_fini(rcl_timer_t *timer)
Finalize a timer.
rcl_timer_get_period
rcl_ret_t rcl_timer_get_period(const rcl_timer_t *timer, int64_t *period)
Retrieve the period of the timer.
guard_condition.h
rcl_timer_exchange_callback
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.
rcl_timer_init
rcl_ret_t rcl_timer_init(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)
Initialize a timer.
time.h
rcl_timer_callback_t
void(* rcl_timer_callback_t)(rcl_timer_t *, int64_t)
User callback signature for timers.
Definition: timer.h:58
rcl_timer_exchange_period
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.
rcl_timer_get_callback
rcl_timer_callback_t rcl_timer_get_callback(const rcl_timer_t *timer)
Return the current timer callback.
rcl_timer_t
struct rcl_timer_t rcl_timer_t
Structure which encapsulates a ROS Timer.
rcl_timer_get_time_since_last_call
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_clock_t
Encapsulation of a time source.
Definition: time.h:137
rcutils_allocator_t
allocator.h
rcl_context_t
Encapsulates the non-global state of an init/shutdown cycle.
Definition: context.h:113
rcl_timer_reset
rcl_ret_t rcl_timer_reset(rcl_timer_t *timer)
Reset a timer.
context.h
rcl_timer_clock
rcl_ret_t rcl_timer_clock(rcl_timer_t *timer, rcl_clock_t **clock)
Retrieve the clock of the timer.
rcl_get_zero_initialized_timer
rcl_timer_t rcl_get_zero_initialized_timer(void)
Return a zero initialized timer.
rcl_timer_is_ready
rcl_ret_t rcl_timer_is_ready(const rcl_timer_t *timer, bool *is_ready)
Calculates whether or not the timer should be called.