updated to use new modules (more independance to libi2ncommon)
[libasyncio] / utils / asyncio_time_tools.hpp
1 /** 
2  * @file
3  * @brief
4  *
5  * @author Reinhard Pfau \<reinhard.pfau@intra2net.com\>
6  *
7  * @copyright &copy; Copyright 2008 Intra2Net AG
8  * @license LPGL
9  * @contact info@intra2net.com
10  *
11  */
12
13 #ifndef __ASYNCIO__TIME_TOOLS_HPP__
14 #define __ASYNCIO__TIME_TOOLS_HPP__
15
16 namespace AsyncIo
17 {
18 namespace Utils
19 {
20
21 /**
22  * @brief structure for storing (a point in time as) seconds and milliseconds.
23  */
24 struct MilliTime
25 {
26     long mt_sec;
27     long mt_msec;
28
29     MilliTime(long sec=0, long msec=0);
30
31     void set(long sec, long msec=0);
32
33     inline long long get_milliseconds() const
34     {
35         return ((long long)mt_sec * 1000L + mt_msec);
36     } // eo get_milliseconds
37
38     void normalize();
39
40     bool operator < (MilliTime& other);
41     bool operator == (MilliTime& other);
42
43     MilliTime& operator -= (const MilliTime& lhs);
44     MilliTime& operator += (const MilliTime& lhs);
45
46 }; // eo struct MilliTime
47
48
49 inline MilliTime operator + (const MilliTime& rhs, const MilliTime& lhs)
50 {
51     MilliTime t(rhs);
52     return t+= lhs;
53 } // eo operator + (const MilliTime& rhs, const MilliTime lhs)
54
55 inline MilliTime operator - (const MilliTime& rhs, const MilliTime& lhs)
56 {
57     MilliTime t(rhs);
58     return t-= lhs;
59 } // eo operator - (const MilliTime& rhs, const MilliTime lhs)
60
61
62 inline bool operator <= (MilliTime& rhs, MilliTime& lhs)
63 {
64     return (rhs<lhs) || (rhs==lhs);
65 } // eo operator <= (MilliTime& rhs, MilliTime& lhs)
66
67
68
69 /*
70 ** tool functions:
71 */
72
73
74 void get_current_real_time(MilliTime& mt);
75 void get_current_monotonic_time(MilliTime& mt);
76
77
78 } // eo namespace Utils
79 } // eo namespace AsyncIo
80
81
82
83 #endif