blob: f37821ff89b06df02b3085672820e4e75d479df2 [file] [log] [blame]
Yanbiao Li8ee37ed2015-05-19 12:44:04 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi68b53852018-07-25 13:56:38 -06002/*
3 * Copyright (c) 2013-2018 Regents of the University of California.
Yanbiao Li8ee37ed2015-05-19 12:44:04 -07004 *
Alexander Afanasyev80b68e12015-09-17 17:01:04 -07005 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Yanbiao Li8ee37ed2015-05-19 12:44:04 -07006 *
Alexander Afanasyev80b68e12015-09-17 17:01:04 -07007 * 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.
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070010 *
Alexander Afanasyev80b68e12015-09-17 17:01:04 -070011 * 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.
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070014 *
Alexander Afanasyev80b68e12015-09-17 17:01:04 -070015 * 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.
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070020 */
21
22#ifndef NDN_MGMT_CONTROL_RESPONSE_HPP
23#define NDN_MGMT_CONTROL_RESPONSE_HPP
24
25#include "../encoding/block.hpp"
26
27namespace ndn {
28namespace mgmt {
29
30/** \brief ControlCommand response
31 */
32class ControlResponse
33{
34public:
35 class Error : public tlv::Error
36 {
37 public:
Junxiao Shi68b53852018-07-25 13:56:38 -060038 using tlv::Error::Error;
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070039 };
40
41 ControlResponse();
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 ControlResponse&
52 setCode(uint32_t code);
53
54 const std::string&
55 getText() const;
56
57 ControlResponse&
58 setText(const std::string& text);
59
60 const Block&
61 getBody() const;
62
63 ControlResponse&
64 setBody(const Block& body);
65
66 const Block&
67 wireEncode() const;
68
69 void
70 wireDecode(const Block& block);
71
72protected:
73 uint32_t m_code;
74 std::string m_text;
75 Block m_body;
76
77 mutable Block m_wire;
78};
79
80inline uint32_t
81ControlResponse::getCode() const
82{
83 return m_code;
84}
85
86inline ControlResponse&
87ControlResponse::setCode(uint32_t code)
88{
89 m_code = code;
90 m_wire.reset();
91 return *this;
92}
93
94inline const std::string&
95ControlResponse::getText() const
96{
97 return m_text;
98}
99
100inline ControlResponse&
101ControlResponse::setText(const std::string& text)
102{
103 m_text = text;
104 m_wire.reset();
105 return *this;
106}
107
108inline const Block&
109ControlResponse::getBody() const
110{
111 return m_body;
112}
113
114inline ControlResponse&
115ControlResponse::setBody(const Block& body)
116{
117 m_body = body;
118 m_body.encode(); // will do nothing if already encoded
119 m_wire.reset();
120 return *this;
121}
122
123std::ostream&
124operator<<(std::ostream& os, const ControlResponse& response);
125
126} // namespace mgmt
127} // namespace ndn
128
Junxiao Shi68b53852018-07-25 13:56:38 -0600129#endif // NDN_MGMT_CONTROL_RESPONSE_HPP