summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEnrico Scholz <ensc@ensc.de>2014-01-01 18:47:02 +0100
committerEnrico Scholz <ensc@ensc.de>2014-01-02 16:14:15 +0100
commit022a3a615a82279e9ac8d03ac4038159838c9560 (patch)
tree3225d3b7cb1b775b621c4206ff922c4c7ecfa075
parent40062d6d083ae0480ba9df57089b9831fb46ea62 (diff)
downloadvdr-plugin-inputdev-022a3a615a82279e9ac8d03ac4038159838c9560.tar.gz
vdr-plugin-inputdev-022a3a615a82279e9ac8d03ac4038159838c9560.tar.bz2
time: handle timeval too
-rw-r--r--inputdev.cc41
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[] = {