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-2023 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::mgmt {
28 
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  {
51  return m_code;
52  }
53 
55  setCode(uint32_t code);
56 
57  const std::string&
58  getText() const
59  {
60  return m_text;
61  }
62 
64  setText(const std::string& text);
65 
66  const Block&
67  getBody() const
68  {
69  return m_body;
70  }
71 
73  setBody(const Block& body);
74 
75  const Block&
76  wireEncode() const;
77 
78  void
79  wireDecode(const Block& block);
80 
81 protected:
82  uint32_t m_code = 200;
83  std::string m_text;
85 
86  mutable Block m_wire;
87 
88 private: // non-member operators
89  // NOTE: the following "hidden friend" operators are available via
90  // argument-dependent lookup only and must be defined inline.
91 
92  friend std::ostream&
93  operator<<(std::ostream& os, const ControlResponse& response)
94  {
95  return os << response.getCode() << ' ' << response.getText();
96  }
97 };
98 
99 } // namespace ndn::mgmt
100 
101 #endif // NDN_CXX_MGMT_CONTROL_RESPONSE_HPP
Represents a TLV element of the NDN packet format.
Definition: block.hpp:45
ControlCommand response.
void wireDecode(const Block &block)
friend std::ostream & operator<<(std::ostream &os, const ControlResponse &response)
const Block & wireEncode() const
const Block & getBody() const
ControlResponse & setBody(const Block &body)
ControlResponse & setText(const std::string &text)
const std::string & getText() const
ControlResponse & setCode(uint32_t code)
Represents an error in TLV encoding or decoding.
Definition: tlv.hpp:54
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:28