diff options
-rw-r--r-- | inputdev.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/inputdev.cc b/inputdev.cc index 90a7653..9f280d2 100644 --- a/inputdev.cc +++ b/inputdev.cc @@ -35,10 +35,22 @@ namespace Time { static int compare(struct timespec const &a, struct timespec const &b); + static int compare(struct timeval const &a, + struct timeval const &b); + static void add(struct timespec &res, struct timespec const &a, struct timespec const &b); + static void add(struct timeval &res, + struct timeval const &a, + struct timeval const &b); + + static bool is_null(struct timeval const &a) + { + return a.tv_sec == 0 && a.tv_usec == 0; + } + static bool check_clock_gettime(void); }; @@ -89,6 +101,20 @@ int Time::compare(struct timespec const &a, struct timespec const &b) return 0; } +int Time::compare(struct timeval const &a, struct timeval const &b) +{ + if (a.tv_sec < b.tv_sec) + return -1; + else if (a.tv_sec > b.tv_sec) + return + 1; + else if (a.tv_usec < b.tv_usec) + return -1; + else if (a.tv_usec > b.tv_usec) + return +1; + else + return 0; +} + void Time::add(struct timespec &res, struct timespec const &a, struct timespec const &b) { @@ -104,6 +130,21 @@ void Time::add(struct timespec &res, } } +void Time::add(struct timeval &res, + struct timeval const &a, struct timeval const &b) +{ + assert(a.tv_usec < 1000000000); + assert(b.tv_usec < 1000000000); + + res.tv_sec = a.tv_sec + b.tv_sec; + res.tv_usec = a.tv_usec + b.tv_usec; + + if (res.tv_usec >= 1000000) { + res.tv_usec -= 1000000; + res.tv_sec += 1; + } +} + bool MagicState::process(struct input_event const &ev) { static unsigned int const SEQUENCE[] = { |