29 #ifndef INCLUDE_OLA_CLOCK_H_ 30 #define INCLUDE_OLA_CLOCK_H_ 43 static const int USEC_IN_SECONDS = 1000000;
44 static 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;
90 time_t
Seconds()
const {
return m_tv.tv_sec; }
95 int32_t
MicroSeconds()
const {
return static_cast<int32_t
>(m_tv.tv_usec); }
107 int64_t
AsInt()
const;
109 std::string ToString()
const;
117 void TimerAdd(
const struct timeval &tv1,
const struct timeval &tv2,
118 struct timeval *result)
const;
123 void TimerSub(
const struct timeval &tv1,
const struct timeval &tv2,
124 struct timeval *result)
const;
126 void Set(int64_t interval_useconds);
132 void Set(
const struct timespec &ts);
142 TimeInterval(int32_t sec, int32_t usec) : m_interval(sec, usec) {}
143 explicit TimeInterval(int64_t usec) : m_interval(usec) {}
163 bool IsZero()
const {
return !m_interval.IsSet(); }
165 void AsTimeval(
struct timeval *tv)
const { m_interval.AsTimeval(tv); }
167 time_t
Seconds()
const {
return m_interval.Seconds(); }
168 int32_t
MicroSeconds()
const {
return m_interval.MicroSeconds(); }
170 int64_t
InMilliSeconds()
const {
return m_interval.InMilliSeconds(); }
171 int64_t
AsInt()
const {
return m_interval.AsInt(); }
173 std::string ToString()
const {
return m_interval.ToString(); }
175 friend std::ostream&
operator<< (std::ostream &out,
177 return out << interval.m_interval.ToString();
195 explicit TimeStamp(
const struct timeval ×tamp) : m_tv(timestamp) {}
196 explicit TimeStamp(
const struct timespec ×tamp) : m_tv(timestamp) {}
202 TimeStamp& operator=(
const struct timeval &tv);
203 TimeStamp& operator=(
const struct timespec &ts);
206 bool operator==(
const TimeStamp &other)
const {
return m_tv == other.m_tv; }
207 bool operator!=(
const TimeStamp &other)
const {
return m_tv != other.m_tv; }
208 bool operator>(
const TimeStamp &other)
const {
return m_tv > other.m_tv; }
209 bool operator>=(
const TimeStamp &other)
const {
return m_tv >= other.m_tv; }
210 bool operator<(
const TimeStamp &other)
const {
return m_tv < other.m_tv; }
211 bool operator<=(
const TimeStamp &other)
const {
return m_tv <= other.m_tv; }
221 bool IsSet()
const {
return m_tv.IsSet(); }
223 time_t
Seconds()
const {
return m_tv.Seconds(); }
224 int32_t
MicroSeconds()
const {
return m_tv.MicroSeconds(); }
226 std::string ToString()
const {
return m_tv.ToString(); }
228 friend std::ostream&
operator<<(std::ostream &out,
230 return out << timestamp.m_tv.ToString();
261 virtual void CurrentMonotonicTime(
TimeStamp* timestamp)
const;
276 virtual void CurrentRealTime(
TimeStamp* timestamp)
const;
284 virtual void CurrentTime(
TimeStamp* timestamp)
const;
299 void AdvanceTime(int32_t sec, int32_t usec);
301 void CurrentMonotonicTime(
TimeStamp *timestamp)
const;
302 void CurrentRealTime(
TimeStamp *timestamp)
const;
303 void CurrentTime(
TimeStamp *timestamp)
const;
309 #endif // INCLUDE_OLA_CLOCK_H_ A time interval, with usecond accuracy.
Definition: Clock.h:138
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
int32_t MicroSeconds() const
Returns the microseconds portion of the BaseTimeVal.
Definition: Clock.h:95
std::ostream & operator<<(std::ostream &out, const DmxBuffer &data)
Stream operator to allow DmxBuffer to be output to stdout.
Definition: DmxBuffer.cpp:402
Used to get the current time.
Definition: Clock.h:242
int64_t InMilliSeconds() const
Returns the entire BaseTimeVal as milliseconds.
Definition: Clock.cpp:133
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Represents a point in time with microsecond accuracy.
Definition: Clock.h:191
int64_t AsInt() const
Returns the entire BaseTimeVal as microseconds.
Definition: Clock.cpp:138
time_t Seconds() const
Returns the seconds portion of the BaseTimeVal.
Definition: Clock.h:90