| // Copyright 2017 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef COBALT_SRC_PUBLIC_LIB_CLOCK_INTERFACES_H_ |
| #define COBALT_SRC_PUBLIC_LIB_CLOCK_INTERFACES_H_ |
| |
| #include <chrono> |
| #include <iomanip> |
| #include <optional> |
| #include <queue> |
| #include <sstream> |
| #include <string> |
| |
| namespace cobalt::util { |
| |
| // Allows us to mock out a clock for tests. |
| class SystemClockInterface { |
| public: |
| virtual ~SystemClockInterface() = default; |
| |
| virtual std::chrono::system_clock::time_point now() = 0; |
| }; |
| |
| // Allows us to mock out a clock for tests. |
| class SteadyClockInterface { |
| public: |
| virtual ~SteadyClockInterface() = default; |
| |
| virtual std::chrono::steady_clock::time_point now() = 0; |
| }; |
| |
| // An abstract interface to a clock that refuses to provide the time if a quality condition is not |
| // satisfied; for example, if the clock has not been initialized from a trustworthy source. |
| class ValidatedClockInterface { |
| public: |
| virtual ~ValidatedClockInterface() = default; |
| |
| // Returns the current time if an accurate clock is avaliable or nullopt otherwise. |
| virtual std::optional<std::chrono::system_clock::time_point> now() = 0; |
| }; |
| |
| } // namespace cobalt::util |
| |
| #endif // COBALT_SRC_PUBLIC_LIB_CLOCK_INTERFACES_H_ |