repo: Watching prefix
Change-Id: Ia315d6e529fa4402ad9ca4706b70db1e75eb054c
Refs: #1784
diff --git a/src/repo-command-parameter.hpp b/src/repo-command-parameter.hpp
index 8a8c4bb..3c4cd54 100644
--- a/src/repo-command-parameter.hpp
+++ b/src/repo-command-parameter.hpp
@@ -33,6 +33,7 @@
using ndn::Selectors;
using ndn::EncodingEstimator;
using ndn::EncodingBuffer;
+using namespace ndn::time;
/**
* @brief Class defining abstraction of parameter of command for NDN Repo Protocol
@@ -57,6 +58,9 @@
, m_hasStartBlockId(false)
, m_hasEndBlockId(false)
, m_hasProcessId(false)
+ , m_hasMaxInterestNum(false)
+ , m_hasWatchTimeout(false)
+ , m_hasInterestLifetime(false)
{
}
@@ -158,12 +162,6 @@
return m_processId;
}
- bool
- hasProcessId() const
- {
- return m_hasProcessId;
- }
-
RepoCommandParameter&
setProcessId(uint64_t processId)
{
@@ -173,6 +171,78 @@
return *this;
}
+ bool
+ hasProcessId() const
+ {
+ return m_hasProcessId;
+ }
+
+ uint64_t
+ getMaxInterestNum() const
+ {
+ assert(hasMaxInterestNum());
+ return m_maxInterestNum;
+ }
+
+ RepoCommandParameter&
+ setMaxInterestNum(uint64_t maxInterestNum)
+ {
+ m_maxInterestNum = maxInterestNum;
+ m_hasMaxInterestNum = true;
+ m_wire.reset();
+ return *this;
+ }
+
+ bool
+ hasMaxInterestNum() const
+ {
+ return m_hasMaxInterestNum;
+ }
+
+ milliseconds
+ getWatchTimeout() const
+ {
+ assert(hasWatchTimeout());
+ return m_watchTimeout;
+ }
+
+ RepoCommandParameter&
+ setWatchTimeout(milliseconds watchTimeout)
+ {
+ m_watchTimeout = watchTimeout;
+ m_hasWatchTimeout = true;
+ m_wire.reset();
+ return *this;
+ }
+
+ bool
+ hasWatchTimeout() const
+ {
+ return m_hasWatchTimeout;
+ }
+
+ milliseconds
+ getInterestLifetime() const
+ {
+ assert(hasInterestLifetime());
+ return m_interestLifetime;
+ }
+
+ RepoCommandParameter&
+ setInterestLifetime(milliseconds interestLifetime)
+ {
+ m_interestLifetime = interestLifetime;
+ m_hasInterestLifetime = true;
+ m_wire.reset();
+ return *this;
+ }
+
+ bool
+ hasInterestLifetime() const
+ {
+ return m_hasInterestLifetime;
+ }
+
template<bool T>
size_t
wireEncode(EncodingImpl<T>& block) const;
@@ -190,11 +260,17 @@
uint64_t m_startBlockId;
uint64_t m_endBlockId;
uint64_t m_processId;
+ uint64_t m_maxInterestNum;
+ milliseconds m_watchTimeout;
+ milliseconds m_interestLifetime;
bool m_hasName;
bool m_hasStartBlockId;
bool m_hasEndBlockId;
bool m_hasProcessId;
+ bool m_hasMaxInterestNum;
+ bool m_hasWatchTimeout;
+ bool m_hasInterestLifetime;
mutable Block m_wire;
};
@@ -227,6 +303,27 @@
totalLength += encoder.prependVarNumber(tlv::StartBlockId);
}
+ if (m_hasMaxInterestNum) {
+ variableLength = encoder.prependNonNegativeInteger(m_maxInterestNum);
+ totalLength += variableLength;
+ totalLength += encoder.prependVarNumber(variableLength);
+ totalLength += encoder.prependVarNumber(tlv::MaxInterestNum);
+ }
+
+ if (m_hasWatchTimeout) {
+ variableLength = encoder.prependNonNegativeInteger(m_watchTimeout.count());
+ totalLength += variableLength;
+ totalLength += encoder.prependVarNumber(variableLength);
+ totalLength += encoder.prependVarNumber(tlv::WatchTimeout);
+ }
+
+ if (m_hasInterestLifetime) {
+ variableLength = encoder.prependNonNegativeInteger(m_interestLifetime.count());
+ totalLength += variableLength;
+ totalLength += encoder.prependVarNumber(variableLength);
+ totalLength += encoder.prependVarNumber(tlv::InterestLifetime);
+ }
+
if (!getSelectors().empty()) {
totalLength += getSelectors().wireEncode(encoder);
}
@@ -263,6 +360,9 @@
m_hasStartBlockId = false;
m_hasEndBlockId = false;
m_hasProcessId = false;
+ m_hasMaxInterestNum = false;
+ m_hasWatchTimeout = false;
+ m_hasInterestLifetime = false;
m_wire = wire;
@@ -312,6 +412,31 @@
m_processId = readNonNegativeInteger(*val);
}
+ // MaxInterestNum
+ val = m_wire.find(tlv::MaxInterestNum);
+ if (val != m_wire.elements_end())
+ {
+ m_hasMaxInterestNum = true;
+ m_maxInterestNum = readNonNegativeInteger(*val);
+ }
+
+ // WatchTimeout
+ val = m_wire.find(tlv::WatchTimeout);
+ if (val != m_wire.elements_end())
+ {
+ m_hasWatchTimeout = true;
+ m_watchTimeout = milliseconds(readNonNegativeInteger(*val));
+ }
+
+ // InterestLiftTime
+ val = m_wire.find(tlv::InterestLifetime);
+ if (val != m_wire.elements_end())
+ {
+ m_hasInterestLifetime = true;
+ m_interestLifetime = milliseconds(readNonNegativeInteger(*val));
+ }
+
+
}
inline std::ostream&
@@ -331,10 +456,22 @@
if (repoCommandParameter.hasEndBlockId()) {
os << " EndBlockId: " << repoCommandParameter.getEndBlockId();
}
- //ProcessId
+ // ProcessId
if (repoCommandParameter.hasProcessId()) {
os << " ProcessId: " << repoCommandParameter.getProcessId();
}
+ // MaxInterestNum
+ if (repoCommandParameter.hasMaxInterestNum()) {
+ os << " MaxInterestNum: " << repoCommandParameter.getMaxInterestNum();
+ }
+ // WatchTimeout
+ if (repoCommandParameter.hasProcessId()) {
+ os << " WatchTimeout: " << repoCommandParameter.getWatchTimeout();
+ }
+ // InterestLifetime
+ if (repoCommandParameter.hasProcessId()) {
+ os << " InterestLifetime: " << repoCommandParameter.getInterestLifetime();
+ }
os << " )";
return os;
}