simplified dns (no self-made recursion); merge PingScheduler and PingRotate; make...
[pingcheck] / src / dns / timetolive.h
CommitLineData
91fcc471
TJ
1/*
2The software in this package is distributed under the GNU General
3Public License version 2 (with a special exception described below).
4
5A copy of GNU General Public License (GPL) is included in this distribution,
6in the file COPYING.GPL.
7
8As a special exception, if other files instantiate templates or use macros
9or inline functions from this file, or you compile this file and link it
10with other works to produce a work based on this file, this file
11does not by itself cause the resulting work to be covered
12by the GNU General Public License.
13
14However the source code for this file must still be made available
15in accordance with section (3) of the GNU General Public License.
16
17This exception does not invalidate any other reasons why a work based
18on 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>
23f51766 29#include <boost/serialization/string.hpp>
dbe986b9 30#include <boost/date_time/posix_time/posix_time.hpp>
e18c1337
CH
31
32// forward declaration
33class HostAddress;
101be5ce
GMF
34
35//-----------------------------------------------------------------------------
36// TimeToLive
37//-----------------------------------------------------------------------------
38
39class TimeToLive
40{
41public:
b0a693a0 42 TimeToLive( uint32_t ttl = 0 );
101be5ce
GMF
43 ~TimeToLive();
44
b0a693a0
GMF
45 uint32_t get_value() const;
46 void set_value( const uint32_t ttl );
101be5ce 47
b0a693a0 48 uint32_t get_updated_value() const;
101be5ce
GMF
49
50private:
d3e8a9f9 51 /// the numeric time-to-live
b0a693a0 52 uint32_t Ttl;
d3e8a9f9
GMF
53 /// the time when the time-to-live was set, so it is possible to know the
54 /// elapsed time
101be5ce 55 boost::posix_time::ptime TtlSetTime;
dbe986b9
CH
56
57 // serialization
58 friend class boost::serialization::access;
59 template<class Archive>
60 void save(Archive & ar, const unsigned int version) const
61 {
62 std::string ttl_creation_time = boost::posix_time::to_iso_string(
63 TtlSetTime);
64 ar & BOOST_SERIALIZATION_NVP(Ttl);
65 ar & BOOST_SERIALIZATION_NVP(ttl_creation_time);
66 }
67
68 template<class Archive>
69 void load(Archive & ar, const unsigned int version)
70 {
71 uint32_t ttl_seconds;
72 std::string ttl_creation_time;
73 ar & BOOST_SERIALIZATION_NVP(ttl_seconds);
74 ar & BOOST_SERIALIZATION_NVP(ttl_creation_time);
75
76 // now convert to Ip and Ttl
77 Ttl = ttl_seconds;
78 TtlSetTime = boost::posix_time::from_iso_string(ttl_creation_time);
79 }
80
81 BOOST_SERIALIZATION_SPLIT_MEMBER()
101be5ce
GMF
82};
83
a9c88e1c 84#endif // TIME_TO_LIVE_H