blob: 2ad94e5e55f8a4078a46c14066bb5b9be5db66e2 [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 Afanasyev258ec2b2014-05-14 16:15:37 -070026#include "../encoding/block-helpers.hpp"
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -080027#include "../encoding/tlv-nfd.hpp"
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080028
29namespace ndn {
Alexander Afanasyeve289b532014-02-09 22:14:44 -080030namespace nfd {
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080031
32/**
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040033 * @ingroup management
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080034 * @brief Class defining abstraction of ControlResponse for NFD Control Protocol
35 *
Junxiao Shi70911652014-08-12 10:14:24 -070036 * @see http://redmine.named-data.net/projects/nfd/wiki/ControlCommand#Response-format
37 * @detail This type is copyable because it's an abstraction of a TLV type.
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080038 */
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070039class ControlResponse
40{
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080041public:
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060042 class Error : public tlv::Error
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070043 {
44 public:
45 explicit
46 Error(const std::string& what)
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060047 : tlv::Error(what)
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070048 {
49 }
50 };
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080051
Junxiao Shi70911652014-08-12 10:14:24 -070052 ControlResponse();
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080053
Junxiao Shi70911652014-08-12 10:14:24 -070054 ControlResponse(uint32_t code, const std::string& text);
Alexander Afanasyeve289b532014-02-09 22:14:44 -080055
Junxiao Shi70911652014-08-12 10:14:24 -070056 explicit
57 ControlResponse(const Block& block);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070058
Junxiao Shi70911652014-08-12 10:14:24 -070059 uint32_t
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080060 getCode() const;
61
Junxiao Shi70911652014-08-12 10:14:24 -070062 void
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080063 setCode(uint32_t code);
64
Junxiao Shi70911652014-08-12 10:14:24 -070065 const std::string&
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080066 getText() const;
67
Junxiao Shi70911652014-08-12 10:14:24 -070068 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070069 setText(const std::string& text);
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080070
Junxiao Shi70911652014-08-12 10:14:24 -070071 const Block&
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080072 getBody() const;
73
Junxiao Shi70911652014-08-12 10:14:24 -070074 void
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080075 setBody(const Block& body);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070076
Junxiao Shi70911652014-08-12 10:14:24 -070077 const Block&
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080078 wireEncode() const;
79
Junxiao Shi70911652014-08-12 10:14:24 -070080 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070081 wireDecode(const Block& block);
82
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080083protected:
84 uint32_t m_code;
85 std::string m_text;
86 Block m_body;
87
88 mutable Block m_wire;
89};
90
91inline uint32_t
92ControlResponse::getCode() const
93{
94 return m_code;
95}
96
97inline void
98ControlResponse::setCode(uint32_t code)
99{
100 m_code = code;
101 m_wire.reset();
102}
103
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700104inline const std::string&
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800105ControlResponse::getText() const
106{
107 return m_text;
108}
109
110inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700111ControlResponse::setText(const std::string& text)
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800112{
113 m_text = text;
114 m_wire.reset();
115}
116
117inline const Block&
118ControlResponse::getBody() const
119{
120 return m_body;
121}
122
123inline void
124ControlResponse::setBody(const Block& body)
125{
126 m_body = body;
127 m_body.encode(); // will do nothing if already encoded
128 m_wire.reset();
129}
130
Junxiao Shi70911652014-08-12 10:14:24 -0700131std::ostream&
132operator<<(std::ostream& os, const ControlResponse& response);
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800133
Alexander Afanasyeve289b532014-02-09 22:14:44 -0800134} // namespace nfd
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800135} // namespace ndn
136
137#endif // NDN_MANAGEMENT_CONTROL_RESPONSE_HPP