Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 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. |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef NDN_MANAGEMENT_CONTROL_RESPONSE_HPP |
| 23 | #define NDN_MANAGEMENT_CONTROL_RESPONSE_HPP |
| 24 | |
Alexander Afanasyev | 274f2b0 | 2014-01-30 20:08:45 -0800 | [diff] [blame] | 25 | #include "../encoding/block.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 26 | #include "../encoding/block-helpers.hpp" |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 27 | #include "../encoding/tlv-nfd.hpp" |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 28 | |
| 29 | namespace ndn { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 30 | namespace nfd { |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 31 | |
| 32 | /** |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 33 | * @ingroup management |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 34 | * @brief Class defining abstraction of ControlResponse for NFD Control Protocol |
| 35 | * |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 36 | * @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 Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 38 | */ |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 39 | class ControlResponse |
| 40 | { |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 41 | public: |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 42 | class Error : public tlv::Error |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 43 | { |
| 44 | public: |
| 45 | explicit |
| 46 | Error(const std::string& what) |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 47 | : tlv::Error(what) |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 48 | { |
| 49 | } |
| 50 | }; |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 51 | |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 52 | ControlResponse(); |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 53 | |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 54 | ControlResponse(uint32_t code, const std::string& text); |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 55 | |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 56 | explicit |
| 57 | ControlResponse(const Block& block); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 58 | |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 59 | uint32_t |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 60 | getCode() const; |
| 61 | |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 62 | void |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 63 | setCode(uint32_t code); |
| 64 | |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 65 | const std::string& |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 66 | getText() const; |
| 67 | |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 68 | void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 69 | setText(const std::string& text); |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 70 | |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 71 | const Block& |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 72 | getBody() const; |
| 73 | |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 74 | void |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 75 | setBody(const Block& body); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 76 | |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 77 | const Block& |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 78 | wireEncode() const; |
| 79 | |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 80 | void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 81 | wireDecode(const Block& block); |
| 82 | |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 83 | protected: |
| 84 | uint32_t m_code; |
| 85 | std::string m_text; |
| 86 | Block m_body; |
| 87 | |
| 88 | mutable Block m_wire; |
| 89 | }; |
| 90 | |
| 91 | inline uint32_t |
| 92 | ControlResponse::getCode() const |
| 93 | { |
| 94 | return m_code; |
| 95 | } |
| 96 | |
| 97 | inline void |
| 98 | ControlResponse::setCode(uint32_t code) |
| 99 | { |
| 100 | m_code = code; |
| 101 | m_wire.reset(); |
| 102 | } |
| 103 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 104 | inline const std::string& |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 105 | ControlResponse::getText() const |
| 106 | { |
| 107 | return m_text; |
| 108 | } |
| 109 | |
| 110 | inline void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 111 | ControlResponse::setText(const std::string& text) |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 112 | { |
| 113 | m_text = text; |
| 114 | m_wire.reset(); |
| 115 | } |
| 116 | |
| 117 | inline const Block& |
| 118 | ControlResponse::getBody() const |
| 119 | { |
| 120 | return m_body; |
| 121 | } |
| 122 | |
| 123 | inline void |
| 124 | ControlResponse::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 Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 131 | std::ostream& |
| 132 | operator<<(std::ostream& os, const ControlResponse& response); |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 133 | |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 134 | } // namespace nfd |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 135 | } // namespace ndn |
| 136 | |
| 137 | #endif // NDN_MANAGEMENT_CONTROL_RESPONSE_HPP |