Commit | Line | Data |
---|---|---|
91fcc471 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 | */ | |
a9c88e1c GMF |
20 | #ifndef TIME_TO_LIVE_H |
21 | #define TIME_TO_LIVE_H | |
101be5ce | 22 | |
b0a693a0 GMF |
23 | #include <stdint.h> |
24 | ||
101be5ce | 25 | #include <boost/asio.hpp> |
dbe986b9 CH |
26 | #include <boost/serialization/access.hpp> |
27 | #include <boost/serialization/nvp.hpp> | |
28 | #include <boost/serialization/split_member.hpp> | |
29 | #include <boost/date_time/posix_time/posix_time.hpp> | |
e18c1337 CH |
30 | |
31 | // forward declaration | |
32 | class HostAddress; | |
101be5ce GMF |
33 | |
34 | //----------------------------------------------------------------------------- | |
35 | // TimeToLive | |
36 | //----------------------------------------------------------------------------- | |
37 | ||
38 | class TimeToLive | |
39 | { | |
40 | public: | |
b0a693a0 | 41 | TimeToLive( uint32_t ttl = 0 ); |
101be5ce GMF |
42 | ~TimeToLive(); |
43 | ||
b0a693a0 GMF |
44 | uint32_t get_value() const; |
45 | void set_value( const uint32_t ttl ); | |
101be5ce | 46 | |
b0a693a0 | 47 | uint32_t get_updated_value() const; |
101be5ce GMF |
48 | |
49 | private: | |
e18c1337 CH |
50 | // required for saving and loading TtlSetTime to original value |
51 | friend class HostAddress; | |
52 | //template<class Archive> | |
53 | //friend void HostAddress::load(Archive & ar, const unsigned int version); | |
54 | //template<class Archive> | |
55 | //friend void HostAddress::save(Archive & ar, const unsigned int version) | |
56 | // const; | |
57 | ||
d3e8a9f9 | 58 | /// the numeric time-to-live |
b0a693a0 | 59 | uint32_t Ttl; |
d3e8a9f9 GMF |
60 | /// the time when the time-to-live was set, so it is possible to know the |
61 | /// elapsed time | |
101be5ce | 62 | boost::posix_time::ptime TtlSetTime; |
dbe986b9 CH |
63 | |
64 | // serialization | |
65 | friend class boost::serialization::access; | |
66 | template<class Archive> | |
67 | void save(Archive & ar, const unsigned int version) const | |
68 | { | |
69 | std::string ttl_creation_time = boost::posix_time::to_iso_string( | |
70 | TtlSetTime); | |
71 | ar & BOOST_SERIALIZATION_NVP(Ttl); | |
72 | ar & BOOST_SERIALIZATION_NVP(ttl_creation_time); | |
73 | } | |
74 | ||
75 | template<class Archive> | |
76 | void load(Archive & ar, const unsigned int version) | |
77 | { | |
78 | uint32_t ttl_seconds; | |
79 | std::string ttl_creation_time; | |
80 | ar & BOOST_SERIALIZATION_NVP(ttl_seconds); | |
81 | ar & BOOST_SERIALIZATION_NVP(ttl_creation_time); | |
82 | ||
83 | // now convert to Ip and Ttl | |
84 | Ttl = ttl_seconds; | |
85 | TtlSetTime = boost::posix_time::from_iso_string(ttl_creation_time); | |
86 | } | |
87 | ||
88 | BOOST_SERIALIZATION_SPLIT_MEMBER() | |
101be5ce GMF |
89 | }; |
90 | ||
a9c88e1c | 91 | #endif // TIME_TO_LIVE_H |