Skip to content

iceoryx_hoofs/cxx/deadline_timer.hpp🔗

Namespaces🔗

Name
iox
building block to easily create free function for logging in a library context
iox::cxx

Classes🔗

Name
class iox::cxx::DeadlineTimer
This offers the deadline timer functionality. It has user convenient methods to reset the timer [by default it uses the intialized duration], reset timer to a customized duration, check if the timer is active and user can also get to know about the remaining time before the timer goes off.

Source code🔗

// Copyright (c) 2021 by Robert Bosch GmbH. 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.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_HOOFS_CXX_DEADLINETIMER_HPP
#define IOX_HOOFS_CXX_DEADLINETIMER_HPP

#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iceoryx_hoofs/platform/signal.hpp"

#include <chrono>
#include <cstdint>

namespace iox
{
namespace cxx
{
class DeadlineTimer
{
  public:
    explicit DeadlineTimer(const iox::units::Duration timeToWait) noexcept;

    bool hasExpired() const noexcept;

    void reset() noexcept;

    void reset(const iox::units::Duration timeToWait) noexcept;

    iox::units::Duration remainingTime() const noexcept;

  private:
    static iox::units::Duration getCurrentMonotonicTime() noexcept;

    iox::units::Duration m_timeToWait;
    iox::units::Duration m_endTime;
};

} // namespace cxx
} // namespace iox


#endif // IOX_HOOFS_CXX_DEADLINETIMER_HPP

Updated on 2 April 2022 at 16:37:47 CEST