face-management-protocol: Converting ForwardingEntry and ForwardingFlags to TLV
Change-Id: I84f60d8c0bc33b6631f7886238ed958aa020428f
diff --git a/include/ndn-cpp/forwarding-entry.hpp b/include/ndn-cpp/forwarding-entry.hpp
index b828a7b..9ac4df6 100644
--- a/include/ndn-cpp/forwarding-entry.hpp
+++ b/include/ndn-cpp/forwarding-entry.hpp
@@ -10,11 +10,8 @@
#include <string>
#include "name.hpp"
-#include "publisher-public-key-digest.hpp"
#include "forwarding-flags.hpp"
-#include "encoding/wire-format.hpp"
-
-struct ndn_ForwardingEntry;
+#include "encoding/block.hpp"
namespace ndn {
@@ -24,46 +21,39 @@
class ForwardingEntry {
public:
ForwardingEntry
- (const std::string& action, const Name& prefix, const PublisherPublicKeyDigest publisherPublicKeyDigest,
- int faceId, const ForwardingFlags& forwardingFlags, int freshnessSeconds)
- : action_(action), prefix_(prefix), publisherPublicKeyDigest_(publisherPublicKeyDigest),
- faceId_(faceId), forwardingFlags_(forwardingFlags), freshnessSeconds_(freshnessSeconds)
+ (const std::string& action,
+ const Name& prefix,
+ int faceId,
+ const ForwardingFlags& forwardingFlags,
+ int freshnessPeriod)
+ : action_(action)
+ , prefix_(prefix)
+ , faceId_(faceId)
+ , forwardingFlags_(forwardingFlags)
+ , freshnessPeriod_(freshnessPeriod)
{
}
ForwardingEntry()
- : faceId_(-1), freshnessSeconds_(-1)
+ : faceId_(-1), freshnessPeriod_(-1)
{
forwardingFlags_.setActive(true);
forwardingFlags_.setChildInherit(true);
}
- Blob
- wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
+ Block
+ wireEncode() const
{
- return wireFormat.encodeForwardingEntry(*this);
+ return wire_;
+ // return wireFormat.encodeForwardingEntry(*this);
}
void
- wireDecode(const uint8_t *input, size_t inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
+ wireDecode(const Block &wire)
{
- wireFormat.decodeForwardingEntry(*this, input, inputLength);
+ // wireFormat.decodeForwardingEntry(*this, input, inputLength);
}
- void
- wireDecode(const std::vector<uint8_t>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
- {
- wireDecode(&input[0], input.size(), wireFormat);
- }
-
- /**
- * Set the forwardingEntryStruct to point to the components in this forwarding entry, without copying any memory.
- * WARNING: The resulting pointers in forwardingEntryStruct are invalid after a further use of this object which could reallocate memory.
- * @param forwardingEntryStruct a C ndn_ForwardingEntry struct where the prefix name components array is already allocated.
- */
- void
- get(struct ndn_ForwardingEntry& forwardingEntryStruct) const;
-
const std::string&
getAction() const { return action_; }
@@ -73,12 +63,6 @@
const Name&
getPrefix() const { return prefix_; }
- PublisherPublicKeyDigest&
- getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
-
- const PublisherPublicKeyDigest&
- getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
-
int
getFaceId() const { return faceId_; }
@@ -86,14 +70,7 @@
getForwardingFlags() const { return forwardingFlags_; }
int
- getFreshnessSeconds() const { return freshnessSeconds_; }
-
- /**
- * Clear this forwarding entry, and set the values by copying from forwardingEntryStruct.
- * @param forwardingEntryStruct a C ndn_ForwardingEntry struct.
- */
- void
- set(const struct ndn_ForwardingEntry& forwardingEntryStruct);
+ getFreshnessPeriod() const { return freshnessPeriod_; }
void
setAction(const std::string& action) { action_ = action; }
@@ -105,15 +82,16 @@
setForwardingFlags(const ForwardingFlags& forwardingFlags) { forwardingFlags_ = forwardingFlags; }
void
- setFreshnessSeconds(int freshnessSeconds) { freshnessSeconds_ = freshnessSeconds; }
+ setFreshnessPeriod(int freshnessPeriod) { freshnessPeriod_ = freshnessPeriod; }
private:
std::string action_; /**< empty for none. */
Name prefix_;
- PublisherPublicKeyDigest publisherPublicKeyDigest_;
int faceId_; /**< -1 for none. */
ForwardingFlags forwardingFlags_;
- int freshnessSeconds_; /**< -1 for none. */
+ int freshnessPeriod_; /**< -1 for none. */
+
+ Block wire_;
};
}
diff --git a/include/ndn-cpp/forwarding-flags.hpp b/include/ndn-cpp/forwarding-flags.hpp
index 7c878b9..e0b91a9 100644
--- a/include/ndn-cpp/forwarding-flags.hpp
+++ b/include/ndn-cpp/forwarding-flags.hpp
@@ -8,8 +8,6 @@
#ifndef NDN_FORWARDING_FLAGS_HPP
#define NDN_FORWARDING_FLAGS_HPP
-#include "c/forwarding-flags.h"
-
namespace ndn {
/**
@@ -17,18 +15,21 @@
* a registered prefix. We use a separate ForwardingFlags object to retain future compatibility if the daemon forwarding
* bits are changed, amended or deprecated.
*/
-class ForwardingFlags : public ndn_ForwardingFlags {
+class ForwardingFlags {
public:
/**
* Create a new ForwardingFlags with "active" and "childInherit" set and all other flags cleared.
*/
ForwardingFlags()
- {
- ndn_ForwardingFlags_initialize(this);
- }
-
- ForwardingFlags(const struct ndn_ForwardingFlags &forwardingFlagsStruct)
- : ndn_ForwardingFlags(forwardingFlagsStruct)
+ : active_(true)
+ , childInherit_(true)
+ , advertise_(false)
+ , last_(false)
+ , capture_(false)
+ , local_(false)
+ , tap_(false)
+ , captureOk_(false)
+
{
}
@@ -36,97 +37,107 @@
* Get the value of the "active" flag.
* @return true if the flag is set, false if it is cleared.
*/
- bool getActive() const { return active; }
+ bool getActive() const { return active_; }
/**
* Get the value of the "childInherit" flag.
* @return true if the flag is set, false if it is cleared.
*/
- bool getChildInherit() const { return childInherit; }
+ bool getChildInherit() const { return childInherit_; }
/**
* Get the value of the "advertise" flag.
* @return true if the flag is set, false if it is cleared.
*/
- bool getAdvertise() const { return advertise; }
+ bool getAdvertise() const { return advertise_; }
/**
* Get the value of the "last" flag.
* @return true if the flag is set, false if it is cleared.
*/
- bool getLast() const { return last; }
+ bool getLast() const { return last_; }
/**
* Get the value of the "capture" flag.
* @return true if the flag is set, false if it is cleared.
*/
- bool getCapture() const { return capture; }
+ bool getCapture() const { return capture_; }
/**
* Get the value of the "local" flag.
* @return true if the flag is set, false if it is cleared.
*/
- bool getLocal() const { return local; }
+ bool getLocal() const { return local_; }
/**
* Get the value of the "tap" flag.
* @return true if the flag is set, false if it is cleared.
*/
- bool getTap() const { return tap; }
+ bool getTap() const { return tap_; }
/**
* Get the value of the "captureOk" flag.
* @return true if the flag is set, false if it is cleared.
*/
- bool getCaptureOk() const { return captureOk; }
+ bool getCaptureOk() const { return captureOk_; }
/**
* Set the value of the "active" flag
* @param active true to set the flag, false to clear it.
*/
- void setActive(bool active) { this->active = active ? 1 : 0; }
+ void setActive(bool active) { this->active_ = active; }
/**
* Set the value of the "childInherit" flag
* @param childInherit true to set the flag, false to clear it.
*/
- void setChildInherit(bool childInherit) { this->childInherit = childInherit ? 1 : 0; }
+ void setChildInherit(bool childInherit) { this->childInherit_ = childInherit; }
/**
* Set the value of the "advertise" flag
* @param advertise true to set the flag, false to clear it.
*/
- void setAdvertise(bool advertise) { this->advertise = advertise ? 1 : 0; }
+ void setAdvertise(bool advertise) { this->advertise_ = advertise; }
/**
* Set the value of the "last" flag
* @param last true to set the flag, false to clear it.
*/
- void setLast(bool last) { this->last = last ? 1 : 0; }
+ void setLast(bool last) { this->last_ = last; }
/**
* Set the value of the "capture" flag
* @param capture true to set the flag, false to clear it.
*/
- void setCapture(bool capture) { this->capture = capture ? 1 : 0; }
+ void setCapture(bool capture) { this->capture_ = capture; }
/**
* Set the value of the "local" flag
* @param local true to set the flag, false to clear it.
*/
- void setLocal(bool local) { this->local = local ? 1 : 0; }
+ void setLocal(bool local) { this->local_ = local; }
/**
* Set the value of the "tap" flag
* @param tap true to set the flag, false to clear it.
*/
- void setTap(bool tap) { this->tap = tap ? 1 : 0; }
+ void setTap(bool tap) { this->tap_ = tap; }
/**
* Set the value of the "captureOk" flag
* @param captureOk true to set the flag, false to clear it.
*/
- void setCaptureOk(bool captureOk) { this->captureOk = captureOk ? 1 : 0; }
+ void setCaptureOk(bool captureOk) { this->captureOk_ = captureOk; }
+
+private:
+ bool active_;
+ bool childInherit_;
+ bool advertise_;
+ bool last_;
+ bool capture_;
+ bool local_;
+ bool tap_;
+ bool captureOk_;
};
}