This refactoring takes a careful approach to avoid rushing the change: * stub headers are left in all the old locations of webrtc/base * existing GN targets are kept and now just forward to the moved ones using public_deps. The only exception to the above is the base_java target and its .java files, which were moved to webrtc/rtc_base right away since it's not possible to use public_deps for android_library. To avoid breaking builds, a temporary Dummy.java file was added to the new intermediate target in webrtc/rtc_base:base_java as well to avoid hitting a GN assert in the android_library template. The above approach should make the transition smooth without breaking downstream. A helper script was created (https://codereview.webrtc.org/2879203002/) and was run like this: stub-headers.py -s webrtc/base -d webrtc/rtc_base -i 7634 stub-headers.py -s webrtc/base/numerics -d webrtc/rtc_base/numerics -i 7634 Fixed invalid header guards in the following files: webrtc/base/base64.h webrtc/base/cryptstring.h webrtc/base/event.h webrtc/base/flags.h webrtc/base/httpbase.h webrtc/base/httpcommon-inl.h webrtc/base/httpcommon.h webrtc/base/httpserver.h webrtc/base/logsinks.h webrtc/base/macutils.h webrtc/base/nattypes.h webrtc/base/openssladapter.h webrtc/base/opensslstreamadapter.h webrtc/base/pathutils.h webrtc/base/physicalsocketserver.h webrtc/base/proxyinfo.h webrtc/base/sigslot.h webrtc/base/sigslotrepeater.h webrtc/base/socket.h webrtc/base/socketaddresspair.h webrtc/base/socketfactory.h webrtc/base/stringutils.h webrtc/base/testbase64.h webrtc/base/testutils.h webrtc/base/transformadapter.h webrtc/base/win32filesystem.h Added new header guards to: sslroots.h testbase64.h BUG=webrtc:7634 NOTRY=True NOPRESUBMIT=True R=kwiberg@webrtc.org Review-Url: https://codereview.webrtc.org/2877023002 . Cr-Commit-Position: refs/heads/master@{#18816}
130 lines
4.2 KiB
C++
130 lines
4.2 KiB
C++
/*
|
|
* Copyright 2005 The WebRTC Project Authors. All rights reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#ifndef WEBRTC_RTC_BASE_TIMEUTILS_H_
|
|
#define WEBRTC_RTC_BASE_TIMEUTILS_H_
|
|
|
|
#include <stdint.h>
|
|
#include <time.h>
|
|
|
|
#include <ctime>
|
|
|
|
namespace rtc {
|
|
|
|
static const int64_t kNumMillisecsPerSec = INT64_C(1000);
|
|
static const int64_t kNumMicrosecsPerSec = INT64_C(1000000);
|
|
static const int64_t kNumNanosecsPerSec = INT64_C(1000000000);
|
|
|
|
static const int64_t kNumMicrosecsPerMillisec =
|
|
kNumMicrosecsPerSec / kNumMillisecsPerSec;
|
|
static const int64_t kNumNanosecsPerMillisec =
|
|
kNumNanosecsPerSec / kNumMillisecsPerSec;
|
|
static const int64_t kNumNanosecsPerMicrosec =
|
|
kNumNanosecsPerSec / kNumMicrosecsPerSec;
|
|
|
|
// TODO(honghaiz): Define a type for the time value specifically.
|
|
|
|
class ClockInterface {
|
|
public:
|
|
virtual ~ClockInterface() {}
|
|
virtual int64_t TimeNanos() const = 0;
|
|
};
|
|
|
|
// Sets the global source of time. This is useful mainly for unit tests.
|
|
//
|
|
// Returns the previously set ClockInterface, or nullptr if none is set.
|
|
//
|
|
// Does not transfer ownership of the clock. SetClockForTesting(nullptr)
|
|
// should be called before the ClockInterface is deleted.
|
|
//
|
|
// This method is not thread-safe; it should only be used when no other thread
|
|
// is running (for example, at the start/end of a unit test, or start/end of
|
|
// main()).
|
|
//
|
|
// TODO(deadbeef): Instead of having functions that access this global
|
|
// ClockInterface, we may want to pass the ClockInterface into everything
|
|
// that uses it, eliminating the need for a global variable and this function.
|
|
ClockInterface* SetClockForTesting(ClockInterface* clock);
|
|
|
|
// Returns previously set clock, or nullptr if no custom clock is being used.
|
|
ClockInterface* GetClockForTesting();
|
|
|
|
// Returns the actual system time, even if a clock is set for testing.
|
|
// Useful for timeouts while using a test clock, or for logging.
|
|
int64_t SystemTimeNanos();
|
|
int64_t SystemTimeMillis();
|
|
|
|
// Returns the current time in milliseconds in 32 bits.
|
|
uint32_t Time32();
|
|
|
|
// Returns the current time in milliseconds in 64 bits.
|
|
int64_t TimeMillis();
|
|
// Deprecated. Do not use this in any new code.
|
|
inline int64_t Time() {
|
|
return TimeMillis();
|
|
}
|
|
|
|
// Returns the current time in microseconds.
|
|
int64_t TimeMicros();
|
|
|
|
// Returns the current time in nanoseconds.
|
|
int64_t TimeNanos();
|
|
|
|
|
|
// Returns a future timestamp, 'elapsed' milliseconds from now.
|
|
int64_t TimeAfter(int64_t elapsed);
|
|
|
|
// Number of milliseconds that would elapse between 'earlier' and 'later'
|
|
// timestamps. The value is negative if 'later' occurs before 'earlier'.
|
|
int64_t TimeDiff(int64_t later, int64_t earlier);
|
|
int32_t TimeDiff32(uint32_t later, uint32_t earlier);
|
|
|
|
// The number of milliseconds that have elapsed since 'earlier'.
|
|
inline int64_t TimeSince(int64_t earlier) {
|
|
return TimeMillis() - earlier;
|
|
}
|
|
|
|
// The number of milliseconds that will elapse between now and 'later'.
|
|
inline int64_t TimeUntil(int64_t later) {
|
|
return later - TimeMillis();
|
|
}
|
|
|
|
class TimestampWrapAroundHandler {
|
|
public:
|
|
TimestampWrapAroundHandler();
|
|
|
|
int64_t Unwrap(uint32_t ts);
|
|
|
|
private:
|
|
uint32_t last_ts_;
|
|
int64_t num_wrap_;
|
|
};
|
|
|
|
// Convert from std::tm, which is relative to 1900-01-01 00:00 to number of
|
|
// seconds from 1970-01-01 00:00 ("epoch"). Don't return time_t since that
|
|
// is still 32 bits on many systems.
|
|
int64_t TmToSeconds(const std::tm& tm);
|
|
|
|
// Return the number of microseconds since January 1, 1970, UTC.
|
|
// Useful mainly when producing logs to be correlated with other
|
|
// devices, and when the devices in question all have properly
|
|
// synchronized clocks.
|
|
//
|
|
// Note that this function obeys the system's idea about what the time
|
|
// is. It is not guaranteed to be monotonic; it will jump in case the
|
|
// system time is changed, e.g., by some other process calling
|
|
// settimeofday. Always use rtc::TimeMicros(), not this function, for
|
|
// measuring time intervals and timeouts.
|
|
int64_t TimeUTCMicros();
|
|
|
|
} // namespace rtc
|
|
|
|
#endif // WEBRTC_RTC_BASE_TIMEUTILS_H_
|