29#ifndef INCLUDE_OLA_CLOCK_H_
30#define INCLUDE_OLA_CLOCK_H_
43static const int USEC_IN_SECONDS = 1000000;
44static const int ONE_THOUSAND = 1000;
56 explicit BaseTimeVal(
const struct timeval ×tamp) { m_tv = timestamp; }
57 explicit BaseTimeVal(
const struct timespec ×tamp) { Set(timestamp); }
58 explicit BaseTimeVal(int64_t interval_useconds) { Set(interval_useconds); }
84 void AsTimeval(
struct timeval *tv)
const;
87 time_t Seconds()
const {
return m_tv.tv_sec; }
89 int32_t MicroSeconds()
const {
return static_cast<int32_t
>(m_tv.tv_usec); }
92 int64_t InMilliSeconds()
const;
95 int64_t AsInt()
const;
97 std::string ToString()
const;
105 void TimerAdd(
const struct timeval &tv1,
const struct timeval &tv2,
106 struct timeval *result)
const;
111 void TimerSub(
const struct timeval &tv1,
const struct timeval &tv2,
112 struct timeval *result)
const;
114 void Set(int64_t interval_useconds);
120 void Set(
const struct timespec &ts);
130 TimeInterval(int32_t sec, int32_t usec) : m_interval(sec, usec) {}
131 explicit TimeInterval(int64_t usec) : m_interval(usec) {}
151 bool IsZero()
const {
return !m_interval.IsSet(); }
153 void AsTimeval(
struct timeval *tv)
const { m_interval.AsTimeval(tv); }
155 time_t Seconds()
const {
return m_interval.Seconds(); }
156 int32_t MicroSeconds()
const {
return m_interval.MicroSeconds(); }
158 int64_t InMilliSeconds()
const {
return m_interval.InMilliSeconds(); }
159 int64_t AsInt()
const {
return m_interval.AsInt(); }
161 std::string ToString()
const {
return m_interval.ToString(); }
163 friend std::ostream& operator<< (std::ostream &out,
165 return out << interval.m_interval.ToString();
183 explicit TimeStamp(
const struct timeval ×tamp) : m_tv(timestamp) {}
184 explicit TimeStamp(
const struct timespec ×tamp) : m_tv(timestamp) {}
190 TimeStamp& operator=(
const struct timeval &tv);
191 TimeStamp& operator=(
const struct timespec &ts);
194 bool operator==(
const TimeStamp &other)
const {
return m_tv == other.m_tv; }
195 bool operator!=(
const TimeStamp &other)
const {
return m_tv != other.m_tv; }
196 bool operator>(
const TimeStamp &other)
const {
return m_tv > other.m_tv; }
197 bool operator>=(
const TimeStamp &other)
const {
return m_tv >= other.m_tv; }
198 bool operator<(
const TimeStamp &other)
const {
return m_tv < other.m_tv; }
199 bool operator<=(
const TimeStamp &other)
const {
return m_tv <= other.m_tv; }
209 bool IsSet()
const {
return m_tv.IsSet(); }
211 time_t Seconds()
const {
return m_tv.Seconds(); }
212 int32_t MicroSeconds()
const {
return m_tv.MicroSeconds(); }
214 std::string ToString()
const {
return m_tv.ToString(); }
216 friend std::ostream& operator<<(std::ostream &out,
218 return out << timestamp.m_tv.ToString();
276 const Clock &operator=(
const Clock &) =
delete;
288 void AdvanceTime(int32_t sec, int32_t usec);
Used to get the current time.
Definition Clock.h:230
virtual void CurrentMonotonicTime(TimeStamp *timestamp) const
Sets timestamp to the current monotonic time.
Definition Clock.cpp:270
virtual void CurrentTime(TimeStamp *timestamp) const
Wrapper around CurrentRealime.
Definition Clock.cpp:286
virtual void CurrentRealTime(TimeStamp *timestamp) const
Sets timestamp to the current real time.
Definition Clock.cpp:280
void CurrentMonotonicTime(TimeStamp *timestamp) const
Sets timestamp to the current monotonic time.
Definition Clock.cpp:299
void CurrentRealTime(TimeStamp *timestamp) const
Sets timestamp to the current real time.
Definition Clock.cpp:311
void CurrentTime(TimeStamp *timestamp) const
Wrapper around CurrentRealime.
Definition Clock.cpp:318
The namespace containing all OLA symbols.
Definition Credentials.cpp:44