Alexander Afanasyev | e1e6f2a | 2014-04-25 11:28:12 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2022, 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 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 23 | #include "common.hpp" |
Alexander Afanasyev | c0e2658 | 2017-08-13 21:16:49 -0400 | [diff] [blame] | 24 | #include "repo-tlv.hpp" |
| 25 | |
Alexander Afanasyev | e291caf | 2014-04-25 11:17:36 -0700 | [diff] [blame] | 26 | #include <ndn-cxx/encoding/encoding-buffer.hpp> |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 27 | #include <ndn-cxx/mgmt/control-response.hpp> |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 28 | |
| 29 | namespace repo { |
| 30 | |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 31 | /** |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 32 | * @brief Class defining abstraction of Response for NDN Repo Protocol |
| 33 | * @sa link https://redmine.named-data.net/projects/repo-ng/wiki/Repo_Protocol_Specification#Repo-Command-Response |
| 34 | */ |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 35 | class RepoCommandResponse : public ndn::mgmt::ControlResponse |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 36 | { |
| 37 | public: |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 38 | class Error : public tlv::Error |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 39 | { |
| 40 | public: |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 41 | using tlv::Error::Error; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 44 | RepoCommandResponse() = default; |
| 45 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 46 | RepoCommandResponse(uint32_t code, const std::string& text) |
| 47 | : ndn::mgmt::ControlResponse(code, text) |
| 48 | , m_hasStartBlockId(false) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 49 | , m_hasEndBlockId(false) |
| 50 | , m_hasProcessId(false) |
| 51 | , m_hasInsertNum(false) |
| 52 | , m_hasDeleteNum(false) |
| 53 | , m_hasStatusCode(false) |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | explicit |
| 58 | RepoCommandResponse(const Block& block) |
| 59 | { |
| 60 | wireDecode(block); |
| 61 | } |
| 62 | |
| 63 | uint64_t |
| 64 | getStartBlockId() const |
| 65 | { |
| 66 | return m_startBlockId; |
| 67 | } |
| 68 | |
| 69 | RepoCommandResponse& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 70 | setStartBlockId(uint64_t startBlockId); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 71 | |
| 72 | bool |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 73 | hasStartBlockId() const; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 74 | |
| 75 | uint64_t |
| 76 | getEndBlockId() const |
| 77 | { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 78 | BOOST_ASSERT(hasEndBlockId()); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 79 | return m_endBlockId; |
| 80 | } |
| 81 | |
| 82 | RepoCommandResponse& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 83 | setEndBlockId(uint64_t endBlockId); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 84 | |
| 85 | bool |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 86 | hasEndBlockId() const; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 87 | |
| 88 | uint64_t |
| 89 | getProcessId() const |
| 90 | { |
| 91 | return m_processId; |
| 92 | } |
| 93 | |
| 94 | RepoCommandResponse& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 95 | setProcessId(uint64_t processId); |
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 | hasProcessId() const; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 99 | |
| 100 | RepoCommandResponse& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 101 | setCode(uint32_t statusCode); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 102 | |
| 103 | bool |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 104 | hasStatusCode() const; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 105 | |
| 106 | uint64_t |
| 107 | getInsertNum() const |
| 108 | { |
| 109 | return m_insertNum; |
| 110 | } |
| 111 | |
| 112 | RepoCommandResponse& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 113 | setInsertNum(uint64_t insertNum); |
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 | hasInsertNum() const; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 117 | |
| 118 | uint64_t |
| 119 | getDeleteNum() const |
| 120 | { |
| 121 | return m_deleteNum; |
| 122 | } |
| 123 | |
| 124 | RepoCommandResponse& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 125 | setDeleteNum(uint64_t deleteNum); |
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 | hasDeleteNum() const; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 129 | |
Alexander Afanasyev | c0e2658 | 2017-08-13 21:16:49 -0400 | [diff] [blame] | 130 | template<ndn::encoding::Tag T> |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 131 | size_t |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 132 | wireEncode(ndn::EncodingImpl<T>& block) const; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 133 | |
| 134 | const Block& |
| 135 | wireEncode() const; |
| 136 | |
| 137 | void |
| 138 | wireDecode(const Block& wire); |
| 139 | |
| 140 | private: |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 141 | uint64_t m_startBlockId; |
| 142 | uint64_t m_endBlockId; |
| 143 | uint64_t m_processId; |
| 144 | uint64_t m_insertNum; |
| 145 | uint64_t m_deleteNum; |
| 146 | |
| 147 | bool m_hasStartBlockId; |
| 148 | bool m_hasEndBlockId; |
| 149 | bool m_hasProcessId; |
| 150 | bool m_hasInsertNum; |
| 151 | bool m_hasDeleteNum; |
| 152 | bool m_hasStatusCode; |
| 153 | |
| 154 | mutable Block m_wire; |
| 155 | }; |
| 156 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 157 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(RepoCommandResponse); |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 158 | |
| 159 | } // namespace repo |
| 160 | |
| 161 | #endif // REPO_REPO_COMMAND_RESPONSE_HPP |