/* The software in this package is distributed under the GNU General Public License version 2 (with a special exception described below). A copy of GNU General Public License (GPL) is included in this distribution, in the file COPYING.GPL. As a special exception, if other files instantiate templates or use macros or inline functions from this file, or you compile this file and link it with other works to produce a work based on this file, this file does not by itself cause the resulting work to be covered by the GNU General Public License. However the source code for this file must still be made available in accordance with section (3) of the GNU General Public License. This exception does not invalidate any other reasons why a work based on this file might be covered by the GNU General Public License. */ #ifndef TIME_TO_LIVE_H #define TIME_TO_LIVE_H #include #include #include #include #include #include #include // forward declaration class HostAddress; //----------------------------------------------------------------------------- // TimeToLive //----------------------------------------------------------------------------- class TimeToLive { public: TimeToLive( uint32_t ttl = 0 ); ~TimeToLive(); uint32_t get_value() const; void set_value( const uint32_t ttl ); uint32_t get_updated_value() const; bool was_set_before(const boost::posix_time::ptime &threshold) const; private: /// the numeric time-to-live uint32_t Ttl; /// the time when the time-to-live was set, so it is possible to know the /// elapsed time boost::posix_time::ptime TtlSetTime; // serialization friend class boost::serialization::access; template void save(Archive & ar, const unsigned int version) const { std::string ttl_creation_time = boost::posix_time::to_iso_string( TtlSetTime); ar & BOOST_SERIALIZATION_NVP(Ttl); ar & BOOST_SERIALIZATION_NVP(ttl_creation_time); } template void load(Archive & ar, const unsigned int version) { std::string ttl_creation_time; ar & BOOST_SERIALIZATION_NVP(Ttl); ar & BOOST_SERIALIZATION_NVP(ttl_creation_time); // now convert to Ip and Ttl TtlSetTime = boost::posix_time::from_iso_string(ttl_creation_time); } BOOST_SERIALIZATION_SPLIT_MEMBER() }; #endif // TIME_TO_LIVE_H