blob: 8c652a77a46f29087936d473d13f6632537a20ff [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
22 (const std::string &action, const Name &prefix, const PublisherPublicKeyDigest publisherPublicKeyDigest,
23 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
34 ptr_lib::shared_ptr<std::vector<unsigned char> > wireEncode(WireFormat &wireFormat) const
35 {
36 return wireFormat.encodeForwardingEntry(*this);
37 }
38 ptr_lib::shared_ptr<std::vector<unsigned char> > wireEncode() const
39 {
40 return wireEncode(*WireFormat::getDefaultWireFormat());
41 }
42 void wireDecode(const unsigned char *input, unsigned int inputLength, WireFormat &wireFormat)
43 {
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 }
50 void wireDecode(const std::vector<unsigned char> &input, WireFormat &wireFormat)
51 {
52 wireDecode(&input[0], input.size(), wireFormat);
53 }
54 void wireDecode(const std::vector<unsigned char> &input)
55 {
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 */
64 void get(struct ndn_ForwardingEntry &forwardingEntryStruct) const;
65
66 const std::string &getAction() const { return action_; }
67
68 Name &getPrefix() { return prefix_; }
69 const Name &getPrefix() const { return prefix_; }
70
71 PublisherPublicKeyDigest &getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
72 const PublisherPublicKeyDigest &getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
73
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 */
84 void set(const struct ndn_ForwardingEntry &forwardingEntryStruct);
85
86 void setAction(const std::string &value) { action_ = value; }
87
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