Program Listing for File time.h

Return to documentation for file (include/rcl/time.h)

// Copyright 2015 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


#ifndef RCL__TIME_H_
#define RCL__TIME_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include "rcl/allocator.h"
#include "rcl/macros.h"
#include "rcl/types.h"
#include "rcl/visibility_control.h"
#include "rcutils/time.h"

#define RCL_S_TO_NS RCUTILS_S_TO_NS
#define RCL_MS_TO_NS RCUTILS_MS_TO_NS
#define RCL_US_TO_NS RCUTILS_US_TO_NS

#define RCL_NS_TO_S RCUTILS_NS_TO_S
#define RCL_NS_TO_MS RCUTILS_NS_TO_MS
#define RCL_NS_TO_US RCUTILS_NS_TO_US

typedef rcutils_time_point_value_t rcl_time_point_value_t;
typedef rcutils_duration_value_t rcl_duration_value_t;


typedef enum rcl_clock_type_e
{
  RCL_CLOCK_UNINITIALIZED = 0,
  RCL_ROS_TIME,
  RCL_SYSTEM_TIME,
  RCL_STEADY_TIME
} rcl_clock_type_t;

typedef struct rcl_duration_s
{
  rcl_duration_value_t nanoseconds;
} rcl_duration_t;

typedef enum rcl_clock_change_e
{
  RCL_ROS_TIME_NO_CHANGE = 1,
  RCL_ROS_TIME_ACTIVATED = 2,
  RCL_ROS_TIME_DEACTIVATED = 3,
  RCL_SYSTEM_TIME_NO_CHANGE = 4
} rcl_clock_change_t;

typedef struct rcl_time_jump_s
{
  rcl_clock_change_t clock_change;
  rcl_duration_t delta;
} rcl_time_jump_t;

typedef void (* rcl_jump_callback_t)(
  const rcl_time_jump_t * time_jump,
  bool before_jump,
  void * user_data);

typedef struct rcl_jump_threshold_s
{
  bool on_clock_change;
  rcl_duration_t min_forward;
  rcl_duration_t min_backward;
} rcl_jump_threshold_t;

typedef struct rcl_jump_callback_info_s
{
  rcl_jump_callback_t callback;
  rcl_jump_threshold_t threshold;
  void * user_data;
} rcl_jump_callback_info_t;

typedef struct rcl_clock_s
{
  rcl_clock_type_t type;
  rcl_jump_callback_info_t * jump_callbacks;
  size_t num_jump_callbacks;
  rcl_ret_t (* get_now)(void * data, rcl_time_point_value_t * now);
  // void (*set_now) (rcl_time_point_value_t);
  void * data;
  rcl_allocator_t allocator;
} rcl_clock_t;

typedef struct rcl_time_point_s
{
  rcl_time_point_value_t nanoseconds;
  rcl_clock_type_t clock_type;
} rcl_time_point_t;

// typedef struct rcl_rate_t
// {
//   rcl_time_point_value_t trigger_time;
//   int64_t period;
//   rcl_clock_type_t clock;;
// } rcl_rate_t;
// TODO(tfoote) integrate rate and timer implementations


RCL_PUBLIC
RCL_WARN_UNUSED
bool
rcl_clock_time_started(rcl_clock_t * clock);


RCL_PUBLIC
RCL_WARN_UNUSED
bool
rcl_clock_valid(rcl_clock_t * clock);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_clock_init(
  rcl_clock_type_t clock_type, rcl_clock_t * clock,
  rcl_allocator_t * allocator);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_clock_fini(
  rcl_clock_t * clock);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_ros_clock_init(
  rcl_clock_t * clock,
  rcl_allocator_t * allocator);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_ros_clock_fini(
  rcl_clock_t * clock);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_steady_clock_init(
  rcl_clock_t * clock,
  rcl_allocator_t * allocator);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_steady_clock_fini(
  rcl_clock_t * clock);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_system_clock_init(
  rcl_clock_t * clock,
  rcl_allocator_t * allocator);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_system_clock_fini(
  rcl_clock_t * clock);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_difference_times(
  const rcl_time_point_t * start, const rcl_time_point_t * finish, rcl_duration_t * delta);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_clock_get_now(rcl_clock_t * clock, rcl_time_point_value_t * time_point_value);



RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_enable_ros_time_override(rcl_clock_t * clock);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_disable_ros_time_override(rcl_clock_t * clock);



RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_is_enabled_ros_time_override(
  rcl_clock_t * clock, bool * is_enabled);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_set_ros_time_override(
  rcl_clock_t * clock, rcl_time_point_value_t time_value);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_clock_add_jump_callback(
  rcl_clock_t * clock, rcl_jump_threshold_t threshold, rcl_jump_callback_t callback,
  void * user_data);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_clock_remove_jump_callback(
  rcl_clock_t * clock, rcl_jump_callback_t callback, void * user_data);

#ifdef __cplusplus
}
#endif

#endif  // RCL__TIME_H_