From 8c04f3936822c13acdb6711ccd3159395a96ee0b Mon Sep 17 00:00:00 2001
From: Matthias Vogelgesang <matthias.vogelgesang@kit.edu>
Date: Thu, 4 Jul 2013 16:58:14 +0200
Subject: Make Timer private and calculate elapsed seconds

---
 test/ipedec.c |  6 +++---
 test/timer.c  | 12 ++++++++++++
 test/timer.h  | 15 ++++++---------
 3 files changed, 21 insertions(+), 12 deletions(-)

(limited to 'test')

diff --git a/test/ipedec.c b/test/ipedec.c
index 52aebb0..f171cc8 100644
--- a/test/ipedec.c
+++ b/test/ipedec.c
@@ -21,6 +21,7 @@ typedef struct {
     int convert_bayer;
 } Options;
 
+
 static int
 read_raw_file(const char *filename, char **buffer, size_t *length)
 {
@@ -103,7 +104,6 @@ print_meta_data (UfoDecoderMeta *meta)
     printf("\n");
 }
 
-
 static int
 process_file(const char *filename, Options *opts)
 {
@@ -217,8 +217,8 @@ process_file(const char *filename, Options *opts)
         fclose(fp);
 
     if (opts->verbose) {
-        mtime = timer->seconds * 1000.0 + timer->useconds / 1000.0;
-        printf("Decoded %i frames in %.5fms\n", n_frames, mtime);
+        printf("Decoded %i frames in %.5fms\n", n_frames,
+               timer_get_seconds (timer) * 1000.0);
     }
 
     if (opts->convert_bayer)
diff --git a/test/timer.c b/test/timer.c
index 43aff84..987f18d 100644
--- a/test/timer.c
+++ b/test/timer.c
@@ -1,6 +1,12 @@
 #include <stdlib.h>
 #include "timer.h"
 
+struct _Timer {
+    struct timeval  start;
+    long            seconds;
+    long            useconds;
+};
+
 
 Timer *
 timer_new (void)
@@ -31,3 +37,9 @@ timer_stop (Timer *t)
     t->seconds += end.tv_sec - t->start.tv_sec;
     t->useconds += end.tv_usec - t->start.tv_usec;
 }
+
+double
+timer_get_seconds (Timer *t)
+{
+    return t->seconds + t->useconds / 1000.0 / 1000.0;
+}
diff --git a/test/timer.h b/test/timer.h
index 272f69d..3367367 100644
--- a/test/timer.h
+++ b/test/timer.h
@@ -3,15 +3,12 @@
 
 #include <sys/time.h>
 
-typedef struct {
-    struct timeval  start;
-    long            seconds;
-    long            useconds;
-} Timer;
+typedef struct _Timer Timer;
 
-Timer * timer_new       (void);
-void    timer_destroy   (Timer *t);
-void    timer_start     (Timer *t);
-void    timer_stop      (Timer *t);
+Timer * timer_new           (void);
+void    timer_destroy       (Timer *t);
+void    timer_start         (Timer *t);
+void    timer_stop          (Timer *t);
+double  timer_get_seconds   (Timer *t);
 
 #endif
-- 
cgit v1.2.3