Commit | Line | Data |
---|---|---|
8c15b8c7 TJ |
1 | /* |
2 | The software in this package is distributed under the GNU General | |
3 | Public License version 2 (with a special exception described below). | |
4 | ||
5 | A copy of GNU General Public License (GPL) is included in this distribution, | |
6 | in the file COPYING.GPL. | |
7 | ||
8 | As a special exception, if other files instantiate templates or use macros | |
9 | or inline functions from this file, or you compile this file and link it | |
10 | with other works to produce a work based on this file, this file | |
11 | does not by itself cause the resulting work to be covered | |
12 | by the GNU General Public License. | |
13 | ||
14 | However the source code for this file must still be made available | |
15 | in accordance with section (3) of the GNU General Public License. | |
16 | ||
17 | This exception does not invalidate any other reasons why a work based | |
18 | on this file might be covered by the GNU General Public License. | |
19 | */ | |
7841da45 | 20 | /** |
aba4c34d RP |
21 | * @file |
22 | * @brief | |
23 | * | |
7841da45 | 24 | * @author Reinhard Pfau \<reinhard.pfau@gmx.de\> |
aba4c34d | 25 | * |
7841da45 RP |
26 | * @copyright © Copyright 2008-2009 Intra2Net AG |
27 | * @contact Intra2net Opensource team \<opensource@intra2net.com\> | |
aba4c34d RP |
28 | */ |
29 | ||
30 | #ifndef __ASYNCIO__TIME_TOOLS_HPP__ | |
31 | #define __ASYNCIO__TIME_TOOLS_HPP__ | |
32 | ||
33 | namespace AsyncIo | |
34 | { | |
35 | namespace Utils | |
36 | { | |
37 | ||
38 | /** | |
39 | * @brief structure for storing (a point in time as) seconds and milliseconds. | |
7841da45 RP |
40 | * |
41 | * This structure is used at various places within libasyncio to represent points in | |
42 | * time or time durations. | |
aba4c34d RP |
43 | */ |
44 | struct MilliTime | |
45 | { | |
46 | long mt_sec; | |
47 | long mt_msec; | |
48 | ||
49 | MilliTime(long sec=0, long msec=0); | |
50 | ||
51 | void set(long sec, long msec=0); | |
52 | ||
53 | inline long long get_milliseconds() const | |
54 | { | |
55 | return ((long long)mt_sec * 1000L + mt_msec); | |
56 | } // eo get_milliseconds | |
57 | ||
58 | void normalize(); | |
59 | ||
60 | bool operator < (MilliTime& other); | |
61 | bool operator == (MilliTime& other); | |
62 | ||
63 | MilliTime& operator -= (const MilliTime& lhs); | |
64 | MilliTime& operator += (const MilliTime& lhs); | |
65 | ||
66 | }; // eo struct MilliTime | |
67 | ||
68 | ||
69 | inline MilliTime operator + (const MilliTime& rhs, const MilliTime& lhs) | |
70 | { | |
71 | MilliTime t(rhs); | |
72 | return t+= lhs; | |
73 | } // eo operator + (const MilliTime& rhs, const MilliTime lhs) | |
74 | ||
75 | inline MilliTime operator - (const MilliTime& rhs, const MilliTime& lhs) | |
76 | { | |
77 | MilliTime t(rhs); | |
78 | return t-= lhs; | |
79 | } // eo operator - (const MilliTime& rhs, const MilliTime lhs) | |
80 | ||
81 | ||
82 | inline bool operator <= (MilliTime& rhs, MilliTime& lhs) | |
83 | { | |
84 | return (rhs<lhs) || (rhs==lhs); | |
85 | } // eo operator <= (MilliTime& rhs, MilliTime& lhs) | |
86 | ||
87 | ||
88 | ||
89 | /* | |
90 | ** tool functions: | |
91 | */ | |
92 | ||
93 | ||
94 | void get_current_real_time(MilliTime& mt); | |
95 | void get_current_monotonic_time(MilliTime& mt); | |
96 | ||
97 | ||
98 | } // eo namespace Utils | |
99 | } // eo namespace AsyncIo | |
100 | ||
101 | ||
102 | ||
fd6ea89e | 103 | #endif |