29 #include <vrpn_Shared.h>
34 #if defined(OSVR_HAVE_STRUCT_TIMEVAL_IN_SYS_TIME_H)
36 typedef time_t tv_seconds_type;
37 typedef suseconds_t tv_microseconds_type;
38 #elif defined(OSVR_HAVE_STRUCT_TIMEVAL_IN_WINSOCK2_H)
40 typedef long tv_seconds_type;
41 typedef long tv_microseconds_type;
44 #define OSVR_USEC_PER_SEC std::micro::den;
51 tv->microseconds / OSVR_USEC_PER_SEC;
53 tv->microseconds -= rem * OSVR_USEC_PER_SEC;
56 if (tv->seconds > 0 && tv->microseconds < 0) {
58 tv->microseconds += OSVR_USEC_PER_SEC;
59 }
else if (tv->seconds < 0 && tv->microseconds > 0) {
61 tv->microseconds -= OSVR_USEC_PER_SEC;
70 tvA->seconds += tvB->seconds;
71 tvA->microseconds += tvB->microseconds;
80 tvA->seconds -= tvB->seconds;
81 tvA->microseconds -= tvB->microseconds;
85 template <
typename T>
inline int numcmp(T a, T b) {
86 return (a == b) ? 0 : (a < b ? -1 : 1);
94 auto major = numcmp(tvA->seconds, tvB->seconds);
95 return (major != 0) ? major : numcmp(tvA->microseconds, tvB->microseconds);
98 #ifdef OSVR_HAVE_STRUCT_TIMEVAL
102 vrpn_gettimeofday(&tv,
nullptr);
111 dest->tv_sec = tv_seconds_type(src->seconds);
112 dest->tv_usec = tv_microseconds_type(src->microseconds);
116 OSVR_IN_PTR
const timeval *src) {
120 dest->seconds = src->tv_sec;
121 dest->microseconds = src->tv_usec;
void osvrTimeValueGetNow(OSVR_TimeValue *dest)
Gets the current time in the TimeValue. Parallel to gettimeofday.
int32_t OSVR_TimeValue_Microseconds
The signed integer type storing the microseconds in a struct OSVR_TimeValue.
void osvrTimeValueToStructTimeval(timeval *dest, const OSVR_TimeValue *src)
Converts from a TimeValue struct to your system's struct timeval.
void osvrTimeValueDifference(OSVR_TimeValue *tvA, const OSVR_TimeValue *tvB)
Computes the difference between two time values, replacing the first with the result.
void osvrStructTimevalToTimeValue(OSVR_TimeValue *dest, const struct timeval *src)
Converts from a TimeValue struct to your system's struct timeval.
Header defining a dependency-free, cross-platform substitute for struct timeval.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
void osvrTimeValueSum(OSVR_TimeValue *tvA, const OSVR_TimeValue *tvB)
Sums two time values, replacing the first with the result.
int osvrTimeValueCmp(const OSVR_TimeValue *tvA, const OSVR_TimeValue *tvB)
Compares two time values (assumed to be normalized), returning the same values as strcmp...
void osvrTimeValueNormalize(OSVR_TimeValue *tv)
"Normalizes" a time value so that the absolute number of microseconds is less than 1...