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/ndnd-face-instance.hpp b/src/management/ndnd-face-instance.hpp
index 1da6b94..60c07dc 100644
--- a/src/management/ndnd-face-instance.hpp
+++ b/src/management/ndnd-face-instance.hpp
@@ -18,7 +18,7 @@
* An FaceInstance holds an action and Name prefix and other fields for an forwarding entry.
*/
class FaceInstance {
-public:
+public:
FaceInstance(const std::string &action,
int64_t faceId,
uint32_t ipProto,
@@ -26,7 +26,7 @@
const std::string &port,
const std::string &multicastInterface,
uint32_t multicastTtl,
- Milliseconds freshnessPeriod)
+ const time::milliseconds& freshnessPeriod)
: action_(action)
, faceId_(faceId)
, ipProto_(ipProto)
@@ -42,73 +42,79 @@
: faceId_(-1)
, ipProto_(-1)
, multicastTtl_(-1)
- , freshnessPeriod_(-1)
+ , freshnessPeriod_(time::milliseconds::min())
{
}
// Action
- const std::string&
+ const std::string&
getAction() const { return action_; }
- void
+ void
setAction(const std::string& action) { action_ = action; wire_.reset(); }
// FaceID
int64_t
getFaceId() const { return faceId_; }
- void
+ void
setFaceId(int64_t faceId) { faceId_ = faceId; wire_.reset(); }
// IPProto
- int32_t
+ int32_t
getIpProto() const { return ipProto_; }
- void
+ void
setIpProto(int32_t ipProto) { ipProto_ = ipProto; wire_.reset(); }
// Host
- const std::string&
+ const std::string&
getHost() const { return host_; }
- void
+ void
setHost(const std::string& host) { host_ = host; wire_.reset(); }
// Port
const std::string&
getPort() const { return port_; }
- void
+ void
setPort(const std::string &port) { port_ = port; wire_.reset(); }
// MulticastInterface
- const std::string&
+ const std::string&
getMulticastInterface() const { return multicastInterface_; }
- void
- setMulticastInterface(const std::string& multicastInterface) { multicastInterface_ = multicastInterface; wire_.reset(); }
+ void
+ setMulticastInterface(const std::string& multicastInterface)
+ {
+ multicastInterface_ = multicastInterface; wire_.reset();
+ }
// MulticastTTL
int32_t
getMulticastTtl() const { return multicastTtl_; }
- void
+ void
setMulticastTtl(int32_t multicastTtl) { multicastTtl_ = multicastTtl; wire_.reset(); }
// Freshness
- int
+ const time::milliseconds&
getFreshnessPeriod() const { return freshnessPeriod_; }
- void
- setFreshnessPeriod(int freshnessPeriod) { freshnessPeriod_ = freshnessPeriod; wire_.reset(); }
+ void
+ setFreshnessPeriod(const time::milliseconds& freshnessPeriod)
+ {
+ freshnessPeriod_ = freshnessPeriod; wire_.reset();
+ }
// Wire
inline const Block&
wireEncode() const;
-
- inline void
+
+ inline void
wireDecode(const Block &wire);
-
+
private:
std::string action_;
int64_t faceId_;
@@ -117,8 +123,8 @@
std::string port_;
std::string multicastInterface_;
int32_t multicastTtl_;
- Milliseconds freshnessPeriod_;
-
+ time::milliseconds freshnessPeriod_;
+
mutable Block wire_;
};
@@ -137,7 +143,7 @@
// MulticastInterface?
// MulticastTTL?
// FreshnessPeriod?
-
+
wire_ = Block(tlv::ndnd::FaceInstance);
// Action
@@ -160,7 +166,7 @@
wire_.push_back
(nonNegativeIntegerBlock(tlv::ndnd::IPProto, ipProto_));
}
-
+
// Host
if (!host_.empty())
{
@@ -190,17 +196,17 @@
}
// FreshnessPeriod
- if (freshnessPeriod_ >= 0)
+ if (freshnessPeriod_ >= time::milliseconds::zero())
{
wire_.push_back
- (nonNegativeIntegerBlock(Tlv::FreshnessPeriod, freshnessPeriod_));
+ (nonNegativeIntegerBlock(Tlv::FreshnessPeriod, freshnessPeriod_.count()));
}
-
+
wire_.encode();
- return wire_;
+ return wire_;
}
-
-inline void
+
+inline void
FaceInstance::wireDecode(const Block &wire)
{
action_.clear();
@@ -210,7 +216,7 @@
port_.clear();
multicastInterface_.clear();
multicastTtl_ = -1;
- freshnessPeriod_ = -1;
+ freshnessPeriod_ = time::milliseconds::min();
wire_ = wire;
wire_.parse();
@@ -278,7 +284,7 @@
val = wire_.find(Tlv::FreshnessPeriod);
if (val != wire_.elements_end())
{
- freshnessPeriod_ = readNonNegativeInteger(*val);
+ freshnessPeriod_ = time::milliseconds(readNonNegativeInteger(*val));
}
}
@@ -286,7 +292,7 @@
operator << (std::ostream &os, const FaceInstance &entry)
{
os << "FaceInstance(";
-
+
// Action
if (!entry.getAction().empty())
{
@@ -330,7 +336,7 @@
}
// FreshnessPeriod
- if (entry.getFreshnessPeriod() >= 0)
+ if (entry.getFreshnessPeriod() >= time::milliseconds::zero())
{
os << "FreshnessPeriod:" << entry.getFreshnessPeriod() << ", ";
}
@@ -343,4 +349,3 @@
} // namespace ndn
#endif // NDN_MANAGEMENT_NDND_FACE_INSTANCE_HPP
-