WvStreams
debian/libwvstreams-dev/usr/include/wvstreams/wvtimeutils.h
1/* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 */
5#ifndef __WVTIMEUTILS_H
6#define __WVTIMEUTILS_H
7
8#ifdef _WIN32
9#include "winsock2.h"
10#include <time.h>
11int gettimeofday(struct timeval *tv, struct timezone *tz);
12#else
13#include <sys/time.h>
14#endif
15
17class WvTime : public timeval
18{
19public:
20 WvTime()
21 { } // WARNING: leaves members uninitialized, like timeval would do!
22 WvTime(long long t)
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; }
30
31 operator long long() const
32 { return ((long long)tv_sec)*1000000LL + tv_usec; }
33};
34
35static const WvTime wvtime_zero(0, 0);
36
42time_t msecdiff(const WvTime &a, const WvTime &b);
43
45WvTime wvtime();
46
48WvTime msecadd(const WvTime &a, time_t msec);
49
51WvTime tvdiff(const WvTime &a, const WvTime &b);
52
57inline void normalize(WvTime &tv)
58{
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;
62}
63
64// Stepped time functions. Used to synchronize wvstreams.
65const WvTime &wvstime();
66void wvstime_sync();
67
68// This function is just like wvstime_sync(), but will never make the
69// time go backward.
70void wvstime_sync_forward();
71
72// This sets the time returned by wvstime() to the specified value. To
73// be used for unit testing.
74void wvstime_set(const WvTime &);
75
79void wvdelay(int msec_delay);
80
81#endif // __WVTIMEUTILS_H
Based on (and interchangeable with) struct timeval.