control-response.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2021 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_CXX_MGMT_CONTROL_RESPONSE_HPP
23 #define NDN_CXX_MGMT_CONTROL_RESPONSE_HPP
24 
26 
27 namespace ndn {
28 namespace mgmt {
29 
33 {
34 public:
35  class Error : public tlv::Error
36  {
37  public:
38  using tlv::Error::Error;
39  };
40 
42 
43  ControlResponse(uint32_t code, const std::string& text);
44 
45  explicit
46  ControlResponse(const Block& block);
47 
48  uint32_t
49  getCode() const;
50 
52  setCode(uint32_t code);
53 
54  const std::string&
55  getText() const;
56 
58  setText(const std::string& text);
59 
60  const Block&
61  getBody() const;
62 
64  setBody(const Block& body);
65 
66  const Block&
67  wireEncode() const;
68 
69  void
70  wireDecode(const Block& block);
71 
72 protected:
73  uint32_t m_code;
74  std::string m_text;
76 
77  mutable Block m_wire;
78 };
79 
80 inline uint32_t
82 {
83  return m_code;
84 }
85 
86 inline ControlResponse&
88 {
89  m_code = code;
90  m_wire.reset();
91  return *this;
92 }
93 
94 inline const std::string&
96 {
97  return m_text;
98 }
99 
100 inline ControlResponse&
101 ControlResponse::setText(const std::string& text)
102 {
103  m_text = text;
104  m_wire.reset();
105  return *this;
106 }
107 
108 inline const Block&
110 {
111  return m_body;
112 }
113 
114 inline ControlResponse&
116 {
117  m_body = body;
118  m_body.encode(); // will do nothing if already encoded
119  m_wire.reset();
120  return *this;
121 }
122 
123 std::ostream&
124 operator<<(std::ostream& os, const ControlResponse& response);
125 
126 } // namespace mgmt
127 } // namespace ndn
128 
129 #endif // NDN_CXX_MGMT_CONTROL_RESPONSE_HPP
Represents a TLV element of the NDN packet format.
Definition: block.hpp:45
void encode()
Encode sub-elements into TLV-VALUE.
Definition: block.cpp:368
void reset() noexcept
Reset the Block to a default-constructed state.
Definition: block.cpp:265
ControlCommand response.
void wireDecode(const Block &block)
const Block & getBody() const
const Block & wireEncode() const
ControlResponse & setBody(const Block &body)
ControlResponse & setText(const std::string &text)
ControlResponse & setCode(uint32_t code)
const std::string & getText() const
represents an error in TLV encoding or decoding
Definition: tlv.hpp:53
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:27
std::ostream & operator<<(std::ostream &os, const ControlResponse &response)
Definition: data.cpp:25