Alexander Afanasyev | e1e6f2a | 2014-04-25 11:28:12 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 2 | /** |
| 3 | * Copyright (c) 2014-2018, Regents of the University of California. |
Alexander Afanasyev | e1e6f2a | 2014-04-25 11:28:12 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of NDN repo-ng (Next generation of NDN repository). |
| 6 | * See AUTHORS.md for complete list of repo-ng authors and contributors. |
| 7 | * |
| 8 | * repo-ng is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 20 | #ifndef REPO_REPO_COMMAND_RESPONSE_HPP |
| 21 | #define REPO_REPO_COMMAND_RESPONSE_HPP |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 22 | |
Alexander Afanasyev | c0e2658 | 2017-08-13 21:16:49 -0400 | [diff] [blame] | 23 | #include "repo-tlv.hpp" |
| 24 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 25 | #include <ndn-cxx/mgmt/control-response.hpp> |
Alexander Afanasyev | e291caf | 2014-04-25 11:17:36 -0700 | [diff] [blame] | 26 | #include <ndn-cxx/encoding/block.hpp> |
Wentao Shang | 91fb4f2 | 2014-05-20 10:55:22 -0700 | [diff] [blame] | 27 | #include <ndn-cxx/encoding/block-helpers.hpp> |
Alexander Afanasyev | e291caf | 2014-04-25 11:17:36 -0700 | [diff] [blame] | 28 | #include <ndn-cxx/encoding/encoding-buffer.hpp> |
| 29 | #include <ndn-cxx/encoding/tlv-nfd.hpp> |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 30 | |
| 31 | namespace repo { |
| 32 | |
| 33 | using ndn::Block; |
| 34 | using ndn::EncodingImpl; |
| 35 | using ndn::EncodingEstimator; |
| 36 | using ndn::EncodingBuffer; |
| 37 | |
| 38 | /** |
| 39 | * @brief Class defining abstraction of Response for NDN Repo Protocol |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 40 | * @sa link https://redmine.named-data.net/projects/repo-ng/wiki/Repo_Protocol_Specification#Repo-Command-Response |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 41 | */ |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 42 | class RepoCommandResponse : public ndn::mgmt::ControlResponse |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 43 | { |
| 44 | public: |
Junxiao Shi | ca188d7 | 2014-10-19 09:49:40 -0700 | [diff] [blame] | 45 | class Error : public ndn::tlv::Error |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 46 | { |
| 47 | public: |
| 48 | explicit |
| 49 | Error(const std::string& what) |
Junxiao Shi | ca188d7 | 2014-10-19 09:49:40 -0700 | [diff] [blame] | 50 | : ndn::tlv::Error(what) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 51 | { |
| 52 | } |
| 53 | }; |
| 54 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 55 | RepoCommandResponse(uint32_t code, const std::string& text) |
| 56 | : ndn::mgmt::ControlResponse(code, text) |
| 57 | , m_hasStartBlockId(false) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 58 | , m_hasEndBlockId(false) |
| 59 | , m_hasProcessId(false) |
| 60 | , m_hasInsertNum(false) |
| 61 | , m_hasDeleteNum(false) |
| 62 | , m_hasStatusCode(false) |
| 63 | { |
| 64 | } |
| 65 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 66 | RepoCommandResponse(){ |
| 67 | } |
| 68 | |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 69 | explicit |
| 70 | RepoCommandResponse(const Block& block) |
| 71 | { |
| 72 | wireDecode(block); |
| 73 | } |
| 74 | |
| 75 | uint64_t |
| 76 | getStartBlockId() const |
| 77 | { |
| 78 | return m_startBlockId; |
| 79 | } |
| 80 | |
| 81 | RepoCommandResponse& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 82 | setStartBlockId(uint64_t startBlockId); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 83 | |
| 84 | bool |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 85 | hasStartBlockId() const; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 86 | |
| 87 | uint64_t |
| 88 | getEndBlockId() const |
| 89 | { |
| 90 | assert(hasEndBlockId()); |
| 91 | return m_endBlockId; |
| 92 | } |
| 93 | |
| 94 | RepoCommandResponse& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 95 | setEndBlockId(uint64_t endBlockId); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 96 | |
| 97 | bool |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 98 | hasEndBlockId() const; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 99 | |
| 100 | uint64_t |
| 101 | getProcessId() const |
| 102 | { |
| 103 | return m_processId; |
| 104 | } |
| 105 | |
| 106 | RepoCommandResponse& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 107 | setProcessId(uint64_t processId); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 108 | |
| 109 | bool |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 110 | hasProcessId() const; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 111 | |
| 112 | RepoCommandResponse& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 113 | setCode(uint32_t statusCode); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 114 | |
| 115 | bool |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 116 | hasStatusCode() const; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 117 | |
| 118 | uint64_t |
| 119 | getInsertNum() const |
| 120 | { |
| 121 | return m_insertNum; |
| 122 | } |
| 123 | |
| 124 | RepoCommandResponse& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 125 | setInsertNum(uint64_t insertNum); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 126 | |
| 127 | bool |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 128 | hasInsertNum() const; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 129 | |
| 130 | uint64_t |
| 131 | getDeleteNum() const |
| 132 | { |
| 133 | return m_deleteNum; |
| 134 | } |
| 135 | |
| 136 | RepoCommandResponse& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 137 | setDeleteNum(uint64_t deleteNum); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 138 | |
| 139 | bool |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 140 | hasDeleteNum() const; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 141 | |
Alexander Afanasyev | c0e2658 | 2017-08-13 21:16:49 -0400 | [diff] [blame] | 142 | template<ndn::encoding::Tag T> |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 143 | size_t |
| 144 | wireEncode(EncodingImpl<T>& block) const; |
| 145 | |
| 146 | const Block& |
| 147 | wireEncode() const; |
| 148 | |
| 149 | void |
| 150 | wireDecode(const Block& wire); |
| 151 | |
| 152 | private: |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 153 | uint64_t m_startBlockId; |
| 154 | uint64_t m_endBlockId; |
| 155 | uint64_t m_processId; |
| 156 | uint64_t m_insertNum; |
| 157 | uint64_t m_deleteNum; |
| 158 | |
| 159 | bool m_hasStartBlockId; |
| 160 | bool m_hasEndBlockId; |
| 161 | bool m_hasProcessId; |
| 162 | bool m_hasInsertNum; |
| 163 | bool m_hasDeleteNum; |
| 164 | bool m_hasStatusCode; |
| 165 | |
| 166 | mutable Block m_wire; |
| 167 | }; |
| 168 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 169 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(RepoCommandResponse); |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 170 | |
| 171 | } // namespace repo |
| 172 | |
| 173 | #endif // REPO_REPO_COMMAND_RESPONSE_HPP |