mark a. foltz | c28ca40 | 2018-07-19 16:11:32 -0700 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef PLATFORM_API_TIME_H_ |
| 6 | #define PLATFORM_API_TIME_H_ |
| 7 | |
Yuri Wiitala | eb8eee7 | 2019-03-26 15:52:43 -0700 | [diff] [blame] | 8 | #include <chrono> |
Yuri Wiitala | f162a61 | 2019-11-22 22:46:04 -0800 | [diff] [blame^] | 9 | |
| 10 | #include "platform/base/trivial_clock_traits.h" |
mark a. foltz | c28ca40 | 2018-07-19 16:11:32 -0700 | [diff] [blame] | 11 | |
| 12 | namespace openscreen { |
| 13 | namespace platform { |
| 14 | |
Yuri Wiitala | f162a61 | 2019-11-22 22:46:04 -0800 | [diff] [blame^] | 15 | // The "reasonably high-resolution" source of monotonic time from the embedder, |
| 16 | // exhibiting the traits described in TrivialClockTraits. This class is not |
| 17 | // instantiated. It only contains a static now() function. |
| 18 | // |
| 19 | // For example, the default platform implementation bases this on |
| 20 | // std::chrono::steady_clock or std::chrono::high_resolution_clock, but an |
| 21 | // embedder may choose to use a different source of time (e.g., the embedder's |
| 22 | // time library, a simulated time source, or a mock). |
| 23 | class Clock : public TrivialClockTraits { |
btolsch | 5292c94 | 2018-07-26 00:06:22 -0700 | [diff] [blame] | 24 | public: |
Yuri Wiitala | f162a61 | 2019-11-22 22:46:04 -0800 | [diff] [blame^] | 25 | // Returns the current time. |
Yuri Wiitala | eb8eee7 | 2019-03-26 15:52:43 -0700 | [diff] [blame] | 26 | static time_point now() noexcept; |
btolsch | 5292c94 | 2018-07-26 00:06:22 -0700 | [diff] [blame] | 27 | }; |
| 28 | |
Yuri Wiitala | eb8eee7 | 2019-03-26 15:52:43 -0700 | [diff] [blame] | 29 | // Returns the number of seconds since UNIX epoch (1 Jan 1970, midnight) |
Yuri Wiitala | f162a61 | 2019-11-22 22:46:04 -0800 | [diff] [blame^] | 30 | // according to the wall clock, which is subject to adjustments (e.g., via NTP). |
| 31 | // Note that this is NOT necessarily the same time source as Clock::now() above, |
| 32 | // and is NOT guaranteed to be monotonically non-decreasing; it is "calendar |
| 33 | // time." |
Yuri Wiitala | eb8eee7 | 2019-03-26 15:52:43 -0700 | [diff] [blame] | 34 | std::chrono::seconds GetWallTimeSinceUnixEpoch() noexcept; |
mark a. foltz | c28ca40 | 2018-07-19 16:11:32 -0700 | [diff] [blame] | 35 | |
| 36 | } // namespace platform |
| 37 | } // namespace openscreen |
| 38 | |
btolsch | a21e8ed | 2018-08-30 15:13:48 -0700 | [diff] [blame] | 39 | #endif // PLATFORM_API_TIME_H_ |