all: Refactoring work with time using boost::chrono
Now the library has two clocks: time::steady_clock and
time::system_clock, following (boost|std)::chrono. In addition to
standard now() method, the library contains several helpers to convert
to/from UnixTimestamp (microsecond resolution) and IsoString (optional
microsecond resolution). The IsoString conversions use
boost::posix_time routines, since boost::chrono supports extended IO
support only starting boost version 1.52 (Boost Chrono V2).
This commit breaks compatibility with previous API. All time-related
Data/Interest calls must explicitly use time units to specify
FreshnessPeriod/InterestLifetime.
Brief usage/conversion guide:
- creation of time units does not support double/float types. If
necessary to create time unit from double, ``ndn::duration<double>`` (for
seconds) needs to be used instead. In some cases, this would also
require ``ndn::duration_cast``, if the target is not ``ndn::nanoseconds``.
- ndn::getNow, ndn::ndn_getNowMilliseconds, ndn::time::now are all
removed in favor of the now() method in a specific clock:
* time::system_clock::now();
* time::steady_clock::now();
- When necessary to convert system_clock::TimePoint to unix timestamp,
``time::toUnixTimestamp`` can be used. This method return number of
milliseconds since UNIX epoch as ``ndn::time::milliseconds`` type.
Use count() method to obtain number as an integral value.
Change-Id: Icd688bc6766e008d60c3d2888173627874526e47
Refs: #1152
diff --git a/src/management/nrd-prefix-reg-options.hpp b/src/management/nrd-prefix-reg-options.hpp
index 412194b..c80d04b 100644
--- a/src/management/nrd-prefix-reg-options.hpp
+++ b/src/management/nrd-prefix-reg-options.hpp
@@ -26,13 +26,13 @@
*/
class PrefixRegOptions {
public:
- struct Error : public Tlv::Error { Error(const std::string &what) : Tlv::Error(what) {} };
+ struct Error : public Tlv::Error { Error(const std::string& what) : Tlv::Error(what) {} };
PrefixRegOptions()
- : m_faceId (INVALID_FACE_ID)
- , m_flags (DEFAULT_FLAGS)
- , m_cost (DEFAULT_COST)
- , m_expirationPeriod (-1)
+ : m_faceId(INVALID_FACE_ID)
+ , m_flags(DEFAULT_FLAGS)
+ , m_cost(DEFAULT_COST)
+ , m_expirationPeriod(time::milliseconds::min())
{
}
@@ -117,14 +117,14 @@
//
- Milliseconds
+ const time::milliseconds&
getExpirationPeriod() const
{
return m_expirationPeriod;
}
PrefixRegOptions&
- setExpirationPeriod(Milliseconds expirationPeriod)
+ setExpirationPeriod(const time::milliseconds& expirationPeriod)
{
m_expirationPeriod = expirationPeriod;
m_wire.reset();
@@ -152,7 +152,7 @@
uint64_t m_faceId;
uint64_t m_flags;
uint64_t m_cost;
- Milliseconds m_expirationPeriod;
+ time::milliseconds m_expirationPeriod;
std::string m_protocol;
mutable Block m_wire;
@@ -184,10 +184,11 @@
}
// ExpirationPeriod
- if (m_expirationPeriod > 0)
+ if (m_expirationPeriod > time::milliseconds::zero())
{
total_len += prependNonNegativeIntegerBlock(block,
- tlv::nrd::ExpirationPeriod, m_expirationPeriod);
+ tlv::nrd::ExpirationPeriod,
+ m_expirationPeriod.count());
}
// Cost
@@ -247,7 +248,7 @@
m_faceId = INVALID_FACE_ID;
m_flags = DEFAULT_FLAGS;
m_cost = DEFAULT_COST;
- m_expirationPeriod = -1;
+ m_expirationPeriod = time::milliseconds::min();
m_protocol.clear();
m_wire = wire;
@@ -289,7 +290,7 @@
val = m_wire.find(tlv::nrd::ExpirationPeriod);
if (val != m_wire.elements_end())
{
- m_expirationPeriod = readNonNegativeInteger(*val);
+ m_expirationPeriod = time::milliseconds(readNonNegativeInteger(*val));
}
// Protocol