control-response.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_CONTROL_RESPONSE_HPP
23 #define NDN_CONTROL_RESPONSE_HPP
24 
25 #include "control-parameters.hpp"
26 #include "encoding/wire-format.hpp"
27 #include "lite/control-response-lite.hpp"
28 
29 namespace ndn {
30 
38 public:
43  : statusCode_(-1)
44  {
45  }
46 
51  ControlResponse(const ControlResponse& controlResponse)
52  : statusCode_(controlResponse.statusCode_),
53  statusText_(controlResponse.statusText_)
54  {
55  if (controlResponse.bodyAsControlParameters_)
56  bodyAsControlParameters_.reset
57  (new ControlParameters(*controlResponse.bodyAsControlParameters_));
58  }
59 
66  Blob
68  {
69  return wireFormat.encodeControlResponse(*this);
70  }
71 
80  void
82  (const uint8_t *input, size_t inputLength,
84  {
85  wireFormat.decodeControlResponse(*this, input, inputLength);
86  }
87 
95  void
97  (const std::vector<uint8_t>& input,
99  {
100  wireDecode(&input[0], input.size(), wireFormat);
101  }
102 
110  void
111  wireDecode
112  (const Blob& input,
114  {
115  wireDecode(input.buf(), input.size(), wireFormat);
116  }
117 
126  void
127  get(ControlResponseLite& controlResponseLite) const;
128 
134  void
135  set(const ControlResponseLite& controlResponseLite);
136 
141  int
142  getStatusCode() const { return statusCode_; }
143 
148  const std::string&
149  getStatusText() const { return statusText_; }
150 
156  const ControlParameters*
157  getBodyAsControlParameters() const { return bodyAsControlParameters_.get(); }
158 
165  setStatusCode(int statusCode)
166  {
167  statusCode_ = statusCode;
168  return *this;
169  }
170 
177  setStatusText(const std::string& statusText)
178  {
179  statusText_ = statusText;
180  return *this;
181  }
182 
192  {
193  if (controlParameters)
194  bodyAsControlParameters_.reset
195  (new ControlParameters(*controlParameters));
196  else
197  bodyAsControlParameters_.reset();
198  return *this;
199  }
200 
201 private:
202  int statusCode_;
203  std::string statusText_;
204  ptr_lib::shared_ptr<ControlParameters> bodyAsControlParameters_;
205 };
206 
207 }
208 
209 #endif
ControlResponse(const ControlResponse &controlResponse)
Create a new ControlResponse as a deep copy of the given ControlResponse.
Definition: control-response.hpp:51
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
A ControlResponseLite holds a status code, status text and other fields for a ControlResponse which i...
Definition: control-response-lite.hpp:35
A ControlResponse holds a status code, status text and other fields for a ControlResponse which is us...
Definition: control-response.hpp:37
ControlResponse & setBodyAsControlParameters(const ControlParameters *controlParameters)
Set the control response body as a ControlParameters.
Definition: control-response.hpp:191
A ControlParameters holds a Name and other fields for a ControlParameters which is used...
Definition: control-parameters.hpp:37
int getStatusCode() const
Get the status code.
Definition: control-response.hpp:142
ControlResponse()
Create a new ControlResponse where all values are unspecified.
Definition: control-response.hpp:42
A Blob holds a pointer to an immutable byte array implemented as const std::vector.
Definition: blob.hpp:42
ControlResponse & setStatusText(const std::string &statusText)
Set the status text.
Definition: control-response.hpp:177
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:159
const std::string & getStatusText() const
Get the status text.
Definition: control-response.hpp:149
size_t size() const
Return the length of the immutable byte array.
Definition: blob.hpp:147
void set(const ControlResponseLite &controlResponseLite)
Clear this ControlResponse, and set the values by copying from controlResponseLite.
Definition: control-response.cpp:44
static WireFormat * getDefaultWireFormat()
Return the default WireFormat used by default encoding and decoding methods which was set with setDef...
Definition: wire-format.cpp:34
ControlResponse & setStatusCode(int statusCode)
Set the status code.
Definition: control-response.hpp:165
const ControlParameters * getBodyAsControlParameters() const
Get the control response body as a ControlParameters.
Definition: control-response.hpp:157
Definition: wire-format.hpp:39
Blob wireEncode(WireFormat &wireFormat=*WireFormat::getDefaultWireFormat()) const
Encode this ControlResponse for a particular wire format.
Definition: control-response.hpp:67
void wireDecode(const uint8_t *input, size_t inputLength, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Decode the input using a particular wire format and update this ControlResponse.
Definition: control-response.hpp:82