Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef NDN_INTEREST_HPP |
| 7 | #define NDN_INTEREST_HPP |
| 8 | |
| 9 | #include <vector> |
| 10 | #include "Name.hpp" |
| 11 | #include "c/Interest.h" |
| 12 | |
| 13 | namespace ndn { |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame^] | 14 | |
| 15 | class ExcludeEntry { |
| 16 | public: |
| 17 | /** |
| 18 | * Create an ExcludeEntry of type ndn_Exclude_ANY |
| 19 | */ |
| 20 | ExcludeEntry() |
| 21 | : type_(ndn_Exclude_ANY) |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Create an ExcludeEntry of type ndn_Exclude_COMPONENT |
| 27 | */ |
| 28 | ExcludeEntry(unsigned char *component, unsigned int componentLen) |
| 29 | : type_(ndn_Exclude_COMPONENT), component_(component, component + componentLen) |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Set the type in the excludeEntryStruct and to point to this component, without copying any memory. |
| 35 | * WARNING: The resulting pointer in excludeEntryStruct is invalid after a further use of this object which could reallocate memory. |
| 36 | * @param excludeEntryStruct the C ndn_NameComponent struct to receive the pointer. |
| 37 | */ |
| 38 | void get(struct ndn_ExcludeEntry &excludeEntryStruct) const |
| 39 | { |
| 40 | excludeEntryStruct.type = type_; |
| 41 | if (type_ == ndn_Exclude_COMPONENT) { |
| 42 | excludeEntryStruct.componentLength = component_.size(); |
| 43 | excludeEntryStruct.component = (unsigned char *)&component_[0]; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | ndn_ExcludeType getType() const { return type_; } |
| 48 | |
| 49 | const std::vector<unsigned char> &getComponent() const { return component_; } |
| 50 | |
| 51 | private: |
| 52 | ndn_ExcludeType type_; |
| 53 | std::vector<unsigned char> component_; /**< only used if type_ is ndn_Exclude_COMPONENT */ |
| 54 | }; |
| 55 | |
| 56 | class Exclude { |
| 57 | public: |
| 58 | /** |
| 59 | * Create a new Exclude with no entries. |
| 60 | */ |
| 61 | Exclude() { |
| 62 | } |
| 63 | |
| 64 | unsigned int getEntryCount() const { |
| 65 | return entries_.size(); |
| 66 | } |
| 67 | |
| 68 | const ExcludeEntry &getEntry(unsigned int i) const { return entries_[i]; } |
| 69 | |
| 70 | /** |
| 71 | * Set the excludeStruct to point to the entries in this exclude, without copying any memory. |
| 72 | * WARNING: The resulting pointers in excludeStruct are invalid after a further use of this object which could reallocate memory. |
| 73 | * @param excludeStruct a C ndn_Exclude struct where the entries array is already allocated. |
| 74 | */ |
| 75 | void get(struct ndn_Exclude &excludeStruct) const; |
| 76 | |
| 77 | /** |
| 78 | * Clear this exclude, and set the entries by copying from the ndn_Exclude struct. |
| 79 | * @param excludeStruct a C ndn_Exclude struct |
| 80 | */ |
| 81 | void set(struct ndn_Exclude &excludeStruct); |
| 82 | |
| 83 | /** |
| 84 | * Add a new entry of type ndn_Exclude_ANY |
| 85 | */ |
| 86 | void addAny() |
| 87 | { |
| 88 | entries_.push_back(ExcludeEntry()); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Add a new entry of type ndn_Exclude_COMPONENT, copying from component of length compnentLength |
| 93 | */ |
| 94 | void addComponent(unsigned char *component, unsigned int componentLen) |
| 95 | { |
| 96 | entries_.push_back(ExcludeEntry(component, componentLen)); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Clear all the entries. |
| 101 | */ |
| 102 | void clear() { |
| 103 | entries_.clear(); |
| 104 | } |
| 105 | |
| 106 | private: |
| 107 | std::vector<ExcludeEntry> entries_; |
| 108 | }; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 109 | |
| 110 | class Interest { |
| 111 | public: |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 112 | void encode(std::vector<unsigned char> &output, WireFormat &wireFormat) const |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 113 | { |
| 114 | wireFormat.encodeInterest(*this, output); |
| 115 | } |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 116 | void encode(std::vector<unsigned char> &output) const |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 117 | { |
| 118 | encode(output, BinaryXMLWireFormat::instance()); |
| 119 | } |
| 120 | void decode(const unsigned char *input, unsigned int inputLength, WireFormat &wireFormat) |
| 121 | { |
| 122 | wireFormat.decodeInterest(*this, input, inputLength); |
| 123 | } |
| 124 | void decode(const unsigned char *input, unsigned int inputLength) |
| 125 | { |
| 126 | decode(input, inputLength, BinaryXMLWireFormat::instance()); |
| 127 | } |
| 128 | void decode(const std::vector<unsigned char> &input, WireFormat &wireFormat) |
| 129 | { |
| 130 | decode(&input[0], input.size(), wireFormat); |
| 131 | } |
| 132 | void decode(const std::vector<unsigned char> &input) |
| 133 | { |
| 134 | decode(&input[0], input.size()); |
| 135 | } |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 136 | |
| 137 | /** |
| 138 | * Set the interestStruct to point to the components in this interest, without copying any memory. |
| 139 | * WARNING: The resulting pointers in interestStruct are invalid after a further use of this object which could reallocate memory. |
| 140 | * @param interestStruct a C ndn_Interest struct where the name components array is already allocated. |
| 141 | */ |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 142 | void get(struct ndn_Interest &interestStruct) const; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 143 | |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 144 | const Name &getName() const { return name_; } |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 145 | |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 146 | int getMinSuffixComponents() const { return minSuffixComponents_; } |
| 147 | |
| 148 | int getMaxSuffixComponents() const { return maxSuffixComponents_; } |
Jeff Thompson | 0a68172 | 2013-07-08 16:21:54 -0700 | [diff] [blame] | 149 | |
| 150 | const std::vector<unsigned char> getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; } |
| 151 | |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame^] | 152 | const Exclude &getExclude() const { return exclude_; } |
Jeff Thompson | 0a68172 | 2013-07-08 16:21:54 -0700 | [diff] [blame] | 153 | |
| 154 | int getChildSelector() const { return childSelector_; } |
| 155 | |
| 156 | int getAnswerOriginKind() const { return answerOriginKind_; } |
| 157 | |
| 158 | int getScope() const { return scope_; } |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 159 | |
| 160 | int getInterestLifetime() const { return interestLifetime_; } |
Jeff Thompson | 0a68172 | 2013-07-08 16:21:54 -0700 | [diff] [blame] | 161 | |
| 162 | const std::vector<unsigned char> getNonce() const { return nonce_; } |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 163 | |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 164 | /** |
| 165 | * Clear this interest, and set the values by copying from the interest struct. |
| 166 | * @param interestStruct a C ndn_Interest struct |
| 167 | */ |
| 168 | void set(struct ndn_Interest &interestStruct); |
| 169 | |
| 170 | private: |
| 171 | |
| 172 | Name name_; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 173 | int minSuffixComponents_; |
Jeff Thompson | f2e5e28 | 2013-07-08 15:26:16 -0700 | [diff] [blame] | 174 | int maxSuffixComponents_; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 175 | std::vector<unsigned char> publisherPublicKeyDigest_; |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame^] | 176 | Exclude exclude_; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 177 | int childSelector_; |
| 178 | int answerOriginKind_; |
| 179 | int scope_; |
| 180 | int interestLifetime_; |
| 181 | std::vector<unsigned char> nonce_; |
| 182 | }; |
| 183 | |
| 184 | } |
| 185 | |
| 186 | #endif |