Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #ifndef NDN_MGMT_CONTROL_RESPONSE_HPP |
| 27 | #define NDN_MGMT_CONTROL_RESPONSE_HPP |
| 28 | |
| 29 | #include "../encoding/block.hpp" |
| 30 | |
| 31 | namespace ndn { |
| 32 | namespace mgmt { |
| 33 | |
| 34 | /** \brief ControlCommand response |
| 35 | */ |
| 36 | class ControlResponse |
| 37 | { |
| 38 | public: |
| 39 | class Error : public tlv::Error |
| 40 | { |
| 41 | public: |
| 42 | explicit |
| 43 | Error(const std::string& what) |
| 44 | : tlv::Error(what) |
| 45 | { |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | ControlResponse(); |
| 50 | |
| 51 | ControlResponse(uint32_t code, const std::string& text); |
| 52 | |
| 53 | explicit |
| 54 | ControlResponse(const Block& block); |
| 55 | |
| 56 | uint32_t |
| 57 | getCode() const; |
| 58 | |
| 59 | ControlResponse& |
| 60 | setCode(uint32_t code); |
| 61 | |
| 62 | const std::string& |
| 63 | getText() const; |
| 64 | |
| 65 | ControlResponse& |
| 66 | setText(const std::string& text); |
| 67 | |
| 68 | const Block& |
| 69 | getBody() const; |
| 70 | |
| 71 | ControlResponse& |
| 72 | setBody(const Block& body); |
| 73 | |
| 74 | const Block& |
| 75 | wireEncode() const; |
| 76 | |
| 77 | void |
| 78 | wireDecode(const Block& block); |
| 79 | |
| 80 | protected: |
| 81 | uint32_t m_code; |
| 82 | std::string m_text; |
| 83 | Block m_body; |
| 84 | |
| 85 | mutable Block m_wire; |
| 86 | }; |
| 87 | |
| 88 | inline uint32_t |
| 89 | ControlResponse::getCode() const |
| 90 | { |
| 91 | return m_code; |
| 92 | } |
| 93 | |
| 94 | inline ControlResponse& |
| 95 | ControlResponse::setCode(uint32_t code) |
| 96 | { |
| 97 | m_code = code; |
| 98 | m_wire.reset(); |
| 99 | return *this; |
| 100 | } |
| 101 | |
| 102 | inline const std::string& |
| 103 | ControlResponse::getText() const |
| 104 | { |
| 105 | return m_text; |
| 106 | } |
| 107 | |
| 108 | inline ControlResponse& |
| 109 | ControlResponse::setText(const std::string& text) |
| 110 | { |
| 111 | m_text = text; |
| 112 | m_wire.reset(); |
| 113 | return *this; |
| 114 | } |
| 115 | |
| 116 | inline const Block& |
| 117 | ControlResponse::getBody() const |
| 118 | { |
| 119 | return m_body; |
| 120 | } |
| 121 | |
| 122 | inline ControlResponse& |
| 123 | ControlResponse::setBody(const Block& body) |
| 124 | { |
| 125 | m_body = body; |
| 126 | m_body.encode(); // will do nothing if already encoded |
| 127 | m_wire.reset(); |
| 128 | return *this; |
| 129 | } |
| 130 | |
| 131 | std::ostream& |
| 132 | operator<<(std::ostream& os, const ControlResponse& response); |
| 133 | |
| 134 | } // namespace mgmt |
| 135 | } // namespace ndn |
| 136 | |
| 137 | #endif // NDN_MGMT_CONTRO_RESPONSE_HPP |