/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2022,  Regents of the University of California,
 *                           Arizona Board of Regents,
 *                           Colorado State University,
 *                           University Pierre & Marie Curie, Sorbonne University,
 *                           Washington University in St. Louis,
 *                           Beijing Institute of Technology,
 *                           The University of Memphis.
 *
 * This file is part of NFD (Named Data Networking Forwarding Daemon).
 * See AUTHORS.md for complete list of NFD authors and contributors.
 *
 * NFD is free software: you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef NFD_TESTS_DAEMON_LIMITED_IO_HPP
#define NFD_TESTS_DAEMON_LIMITED_IO_HPP

#include "tests/daemon/global-io-fixture.hpp"

#include <exception>

namespace nfd {
namespace tests {

/** \brief Provides IO operations limit and/or time limit for unit testing.
 *
 *  \warning LimitedIo is incompatible with RibIoFixture
 */
class LimitedIo : noncopyable
{
public:
  explicit
  LimitedIo(GlobalIoTimeFixture* fixture = nullptr);

  /// indicates why run() returns
  enum StopReason {
    /// g_io.run() returns normally because there's no work to do
    NO_WORK,
    /// .afterOp() has been invoked nOpsLimit times
    EXCEED_OPS,
    /// nTimeLimit has elapsed
    EXCEED_TIME,
    /// an exception is thrown
    EXCEPTION
  };

  /** \brief g_io.run() with operation count and/or time limit
   *  \param nOpsLimit operation count limit, pass UNLIMITED_OPS for no limit
   *  \param timeLimit time limit, pass UNLIMITED_TIME for no limit
   *  \param tick if this LimitedIo is constructed with GlobalIoTimeFixture,
   *              this is passed to .advanceClocks(), otherwise ignored
   */
  StopReason
  run(int nOpsLimit, time::nanoseconds timeLimit, time::nanoseconds tick = 1_ms);

  /// count an operation
  void
  afterOp();

  /** \brief defer for specified duration
   *
   *  equivalent to .run(UNLIMITED_OPS, d)
   */
  void
  defer(time::nanoseconds d)
  {
    this->run(UNLIMITED_OPS, d);
  }

  std::exception_ptr
  getLastException() const
  {
    return m_lastException;
  }

private:
  /** \brief an exception to stop IO operation
   */
  class StopException : public std::exception
  {
  };

  void
  afterTimeout();

public:
  static constexpr int UNLIMITED_OPS = std::numeric_limits<int>::max();
  static constexpr time::nanoseconds UNLIMITED_TIME = time::nanoseconds::min();

private:
  GlobalIoTimeFixture* m_fixture;
  StopReason m_reason;
  int m_nOpsRemaining = 0;
  scheduler::EventId m_timeout;
  std::exception_ptr m_lastException;
  bool m_isRunning = false;
};

} // namespace tests
} // namespace nfd

#endif // NFD_TESTS_DAEMON_LIMITED_IO_HPP
