blob: 42ffd3d996259da136fd926f946da2fedf6dffc6 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -08002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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.
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080020 */
21
22#ifndef NDN_MANAGEMENT_CONTROL_RESPONSE_HPP
23#define NDN_MANAGEMENT_CONTROL_RESPONSE_HPP
24
Alexander Afanasyev274f2b02014-01-30 20:08:45 -080025#include "../encoding/block.hpp"
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080026
27namespace ndn {
Alexander Afanasyeve289b532014-02-09 22:14:44 -080028namespace nfd {
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080029
30/**
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040031 * @ingroup management
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080032 * @brief Class defining abstraction of ControlResponse for NFD Control Protocol
33 *
Junxiao Shi70911652014-08-12 10:14:24 -070034 * @see http://redmine.named-data.net/projects/nfd/wiki/ControlCommand#Response-format
35 * @detail This type is copyable because it's an abstraction of a TLV type.
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080036 */
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070037class ControlResponse
38{
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080039public:
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060040 class Error : public tlv::Error
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070041 {
42 public:
43 explicit
44 Error(const std::string& what)
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060045 : tlv::Error(what)
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070046 {
47 }
48 };
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080049
Junxiao Shi70911652014-08-12 10:14:24 -070050 ControlResponse();
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080051
Junxiao Shi70911652014-08-12 10:14:24 -070052 ControlResponse(uint32_t code, const std::string& text);
Alexander Afanasyeve289b532014-02-09 22:14:44 -080053
Junxiao Shi70911652014-08-12 10:14:24 -070054 explicit
55 ControlResponse(const Block& block);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070056
Junxiao Shi70911652014-08-12 10:14:24 -070057 uint32_t
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080058 getCode() const;
59
Junxiao Shi70911652014-08-12 10:14:24 -070060 void
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080061 setCode(uint32_t code);
62
Junxiao Shi70911652014-08-12 10:14:24 -070063 const std::string&
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080064 getText() const;
65
Junxiao Shi70911652014-08-12 10:14:24 -070066 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070067 setText(const std::string& text);
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080068
Junxiao Shi70911652014-08-12 10:14:24 -070069 const Block&
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080070 getBody() const;
71
Junxiao Shi70911652014-08-12 10:14:24 -070072 void
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080073 setBody(const Block& body);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070074
Junxiao Shi70911652014-08-12 10:14:24 -070075 const Block&
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080076 wireEncode() const;
77
Junxiao Shi70911652014-08-12 10:14:24 -070078 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070079 wireDecode(const Block& block);
80
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080081protected:
82 uint32_t m_code;
83 std::string m_text;
84 Block m_body;
85
86 mutable Block m_wire;
87};
88
89inline uint32_t
90ControlResponse::getCode() const
91{
92 return m_code;
93}
94
95inline void
96ControlResponse::setCode(uint32_t code)
97{
98 m_code = code;
99 m_wire.reset();
100}
101
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700102inline const std::string&
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800103ControlResponse::getText() const
104{
105 return m_text;
106}
107
108inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700109ControlResponse::setText(const std::string& text)
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800110{
111 m_text = text;
112 m_wire.reset();
113}
114
115inline const Block&
116ControlResponse::getBody() const
117{
118 return m_body;
119}
120
121inline void
122ControlResponse::setBody(const Block& body)
123{
124 m_body = body;
125 m_body.encode(); // will do nothing if already encoded
126 m_wire.reset();
127}
128
Junxiao Shi70911652014-08-12 10:14:24 -0700129std::ostream&
130operator<<(std::ostream& os, const ControlResponse& response);
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800131
Alexander Afanasyeve289b532014-02-09 22:14:44 -0800132} // namespace nfd
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800133} // namespace ndn
134
135#endif // NDN_MANAGEMENT_CONTROL_RESPONSE_HPP