diff options
author | lloyd <[email protected]> | 2008-11-21 16:55:57 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-11-21 16:55:57 +0000 |
commit | 4db9d2279629408a9df94b887a65c6aabcefeb6f (patch) | |
tree | cb1b3979ab2a1d7e4f9fc1b30dac43b87059b707 | |
parent | 8c885d8fca72e46a27f3f86f3645c780d34596b8 (diff) |
Make Timer a pure virtual interface and add a new subclass ANSI_Clock_Timer
which uses the ANSI/ISO clock function (previously this had been the
Timer::clock default implementation).
-rw-r--r-- | src/timer/timer.cpp | 43 | ||||
-rw-r--r-- | src/timer/timer.h | 28 |
2 files changed, 40 insertions, 31 deletions
diff --git a/src/timer/timer.cpp b/src/timer/timer.cpp index a37cf39c3..7ea4f56ad 100644 --- a/src/timer/timer.cpp +++ b/src/timer/timer.cpp @@ -1,7 +1,7 @@ -/************************************************* -* Timestamp Functions Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ +/** +* Timestamp Functions Source File +* (C) 1999-2008 Jack Lloyd +*/ #include <botan/timer.h> #include <botan/loadstor.h> @@ -10,25 +10,17 @@ namespace Botan { -/************************************************* -* Get the system clock * -*************************************************/ +/** +* Get the system clock +*/ u64bit system_time() { return static_cast<u64bit>(std::time(0)); } -/************************************************* -* Default Timer clock reading * -*************************************************/ -u64bit Timer::clock() const - { - return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC); - } - -/************************************************* -* Read the clock and return the output * -*************************************************/ +/** +* Read the clock and return the output +*/ u32bit Timer::fast_poll(byte out[], u32bit length) { const u64bit clock_value = this->clock(); @@ -44,9 +36,9 @@ u32bit Timer::slow_poll(byte out[], u32bit length) return fast_poll(out, length); } -/************************************************* -* Combine a two time values into a single one * -*************************************************/ +/** +* Combine a two time values into a single one +*/ u64bit Timer::combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz) { static const u64bit NANOSECONDS_UNITS = 1000000000; @@ -54,4 +46,13 @@ u64bit Timer::combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz) return ((seconds * NANOSECONDS_UNITS) + parts); } +/** +* ANSI Clock +*/ +u64bit ANSI_Clock_Timer::clock() const + { + return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC); + } + + } diff --git a/src/timer/timer.h b/src/timer/timer.h index 9aa95f261..dfa04ee3a 100644 --- a/src/timer/timer.h +++ b/src/timer/timer.h @@ -1,7 +1,7 @@ -/************************************************* -* Timestamp Functions Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ +/** +* Timestamp Functions Header File +* (C) 1999-2008 Jack Lloyd +*/ #ifndef BOTAN_TIMERS_H__ #define BOTAN_TIMERS_H__ @@ -10,23 +10,31 @@ namespace Botan { -/************************************************* -* Timer Interface * -*************************************************/ +/** +* Timer Interface +*/ class BOTAN_DLL Timer : public EntropySource { public: - virtual u64bit clock() const; + virtual u64bit clock() const = 0; u32bit slow_poll(byte[], u32bit); u32bit fast_poll(byte[], u32bit); - std::string name() const { return "ANSI clock"; } - virtual ~Timer() {} protected: static u64bit combine_timers(u32bit, u32bit, u32bit); }; +/** +* ANSI Clock Timer +*/ +class BOTAN_DLL ANSI_Clock_Timer : public Timer + { + public: + std::string name() const { return "ANSI clock"; } + u64bit clock() const; + }; + } #endif |