blob: 177e5c4c8d7c32de3ebd2093f74f97c70fdeae21 [file] [log] [blame]
Jeff Thompson990599b2013-08-27 15:14:25 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
4 */
5
6#ifndef NDN_FORWARDING_ENTRY_HPP
7#define NDN_FORWARDING_ENTRY_HPP
8
9#include <string>
10#include "name.hpp"
11#include "publisher-public-key-digest.hpp"
12#include "c/forwarding-entry.h"
13
14namespace ndn {
15
16/**
17 * An ForwardingEntry holds an action and Name prefix and other fields for an forwarding entry.
18 */
19class ForwardingEntry {
20public:
21 ForwardingEntry
Jeff Thompson1656e6a2013-08-29 18:01:48 -070022 (const std::string& action, const Name& prefix, const PublisherPublicKeyDigest publisherPublicKeyDigest,
Jeff Thompson990599b2013-08-27 15:14:25 -070023 int faceId, int forwardingFlags, int freshnessSeconds)
24 : action_(action), prefix_(prefix), publisherPublicKeyDigest_(publisherPublicKeyDigest),
25 faceId_(faceId), forwardingFlags_(forwardingFlags), freshnessSeconds_(freshnessSeconds)
26 {
27 }
28
29 ForwardingEntry()
30 : faceId_(-1), forwardingFlags_(-1), freshnessSeconds_(-1)
31 {
32 }
33
Jeff Thompsonc2b7b142013-09-12 15:29:04 -070034 Blob wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
Jeff Thompson990599b2013-08-27 15:14:25 -070035 {
36 return wireFormat.encodeForwardingEntry(*this);
37 }
Jeff Thompsonc2b7b142013-09-12 15:29:04 -070038 void wireDecode(const unsigned char *input, unsigned int inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
Jeff Thompson990599b2013-08-27 15:14:25 -070039 {
40 wireFormat.decodeForwardingEntry(*this, input, inputLength);
41 }
Jeff Thompsonc2b7b142013-09-12 15:29:04 -070042 void wireDecode(const std::vector<unsigned char>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
Jeff Thompson990599b2013-08-27 15:14:25 -070043 {
44 wireDecode(&input[0], input.size(), wireFormat);
45 }
Jeff Thompson990599b2013-08-27 15:14:25 -070046
47 /**
48 * Set the forwardingEntryStruct to point to the components in this forwarding entry, without copying any memory.
49 * WARNING: The resulting pointers in forwardingEntryStruct are invalid after a further use of this object which could reallocate memory.
50 * @param forwardingEntryStruct a C ndn_ForwardingEntry struct where the prefix name components array is already allocated.
51 */
Jeff Thompson1656e6a2013-08-29 18:01:48 -070052 void get(struct ndn_ForwardingEntry& forwardingEntryStruct) const;
Jeff Thompson990599b2013-08-27 15:14:25 -070053
Jeff Thompson1656e6a2013-08-29 18:01:48 -070054 const std::string& getAction() const { return action_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070055
Jeff Thompson1656e6a2013-08-29 18:01:48 -070056 Name& getPrefix() { return prefix_; }
57 const Name& getPrefix() const { return prefix_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070058
Jeff Thompson1656e6a2013-08-29 18:01:48 -070059 PublisherPublicKeyDigest& getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
60 const PublisherPublicKeyDigest& getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070061
62 int getFaceId() const { return faceId_; }
63
64 int getForwardingFlags() const { return forwardingFlags_; }
65
66 int getFreshnessSeconds() const { return freshnessSeconds_; }
67
68 /**
69 * Clear this forwarding entry, and set the values by copying from forwardingEntryStruct.
70 * @param forwardingEntryStruct a C ndn_ForwardingEntry struct.
71 */
Jeff Thompson1656e6a2013-08-29 18:01:48 -070072 void set(const struct ndn_ForwardingEntry& forwardingEntryStruct);
Jeff Thompson990599b2013-08-27 15:14:25 -070073
Jeff Thompson1656e6a2013-08-29 18:01:48 -070074 void setAction(const std::string& value) { action_ = value; }
Jeff Thompson990599b2013-08-27 15:14:25 -070075
76 void setFaceId(int value) { faceId_ = value; }
77
78 void setForwardingFlags(int value) { forwardingFlags_ = value; }
79
80 void setFreshnessSeconds(int value) { freshnessSeconds_ = value; }
81
82 std::string action_; /**< empty for none. */
83 Name prefix_;
84 PublisherPublicKeyDigest publisherPublicKeyDigest_;
85 int faceId_; /**< -1 for none. */
86 int forwardingFlags_; /**< -1 for none. */
87 int freshnessSeconds_; /**< -1 for none. */
88};
89
90}
91
92#endif