control-parameters.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_CONTROL_PARAMETERS_HPP
23 #define NDN_CONTROL_PARAMETERS_HPP
24 
25 #include "name.hpp"
26 #include "forwarding-flags.hpp"
27 #include "encoding/wire-format.hpp"
28 
30 
31 namespace ndn {
32 
39 public:
41  : hasName_(false), faceId_(-1), localControlFeature_(-1), origin_(-1), cost_(-1),
42  expirationPeriod_(-1.0)
43  {
44  }
45 
46  Blob
47  wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
48  {
49  return wireFormat.encodeControlParameters(*this);
50  }
51 
52  void
53  wireDecode(const uint8_t *input, size_t inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
54  {
55  wireFormat.decodeControlParameters(*this, input, inputLength);
56  }
57 
58  void
59  wireDecode(const std::vector<uint8_t>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
60  {
61  wireDecode(&input[0], input.size(), wireFormat);
62  }
63 
64  void
65  wireDecode
66  (const Blob& input,
68  {
69  wireDecode(input.buf(), input.size(), wireFormat);
70  }
71 
80  void
81  get(struct ndn_ControlParameters& controlParametersStruct) const;
82 
87  bool
88  getHasName() const { return hasName_; }
89 
94  const Name&
95  getName() const { return name_; }
96 
97  int
98  getFaceId() const { return faceId_; }
99 
100  const std::string&
101  getUri() const { return uri_; }
102 
103  int
104  getLocalControlFeature() const { return localControlFeature_; }
105 
106  int
107  getOrigin() const { return origin_; }
108 
109  int
110  getCost() const { return cost_; }
111 
112  ForwardingFlags&
113  getForwardingFlags() { return flags_; }
114 
115  const ForwardingFlags&
116  getForwardingFlags() const { return flags_; }
117 
118  Name&
119  getStrategy() { return strategy_; }
120 
121  const Name&
122  getStrategy() const { return strategy_; }
123 
125  getExpirationPeriod() const { return expirationPeriod_; }
126 
133  void
134  set(const struct ndn_ControlParameters& controlParametersStruct);
135 
141  void
142  setHasName(bool hasName) { hasName_ = hasName; }
143 
151  setName(const Name& name)
152  {
153  hasName_ = true;
154  name_ = name;
155  return *this;
156  }
157 
165  {
166  faceId_ = faceId;
167  return *this;
168  }
169 
176  setUri(const std::string& uri)
177  {
178  uri_ = uri;
179  return *this;
180  }
181 
190  {
191  localControlFeature_ = localControlFeature;
192  return *this;
193  }
194 
202  {
203  origin_ = origin;
204  return *this;
205  }
206 
214  {
215  cost_ = cost;
216  return *this;
217  }
218 
227  {
228  flags_ = flags;
229  return *this;
230  }
231 
239  {
240  strategy_ = strategy;
241  return *this;
242  }
243 
252  {
253  expirationPeriod_ = expirationPeriod;
254  return *this;
255  }
256 
257 private:
258  bool hasName_;
259  Name name_;
260  int faceId_;
261  std::string uri_;
262  int localControlFeature_;
263  int origin_;
264  int cost_;
265  ForwardingFlags flags_;
266  Name strategy_;
267  Milliseconds expirationPeriod_;
268 };
269 
270 }
271 
272 #endif
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:111
const Name & getName() const
Get the name, if specified.
Definition: control-parameters.hpp:95
Copyright (C) 2013-2015 Regents of the University of California.
Definition: common.hpp:35
int cost
-1 for none.
Definition: control-parameters.h:49
struct ndn_Name strategy
nComponents == 0 for none.
Definition: control-parameters.h:51
ControlParameters & setLocalControlFeature(int localControlFeature)
Set the local control feature value.
Definition: control-parameters.hpp:189
A ForwardingFlags object holds the flags which specify how the forwarding daemon should forward an in...
Definition: forwarding-flags.hpp:34
ControlParameters & setForwardingFlags(const ForwardingFlags &flags)
Set the ForwardingFlags object to a copy of forwardingFlags.
Definition: control-parameters.hpp:226
int localControlFeature
-1 for none.
Definition: control-parameters.h:47
ControlParameters & setName(const Name &name)
Set the name.
Definition: control-parameters.hpp:151
struct ndn_Blob uri
A Blob whose value is a pointer to pre-allocated buffer.
Definition: control-parameters.h:45
ControlParameters & setOrigin(int origin)
Set the origin value.
Definition: control-parameters.hpp:201
ControlParameters & setStrategy(const Name &strategy)
Set the strategy to a copy of the given Name.
Definition: control-parameters.hpp:238
A ControlParameters holds a Name and other fields for a ControlParameters which is used...
Definition: control-parameters.hpp:38
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:42
A Blob holds a pointer to an immutable byte array implemented as const std::vector.
Definition: blob.hpp:42
const uint8_t * buf() const
Return a const pointer to the first byte of the immutable byte array, or 0 if the pointer is null...
Definition: blob.hpp:138
size_t size() const
Return the length of the immutable byte array.
Definition: blob.hpp:126
int faceId
-1 for none.
Definition: control-parameters.h:44
ControlParameters & setCost(int cost)
Set the cost value.
Definition: control-parameters.hpp:213
ControlParameters & setFaceId(int faceId)
Set the Face ID.
Definition: control-parameters.hpp:164
static WireFormat * getDefaultWireFormat()
Return the default WireFormat used by default encoding and decoding methods which was set with setDef...
Definition: wire-format.cpp:36
int origin
-1 for none.
Definition: control-parameters.h:48
void set(const struct ndn_ControlParameters &controlParametersStruct)
Clear this ControlParameters, and set the values by copying from controlParametersStruct.
Definition: control-parameters.cpp:51
ControlParameters & setUri(const std::string &uri)
Set the URI.
Definition: control-parameters.hpp:176
void setHasName(bool hasName)
Set the flag for whether the name is specified.
Definition: control-parameters.hpp:142
Definition: wire-format.hpp:37
An ndn_ControlParameters holds fields for a ControlParameters which is used in the command interest s...
Definition: control-parameters.h:41
struct ndn_Name name
Only used if hasName.
Definition: control-parameters.h:43
ControlParameters & setExpirationPeriod(Milliseconds expirationPeriod)
Set the expiration period.
Definition: control-parameters.hpp:251
bool getHasName() const
Check if the name is specified.
Definition: control-parameters.hpp:88
ndn_Milliseconds expirationPeriod
-1 for none.
Definition: control-parameters.h:52