2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 #ifndef __WVTIMEUTILS_H
6 #define __WVTIMEUTILS_H
11 int gettimeofday(struct timeval
*tv
, struct timezone
*tz
);
16 /** Based on (and interchangeable with) struct timeval. */
17 class WvTime
: public timeval
21 { } // WARNING: leaves members uninitialized, like timeval would do!
23 { tv_sec
= long(t
/1000000L); tv_usec
= long(t
%1000000L); }
24 WvTime(time_t sec
, time_t usec
)
25 { tv_sec
= long(sec
); tv_usec
= long(usec
); }
26 WvTime(const struct timeval
&tv
)
27 { tv_sec
= tv
.tv_sec
; tv_usec
= tv
.tv_usec
; }
28 WvTime(const WvTime
&tv
)
29 { tv_sec
= tv
.tv_sec
; tv_usec
= tv
.tv_usec
; }
31 operator long long() const
32 { return ((long long)tv_sec
)*1000000LL + tv_usec
; }
35 static const WvTime
wvtime_zero(0, 0);
37 /** Returns the number of milliseconds between times a and b (ie a-b).
38 * Value returned is not rounded, it is chopped via integer division
39 * For example: if the result of the subtraction is 0.9, the returned
40 * value is 0 if the result is -0.9, the result is also 0.
42 time_t msecdiff(const WvTime
&a
, const WvTime
&b
);
44 /** Returns the current time of day. */
47 /** Adds the specified number of milliseconds to a time value. */
48 WvTime
msecadd(const WvTime
&a
, time_t msec
);
50 /** Returns the timeval difference between two timevals (ie a-b). */
51 WvTime
tvdiff(const WvTime
&a
, const WvTime
&b
);
53 /** Normalizes the time value.
54 * This means that any two 'equally valued' timevals will be converted
55 * so that the seconds and the microseconds are the same in each timeval.
57 inline void normalize(WvTime
&tv
)
59 tv
.tv_sec
+= tv
.tv_usec
< 0 ? (tv
.tv_usec
/1000000)-1 : tv
.tv_usec
/1000000;
60 tv
.tv_usec
%= 1000000;
61 tv
.tv_usec
+= tv
.tv_usec
< 0 ? 1000000 : 0;
64 // Stepped time functions. Used to synchronize wvstreams.
65 const WvTime
&wvstime();
68 // This function is just like wvstime_sync(), but will never make the
70 void wvstime_sync_forward();
72 // This sets the time returned by wvstime() to the specified value. To
73 // be used for unit testing.
74 void wvstime_set(const WvTime
&);
77 * Delay for a requested number of milliseconds.
79 void wvdelay(int msec_delay
);
81 #endif // __WVTIMEUTILS_H