blob: 9919f49f3b11e5e6d0d6565f26687bce8ae06662 [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 Thompson1656e6a2013-08-29 18:01:48 -070034 ptr_lib::shared_ptr<std::vector<unsigned char> > wireEncode(WireFormat& wireFormat) const
Jeff Thompson990599b2013-08-27 15:14:25 -070035 {
36 return wireFormat.encodeForwardingEntry(*this);
37 }
38 ptr_lib::shared_ptr<std::vector<unsigned char> > wireEncode() const
39 {
40 return wireEncode(*WireFormat::getDefaultWireFormat());
41 }
Jeff Thompson1656e6a2013-08-29 18:01:48 -070042 void wireDecode(const unsigned char *input, unsigned int inputLength, WireFormat& wireFormat)
Jeff Thompson990599b2013-08-27 15:14:25 -070043 {
44 wireFormat.decodeForwardingEntry(*this, input, inputLength);
45 }
46 void wireDecode(const unsigned char *input, unsigned int inputLength)
47 {
48 wireDecode(input, inputLength, *WireFormat::getDefaultWireFormat());
49 }
Jeff Thompson1656e6a2013-08-29 18:01:48 -070050 void wireDecode(const std::vector<unsigned char>& input, WireFormat& wireFormat)
Jeff Thompson990599b2013-08-27 15:14:25 -070051 {
52 wireDecode(&input[0], input.size(), wireFormat);
53 }
Jeff Thompson1656e6a2013-08-29 18:01:48 -070054 void wireDecode(const std::vector<unsigned char>& input)
Jeff Thompson990599b2013-08-27 15:14:25 -070055 {
56 wireDecode(&input[0], input.size());
57 }
58
59 /**
60 * Set the forwardingEntryStruct to point to the components in this forwarding entry, without copying any memory.
61 * WARNING: The resulting pointers in forwardingEntryStruct are invalid after a further use of this object which could reallocate memory.
62 * @param forwardingEntryStruct a C ndn_ForwardingEntry struct where the prefix name components array is already allocated.
63 */
Jeff Thompson1656e6a2013-08-29 18:01:48 -070064 void get(struct ndn_ForwardingEntry& forwardingEntryStruct) const;
Jeff Thompson990599b2013-08-27 15:14:25 -070065
Jeff Thompson1656e6a2013-08-29 18:01:48 -070066 const std::string& getAction() const { return action_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070067
Jeff Thompson1656e6a2013-08-29 18:01:48 -070068 Name& getPrefix() { return prefix_; }
69 const Name& getPrefix() const { return prefix_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070070
Jeff Thompson1656e6a2013-08-29 18:01:48 -070071 PublisherPublicKeyDigest& getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
72 const PublisherPublicKeyDigest& getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
Jeff Thompson990599b2013-08-27 15:14:25 -070073
74 int getFaceId() const { return faceId_; }
75
76 int getForwardingFlags() const { return forwardingFlags_; }
77
78 int getFreshnessSeconds() const { return freshnessSeconds_; }
79
80 /**
81 * Clear this forwarding entry, and set the values by copying from forwardingEntryStruct.
82 * @param forwardingEntryStruct a C ndn_ForwardingEntry struct.
83 */
Jeff Thompson1656e6a2013-08-29 18:01:48 -070084 void set(const struct ndn_ForwardingEntry& forwardingEntryStruct);
Jeff Thompson990599b2013-08-27 15:14:25 -070085
Jeff Thompson1656e6a2013-08-29 18:01:48 -070086 void setAction(const std::string& value) { action_ = value; }
Jeff Thompson990599b2013-08-27 15:14:25 -070087
88 void setFaceId(int value) { faceId_ = value; }
89
90 void setForwardingFlags(int value) { forwardingFlags_ = value; }
91
92 void setFreshnessSeconds(int value) { freshnessSeconds_ = value; }
93
94 std::string action_; /**< empty for none. */
95 Name prefix_;
96 PublisherPublicKeyDigest publisherPublicKeyDigest_;
97 int faceId_; /**< -1 for none. */
98 int forwardingFlags_; /**< -1 for none. */
99 int freshnessSeconds_; /**< -1 for none. */
100};
101
102}
103
104#endif