NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
control-response.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "control-response.hpp"
23 #include "../encoding/block-helpers.hpp"
24 #include "../encoding/tlv-nfd.hpp"
25 
26 namespace ndn {
27 namespace mgmt {
28 
29 // BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ControlResponse>));
30 BOOST_CONCEPT_ASSERT((WireEncodable<ControlResponse>));
31 BOOST_CONCEPT_ASSERT((WireDecodable<ControlResponse>));
32 static_assert(std::is_base_of<tlv::Error, ControlResponse::Error>::value,
33  "ControlResponse::Error must inherit from tlv::Error");
34 
36  : m_code(200)
37 {
38 }
39 
40 ControlResponse::ControlResponse(uint32_t code, const std::string& text)
41  : m_code(code)
42  , m_text(text)
43 {
44 }
45 
47 {
48  wireDecode(block);
49 }
50 
51 const Block&
53 {
54  if (m_wire.hasWire())
55  return m_wire;
56 
59 
61 
62  if (m_body.hasWire()) {
64  }
65 
66  m_wire.encode();
67  return m_wire;
68 }
69 
70 void
72 {
73  m_wire = wire;
74  m_wire.parse();
75 
77  throw Error("Requested decoding of ControlResponse, but Block is of different type");
78 
80  if (val == m_wire.elements_end() || val->type() != tlv::nfd::StatusCode) {
81  throw Error("Incorrect ControlResponse format (StatusCode missing or not the first item)");
82  }
83 
85  ++val;
86 
87  if (val == m_wire.elements_end() || val->type() != tlv::nfd::StatusText) {
88  throw Error("Incorrect ControlResponse format (StatusText missing or not the second item)");
89  }
90  m_text.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
91  ++val;
92 
93  if (val != m_wire.elements_end())
94  m_body = *val;
95  else
96  m_body = Block();
97 }
98 
99 std::ostream&
100 operator<<(std::ostream& os, const ControlResponse& response)
101 {
102  os << response.getCode() << " " << response.getText();
103  return os;
104 }
105 
106 } // namespace mgmt
107 } // namespace ndn
element_const_iterator elements_begin() const
Definition: block.cpp:589
bool hasWire() const
Check if the Block has fully encoded wire.
Definition: block.cpp:471
Copyright (c) 2011-2015 Regents of the University of California.
element_const_iterator elements_end() const
Definition: block.cpp:595
void parse() const
Parse wire buffer into subblocks.
Definition: block.cpp:322
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
const Block & wireEncode() const
Block makeNonNegativeIntegerBlock(uint32_t type, uint64_t value)
Create a TLV block type type containing non-negative integer value.
uint64_t readNonNegativeInteger(const Block &block)
Helper to read a non-negative integer from a block.
Block makeBinaryBlock(uint32_t type, const uint8_t *value, size_t length)
Create a TLV block type type with value from a buffer value of size length.
element_container::const_iterator element_const_iterator
Definition: block.hpp:48
void push_back(const Block &element)
Definition: block.cpp:568
std::ostream & operator<<(std::ostream &os, const ControlResponse &response)
void wireDecode(const Block &block)
void encode()
Encode subblocks into wire buffer.
Definition: block.cpp:355
const std::string & getText() const
ControlCommand response.
a concept check for TLV abstraction with .wireEncode method
Definition: concepts.hpp:34
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
Definition: concepts.hpp:70
uint32_t type() const
Definition: block.hpp:324