rcl  beta1
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 
15 #ifndef RCL__TIMER_H_
16 #define RCL__TIMER_H_
17 
18 #if __cplusplus
19 extern "C"
20 {
21 #endif
22 
23 #include <stdbool.h>
24 
25 #include "rcl/allocator.h"
26 #include "rcl/macros.h"
27 #include "rcl/time.h"
28 #include "rcl/types.h"
29 #include "rmw/rmw.h"
30 
31 struct rcl_timer_impl_t;
32 
34 typedef struct rcl_timer_t
35 {
37  struct rcl_timer_impl_t * impl;
38 } rcl_timer_t;
39 
41 
53 typedef void (* rcl_timer_callback_t)(rcl_timer_t *, uint64_t);
54 
58 rcl_timer_t
60 
62 
137 rcl_ret_t
139  rcl_timer_t * timer,
140  uint64_t period,
141  const rcl_timer_callback_t callback,
142  rcl_allocator_t allocator);
143 
145 
172 rcl_ret_t
173 rcl_timer_fini(rcl_timer_t * timer);
174 
176 
216 rcl_ret_t
217 rcl_timer_call(rcl_timer_t * timer);
218 
220 
246 rcl_ret_t
247 rcl_timer_is_ready(const rcl_timer_t * timer, bool * is_ready);
248 
250 
281 rcl_ret_t
282 rcl_timer_get_time_until_next_call(const rcl_timer_t * timer, int64_t * time_until_next_call);
283 
285 
313 rcl_ret_t
314 rcl_timer_get_time_since_last_call(const rcl_timer_t * timer, uint64_t * time_since_last_call);
315 
317 
340 rcl_ret_t
341 rcl_timer_get_period(const rcl_timer_t * timer, uint64_t * period);
342 
344 
371 rcl_ret_t
372 rcl_timer_exchange_period(const rcl_timer_t * timer, uint64_t new_period, uint64_t * old_period);
373 
375 
395 rcl_timer_get_callback(const rcl_timer_t * timer);
396 
398 
422 rcl_timer_exchange_callback(rcl_timer_t * timer, const rcl_timer_callback_t new_callback);
423 
425 
449 rcl_ret_t
450 rcl_timer_cancel(rcl_timer_t * timer);
451 
453 
478 rcl_ret_t
479 rcl_timer_is_canceled(const rcl_timer_t * timer, bool * is_canceled);
480 
482 
504 rcl_ret_t
505 rcl_timer_reset(rcl_timer_t * timer);
506 
507 #if __cplusplus
508 }
509 #endif
510 
511 #endif // RCL__TIMER_H_
rcl_ret_t rcl_timer_is_ready(const rcl_timer_t *timer, bool *is_ready)
Calculates whether or not the timer should be called.
rmw_ret_t rcl_ret_t
Definition: types.h:20
void(* rcl_timer_callback_t)(rcl_timer_t *, uint64_t)
User callback signature for timers.
Definition: timer.h:53
rcl_ret_t rcl_timer_get_time_since_last_call(const rcl_timer_t *timer, uint64_t *time_since_last_call)
Retrieve the time since the previous call to rcl_timer_call() occurred.
rcl_ret_t rcl_timer_fini(rcl_timer_t *timer)
Finalize a timer.
rcl_timer_t rcl_get_zero_initialized_timer(void)
Return a zero initialized timer.
rcl_ret_t rcl_timer_reset(rcl_timer_t *timer)
Reset a timer.
struct rcl_timer_t rcl_timer_t
Structure which encapsulates a ROS Timer.
rcl_ret_t rcl_timer_call(rcl_timer_t *timer)
Call the timer&#39;s callback and set the last call time.
rcl_timer_callback_t rcl_timer_get_callback(const rcl_timer_t *timer)
Return the current timer callback.
#define RCL_WARN_UNUSED
Ignored return values of functions with this macro will emit a warning.
Definition: macros.h:25
#define RCL_PUBLIC
Definition: visibility_control.h:48
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_ret_t rcl_timer_init(rcl_timer_t *timer, uint64_t period, const rcl_timer_callback_t callback, rcl_allocator_t allocator)
Initialize a timer.
rcl_ret_t rcl_timer_is_canceled(const rcl_timer_t *timer, bool *is_canceled)
Retrieve the canceled state of a timer.
rcl_ret_t rcl_timer_cancel(rcl_timer_t *timer)
Cancel a timer.
struct rcl_timer_impl_t * impl
Private implementation pointer.
Definition: timer.h:37
Encapsulation of an allocator.
Definition: allocator.h:40
rcl_ret_t rcl_timer_get_period(const rcl_timer_t *timer, uint64_t *period)
Retrieve the period of the timer.
Structure which encapsulates a ROS Timer.
Definition: timer.h:34
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_ret_t rcl_timer_exchange_period(const rcl_timer_t *timer, uint64_t new_period, uint64_t *old_period)
Exchange the period of the timer and return the previous period.