Program Listing for File time_controller_clock.hpp

Return to documentation for file (/tmp/ws/src/rosbag2/rosbag2_cpp/include/rosbag2_cpp/clocks/time_controller_clock.hpp)

// Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// 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 ROSBAG2_CPP__CLOCKS__TIME_CONTROLLER_CLOCK_HPP_
#define ROSBAG2_CPP__CLOCKS__TIME_CONTROLLER_CLOCK_HPP_

#include <chrono>
#include <memory>

#include "rosbag2_cpp/clocks/player_clock.hpp"

namespace rosbag2_cpp
{

class TimeControllerClockImpl;
class TimeControllerClock : public PlayerClock
{
public:
  ROSBAG2_CPP_PUBLIC
  TimeControllerClock(
    rcutils_time_point_value_t starting_time,
    NowFunction now_fn = std::chrono::steady_clock::now,
    std::chrono::milliseconds sleep_time_while_paused = std::chrono::milliseconds{100},
    bool start_paused = false);

  ROSBAG2_CPP_PUBLIC
  virtual ~TimeControllerClock();

  ROSBAG2_CPP_PUBLIC
  rcutils_time_point_value_t now() const override;

  ROSBAG2_CPP_PUBLIC
  bool sleep_until(rcutils_time_point_value_t until) override;

  ROSBAG2_CPP_PUBLIC
  bool sleep_until(rclcpp::Time until) override;

  ROSBAG2_CPP_PUBLIC
  bool set_rate(double rate) override;

  ROSBAG2_CPP_PUBLIC
  double get_rate() const override;

  ROSBAG2_CPP_PUBLIC
  void pause() override;

  ROSBAG2_CPP_PUBLIC
  void resume() override;

  ROSBAG2_CPP_PUBLIC
  bool is_paused() const override;

  ROSBAG2_CPP_PUBLIC
  void jump(rcutils_time_point_value_t ros_time) override;

  ROSBAG2_CPP_PUBLIC
  void jump(rclcpp::Time ros_time) override;

  ROSBAG2_CPP_PUBLIC
  rclcpp::JumpHandler::SharedPtr create_jump_callback(
    rclcpp::JumpHandler::pre_callback_t pre_callback,
    rclcpp::JumpHandler::post_callback_t post_callback,
    const rcl_jump_threshold_t & threshold) override;

  ROSBAG2_CPP_PUBLIC
  std::chrono::steady_clock::time_point
  ros_to_steady(rcutils_time_point_value_t ros_time) const;

private:
  std::unique_ptr<TimeControllerClockImpl> impl_;
};


}  // namespace rosbag2_cpp

#endif  // ROSBAG2_CPP__CLOCKS__TIME_CONTROLLER_CLOCK_HPP_