blob: 73a94848dd442190bb64973f5548f924eb0590e3 [file] [log] [blame]
/**
* Copyright (C) 2013 Regents of the University of California.
* @author: Jeff Thompson <jefft0@remap.ucla.edu>
* See COPYING for copyright and distribution information.
*/
#ifndef NDN_FORWARDING_ENTRY_HPP
#define NDN_FORWARDING_ENTRY_HPP
#include <string>
#include "name.hpp"
#include "publisher-public-key-digest.hpp"
#include "c/forwarding-entry.h"
namespace ndn {
/**
* An ForwardingEntry holds an action and Name prefix and other fields for an forwarding entry.
*/
class ForwardingEntry {
public:
ForwardingEntry
(const std::string& action, const Name& prefix, const PublisherPublicKeyDigest publisherPublicKeyDigest,
int faceId, int forwardingFlags, int freshnessSeconds)
: action_(action), prefix_(prefix), publisherPublicKeyDigest_(publisherPublicKeyDigest),
faceId_(faceId), forwardingFlags_(forwardingFlags), freshnessSeconds_(freshnessSeconds)
{
}
ForwardingEntry()
: faceId_(-1), forwardingFlags_(-1), freshnessSeconds_(-1)
{
}
Blob
wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
{
return wireFormat.encodeForwardingEntry(*this);
}
void
wireDecode(const uint8_t *input, unsigned int inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
{
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_; }
Name&
getPrefix() { return prefix_; }
const Name&
getPrefix() const { return prefix_; }
PublisherPublicKeyDigest&
getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
const PublisherPublicKeyDigest&
getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
int
getFaceId() const { return faceId_; }
int
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);
void
setAction(const std::string& value) { action_ = value; }
void
setFaceId(int value) { faceId_ = value; }
void
setForwardingFlags(int value) { forwardingFlags_ = value; }
void
setFreshnessSeconds(int value) { freshnessSeconds_ = value; }
private:
std::string action_; /**< empty for none. */
Name prefix_;
PublisherPublicKeyDigest publisherPublicKeyDigest_;
int faceId_; /**< -1 for none. */
int forwardingFlags_; /**< -1 for none. */
int freshnessSeconds_; /**< -1 for none. */
};
}
#endif