|
Revision 598, 1.4 KB
(checked in by zhibinwu, 6 years ago)
|
|
adding clockref
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
| Line | |
|---|
| 1 | #ifndef UNIX_TIME_PORT_H |
|---|
| 2 | #define UNIX_TIME_PORT_H |
|---|
| 3 | |
|---|
| 4 | #include <time.h> |
|---|
| 5 | #include <sys/time.h> |
|---|
| 6 | #include <unistd.h> |
|---|
| 7 | |
|---|
| 8 | /** |
|---|
| 9 | * This class wraps some simple timing functons of Unix(Linux) System. |
|---|
| 10 | * In general, UnixTime class provide a wall clock of the program and it can be paused and resumed. |
|---|
| 11 | * The timing used in UNIX/Linux system is not accurate. |
|---|
| 12 | * we wrap basic timing operations in this class, for example we are going to map |
|---|
| 13 | * a timeval structure to a double absolute time value. |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| 16 | class UnixTime{ |
|---|
| 17 | public: |
|---|
| 18 | UnixTime(int externalcaliber = -1 ); |
|---|
| 19 | void setOrigin(); |
|---|
| 20 | /**Function to get the original time indication in system clock. |
|---|
| 21 | */ |
|---|
| 22 | inline double getOrigin(){return origin_;} |
|---|
| 23 | double getAbsoluteTime(); |
|---|
| 24 | inline void setAbsoluteOrigin(int hours){if (hours>0)abs_origin_ = hours*3600.0; }; |
|---|
| 25 | double getCurrentTime(); |
|---|
| 26 | bool pauseClock(); |
|---|
| 27 | bool resumeClock(); |
|---|
| 28 | /** |
|---|
| 29 | * Function to shift the orginal time. |
|---|
| 30 | */ |
|---|
| 31 | inline void shiftOrigin(double shifttime){ origin_ += shifttime;} |
|---|
| 32 | void waitAt(double timestamp); |
|---|
| 33 | |
|---|
| 34 | private: |
|---|
| 35 | double origin_; ///< original time. timing are in the unit of seconds of system clock |
|---|
| 36 | double abs_origin_; ///< starting time offset to calculate absolute time |
|---|
| 37 | double pauseinstant_; ///< The clock time (relative time) when the clock is paused |
|---|
| 38 | bool paused_; ///< A flag to indicate if the clock is paused now |
|---|
| 39 | }; |
|---|
| 40 | |
|---|
| 41 | #endif |
|---|