common.hpp: time: Added typedef for Milliseconds and MillisecondsSince1970, and use instead of double where appropriate.
diff --git a/ndn-cpp/c/data.h b/ndn-cpp/c/data.h
index 8d14e05..68ed6ed 100644
--- a/ndn-cpp/c/data.h
+++ b/ndn-cpp/c/data.h
@@ -46,10 +46,10 @@
* An ndn_MetaInfo struct holds the meta info which is signed inside the data packet.
*/
struct ndn_MetaInfo {
- double timestampMilliseconds; /**< milliseconds since 1/1/1970. -1 for none */
- ndn_ContentType type; /**< default is ndn_ContentType_DATA. -1 for none */
- int freshnessSeconds; /**< -1 for none */
- struct ndn_NameComponent finalBlockID; /**< has a pointer to a pre-allocated buffer. 0 for none */
+ ndn_MillisecondsSince1970 timestampMilliseconds; /**< milliseconds since 1/1/1970. -1 for none */
+ ndn_ContentType type; /**< default is ndn_ContentType_DATA. -1 for none */
+ int freshnessSeconds; /**< -1 for none */
+ struct ndn_NameComponent finalBlockID; /**< has a pointer to a pre-allocated buffer. 0 for none */
};
/**
diff --git a/ndn-cpp/c/interest.h b/ndn-cpp/c/interest.h
index 12ca38e..438fecd 100644
--- a/ndn-cpp/c/interest.h
+++ b/ndn-cpp/c/interest.h
@@ -99,7 +99,7 @@
int childSelector; /**< -1 for none */
int answerOriginKind; /**< -1 for none */
int scope; /**< -1 for none */
- double interestLifetimeMilliseconds; /**< milliseconds. -1.0 for none */
+ ndn_Milliseconds interestLifetimeMilliseconds; /**< milliseconds. -1.0 for none */
struct ndn_Blob nonce; /**< The blob whose value is a pointer to a pre-allocated buffer. 0 for none */
};
diff --git a/ndn-cpp/c/util/time.c b/ndn-cpp/c/util/time.c
index a794047..9da0e1c 100644
--- a/ndn-cpp/c/util/time.c
+++ b/ndn-cpp/c/util/time.c
@@ -7,7 +7,7 @@
#include <sys/time.h>
#include "time.h"
-double
+ndn_MillisecondsSince1970
ndn_getNowMilliseconds()
{
struct timeval t;
diff --git a/ndn-cpp/c/util/time.h b/ndn-cpp/c/util/time.h
index 36b4dad..adcb0b4 100644
--- a/ndn-cpp/c/util/time.h
+++ b/ndn-cpp/c/util/time.h
@@ -7,6 +7,8 @@
#ifndef NDN_TIME_H
#define NDN_TIME_H
+#include <ndn-cpp/c/common.h>
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -15,7 +17,7 @@
* Use gettimeofday to return the current time in milliseconds.
* @return The current time in milliseconds since 1/1/1970, including fractions of a millisecond according to timeval.tv_usec.
*/
-double
+ndn_MillisecondsSince1970
ndn_getNowMilliseconds();
#ifdef __cplusplus
diff --git a/ndn-cpp/encoding/der/der.cpp b/ndn-cpp/encoding/der/der.cpp
index 7981727..0b5531e 100644
--- a/ndn-cpp/encoding/der/der.cpp
+++ b/ndn-cpp/encoding/der/der.cpp
@@ -576,7 +576,7 @@
/*
* DerGtime
*/
-DerGtime::DerGtime(const Time& time)
+DerGtime::DerGtime(const MillisecondsSince1970& time)
:DerNode(DER_GENERALIZED_TIME)
{
string pTimeStr = toIsoString(time);
@@ -594,14 +594,14 @@
DerGtime::~DerGtime()
{}
-string DerGtime::toIsoString(const Time& time)
+string DerGtime::toIsoString(const MillisecondsSince1970& time)
{
#if 1
throw std::runtime_error("not implemented");
#endif
}
-Time DerGtime::fromIsoString(const string& isoString)
+MillisecondsSince1970 DerGtime::fromIsoString(const string& isoString)
{
#if 1
throw std::runtime_error("not implemented");
diff --git a/ndn-cpp/encoding/der/der.hpp b/ndn-cpp/encoding/der/der.hpp
index 9ed4a2a..ff92c78 100644
--- a/ndn-cpp/encoding/der/der.hpp
+++ b/ndn-cpp/encoding/der/der.hpp
@@ -355,7 +355,7 @@
class DerGtime : public DerNode
{
public:
- DerGtime(const Time& time);
+ DerGtime(const MillisecondsSince1970& time);
DerGtime(std::istream& start);
@@ -372,14 +372,14 @@
* @param time Milliseconds since 1/1/1970.
* @return The ISO string.
*/
- static std::string toIsoString(const Time& time);
+ static std::string toIsoString(const MillisecondsSince1970& time);
/**
* Convert from the ISO string representation to the internal time format.
* @param isoString The ISO time formatted string.
* @return The time in milliseconds since 1/1/1970.
*/
- static Time fromIsoString(const std::string& isoString);
+ static MillisecondsSince1970 fromIsoString(const std::string& isoString);
};
} // der
diff --git a/ndn-cpp/node.cpp b/ndn-cpp/node.cpp
index 35a295a..622d155 100644
--- a/ndn-cpp/node.cpp
+++ b/ndn-cpp/node.cpp
@@ -240,7 +240,7 @@
transport_->processEvents();
// Check for PIT entry timeouts. Go backwards through the list so we can erase entries.
- double nowMilliseconds = ndn_getNowMilliseconds();
+ MillisecondsSince1970 nowMilliseconds = ndn_getNowMilliseconds();
for (int i = (int)pendingInterestTable_.size() - 1; i >= 0; --i) {
if (pendingInterestTable_[i]->checkTimeout(this, nowMilliseconds)) {
pendingInterestTable_.erase(pendingInterestTable_.begin() + i);
@@ -352,7 +352,7 @@
}
bool
-Node::PendingInterest::checkTimeout(Node *parent, double nowMilliseconds)
+Node::PendingInterest::checkTimeout(Node *parent, MillisecondsSince1970 nowMilliseconds)
{
if (timeoutTimeMilliseconds_ >= 0.0 && nowMilliseconds >= timeoutTimeMilliseconds_) {
if (onTimeout_) {
diff --git a/ndn-cpp/security/certificate/certificate.cpp b/ndn-cpp/security/certificate/certificate.cpp
index 9a01424..a1acfbf 100644
--- a/ndn-cpp/security/certificate/certificate.cpp
+++ b/ndn-cpp/security/certificate/certificate.cpp
@@ -45,7 +45,7 @@
bool
Certificate::isTooEarly()
{
- Time now = ndn_getNowMilliseconds();
+ MillisecondsSince1970 now = ndn_getNowMilliseconds();
if(now < notBefore_)
return true;
else
@@ -55,7 +55,7 @@
bool
Certificate::isTooLate()
{
- Time now = ndn_getNowMilliseconds();
+ MillisecondsSince1970 now = ndn_getNowMilliseconds();
if(now > notAfter_)
return true;
else
diff --git a/ndn-cpp/security/identity/identity-manager.cpp b/ndn-cpp/security/identity/identity-manager.cpp
index f5b4657..c5a7793 100644
--- a/ndn-cpp/security/identity/identity-manager.cpp
+++ b/ndn-cpp/security/identity/identity-manager.cpp
@@ -82,7 +82,7 @@
}
Name
-IdentityManager::createIdentityCertificate(const Name& keyName, const Name& signerCertificateName, const Time& notBefore, const Time& notAfter)
+IdentityManager::createIdentityCertificate(const Name& keyName, const Name& signerCertificateName, const MillisecondsSince1970& notBefore, const MillisecondsSince1970& notAfter)
{
Blob keyBlob = identityStorage_->getKey(keyName);
shared_ptr<PublicKey> publicKey = PublicKey::fromDer(keyBlob);
@@ -97,7 +97,7 @@
ptr_lib::shared_ptr<IdentityCertificate>
IdentityManager::createIdentityCertificate
- (const Name& keyName, const PublicKey& publicKey, const Name& signerCertificateName, const Time& notBefore, const Time& notAfter)
+ (const Name& keyName, const PublicKey& publicKey, const Name& signerCertificateName, const MillisecondsSince1970& notBefore, const MillisecondsSince1970& notAfter)
{
#if 0
shared_ptr<IdentityCertificate> certificate(new IdentityCertificate());
@@ -236,9 +236,9 @@
current.tm_hour = 0;
current.tm_min = 0;
current.tm_sec = 0;
- Time notBefore = boost::posix_time::ptime_from_tm(current);
+ MillisecondsSince1970 notBefore = boost::posix_time::ptime_from_tm(current);
current.tm_year = current.tm_year + 20;
- Time notAfter = boost::posix_time::ptime_from_tm(current);
+ MillisecondsSince1970 notAfter = boost::posix_time::ptime_from_tm(current);
certificate->setNotBefore(notBefore);
certificate->setNotAfter(notAfter);