Bence Béky | bac0405 | 2022-04-07 15:44:29 -0400 | [diff] [blame] | 1 | // Copyright (c) 2012 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 QUICHE_QUIC_CORE_QUIC_CLOCK_H_ |
| 6 | #define QUICHE_QUIC_CORE_QUIC_CLOCK_H_ |
| 7 | |
| 8 | #include "quiche/quic/core/quic_time.h" |
| 9 | #include "quiche/quic/platform/api/quic_export.h" |
| 10 | |
| 11 | /* API_DESCRIPTION |
| 12 | QuicClock is used by QUIC core to get current time. Its instance is created by |
| 13 | applications and passed into QuicDispatcher and QuicConnectionHelperInterface. |
| 14 | API-DESCRIPTION */ |
| 15 | |
| 16 | namespace quic { |
| 17 | |
| 18 | // Interface for retrieving the current time. |
| 19 | class QUIC_EXPORT_PRIVATE QuicClock { |
| 20 | public: |
vasilvv | 957e552 | 2022-04-21 15:05:51 -0700 | [diff] [blame] | 21 | QuicClock() = default; |
| 22 | virtual ~QuicClock() = default; |
Bence Béky | bac0405 | 2022-04-07 15:44:29 -0400 | [diff] [blame] | 23 | |
| 24 | QuicClock(const QuicClock&) = delete; |
| 25 | QuicClock& operator=(const QuicClock&) = delete; |
| 26 | |
Bence Béky | bac0405 | 2022-04-07 15:44:29 -0400 | [diff] [blame] | 27 | // Returns the approximate current time as a QuicTime object. |
| 28 | virtual QuicTime ApproximateNow() const = 0; |
| 29 | |
| 30 | // Returns the current time as a QuicTime object. |
| 31 | // Note: this use significant resources please use only if needed. |
| 32 | virtual QuicTime Now() const = 0; |
| 33 | |
| 34 | // WallNow returns the current wall-time - a time that is consistent across |
| 35 | // different clocks. |
| 36 | virtual QuicWallTime WallNow() const = 0; |
| 37 | |
| 38 | // Converts |walltime| to a QuicTime relative to this clock's epoch. |
| 39 | virtual QuicTime ConvertWallTimeToQuicTime( |
| 40 | const QuicWallTime& walltime) const; |
| 41 | |
| 42 | protected: |
| 43 | // Creates a new QuicTime using |time_us| as the internal value. |
| 44 | QuicTime CreateTimeFromMicroseconds(uint64_t time_us) const { |
| 45 | return QuicTime(time_us); |
| 46 | } |
Bence Béky | bac0405 | 2022-04-07 15:44:29 -0400 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | } // namespace quic |
| 50 | |
| 51 | #endif // QUICHE_QUIC_CORE_QUIC_CLOCK_H_ |