NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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; -*- */
26 #include "control-response.hpp"
27 #include "../encoding/block-helpers.hpp"
28 #include "../encoding/tlv-nfd.hpp"
29 
30 namespace ndn {
31 namespace mgmt {
32 
33 // BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ControlResponse>));
34 BOOST_CONCEPT_ASSERT((WireEncodable<ControlResponse>));
35 BOOST_CONCEPT_ASSERT((WireDecodable<ControlResponse>));
36 static_assert(std::is_base_of<tlv::Error, ControlResponse::Error>::value,
37  "ControlResponse::Error must inherit from tlv::Error");
38 
40  : m_code(200)
41 {
42 }
43 
44 ControlResponse::ControlResponse(uint32_t code, const std::string& text)
45  : m_code(code)
46  , m_text(text)
47 {
48 }
49 
51 {
52  wireDecode(block);
53 }
54 
55 const Block&
57 {
58  if (m_wire.hasWire())
59  return m_wire;
60 
63 
65 
66  if (m_body.hasWire()) {
68  }
69 
70  m_wire.encode();
71  return m_wire;
72 }
73 
74 void
76 {
77  m_wire = wire;
78  m_wire.parse();
79 
81  throw Error("Requested decoding of ControlResponse, but Block is of different type");
82 
84  if (val == m_wire.elements_end() || val->type() != tlv::nfd::StatusCode) {
85  throw Error("Incorrect ControlResponse format (StatusCode missing or not the first item)");
86  }
87 
89  ++val;
90 
91  if (val == m_wire.elements_end() || val->type() != tlv::nfd::StatusText) {
92  throw Error("Incorrect ControlResponse format (StatusText missing or not the second item)");
93  }
94  m_text.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
95  ++val;
96 
97  if (val != m_wire.elements_end())
98  m_body = *val;
99  else
100  m_body = Block();
101 }
102 
103 std::ostream&
104 operator<<(std::ostream& os, const ControlResponse& response)
105 {
106  os << response.getCode() << " " << response.getText();
107  return os;
108 }
109 
110 } // namespace mgmt
111 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
const Block & wireEncode() const
const std::string & getText() const
uint64_t readNonNegativeInteger(const Block &block)
Helper to read a non-negative integer from a block.
element_const_iterator elements_end() const
Definition: block.cpp:595
Block nonNegativeIntegerBlock(uint32_t type, uint64_t value)
element_const_iterator elements_begin() const
Definition: block.cpp:589
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 parse() const
Parse wire buffer into subblocks.
Definition: block.cpp:322
uint32_t type() const
Definition: block.hpp:346
Block dataBlock(uint32_t type, const uint8_t *data, size_t dataSize)
void wireDecode(const Block &block)
void encode()
Encode subblocks into wire buffer.
Definition: block.cpp:355
bool hasWire() const
Check if the Block has fully encoded wire.
Definition: block.cpp:471
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