Alexander Afanasyev | e1e6f2a | 2014-04-25 11:28:12 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | c0e2658 | 2017-08-13 21:16:49 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 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_PARAMETER_HPP |
| 21 | #define REPO_REPO_COMMAND_PARAMETER_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> |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 27 | #include <ndn-cxx/mgmt/control-parameters.hpp> |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 28 | |
| 29 | namespace repo { |
| 30 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 31 | enum RepoParameterField { |
| 32 | REPO_PARAMETER_NAME, |
| 33 | REPO_PARAMETER_START_BLOCK_ID, |
| 34 | REPO_PARAMETER_END_BLOCK_ID, |
| 35 | REPO_PARAMETER_PROCESS_ID, |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 36 | REPO_PARAMETER_INTEREST_LIFETIME, |
| 37 | REPO_PARAMETER_UBOUND |
| 38 | }; |
| 39 | |
| 40 | const std::string REPO_PARAMETER_FIELD[REPO_PARAMETER_UBOUND] = { |
| 41 | "Name", |
| 42 | "StartBlockId", |
| 43 | "EndBlockId", |
| 44 | "ProcessId", |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 45 | "InterestLifetime" |
| 46 | }; |
| 47 | |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 48 | /** |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 49 | * @brief Class defining abstraction of parameter of command for NDN Repo Protocol |
| 50 | * @sa link https://redmine.named-data.net/projects/repo-ng/wiki/Repo_Protocol_Specification#RepoCommandParameter |
| 51 | */ |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 52 | class RepoCommandParameter : public ndn::mgmt::ControlParameters |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 53 | { |
| 54 | public: |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 55 | class Error : public tlv::Error |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 56 | { |
| 57 | public: |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 58 | using tlv::Error::Error; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | RepoCommandParameter() |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 62 | : m_hasFields(REPO_PARAMETER_UBOUND) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 63 | { |
| 64 | } |
| 65 | |
| 66 | explicit |
| 67 | RepoCommandParameter(const Block& block) |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 68 | : m_hasFields(REPO_PARAMETER_UBOUND) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 69 | { |
| 70 | wireDecode(block); |
| 71 | } |
| 72 | |
| 73 | const Name& |
| 74 | getName() const |
| 75 | { |
| 76 | return m_name; |
| 77 | } |
| 78 | |
| 79 | RepoCommandParameter& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 80 | setName(const Name& name); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 81 | |
| 82 | bool |
| 83 | hasName() const |
| 84 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 85 | return m_hasFields[REPO_PARAMETER_NAME]; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 88 | |
| 89 | uint64_t |
| 90 | getStartBlockId() const |
| 91 | { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 92 | BOOST_ASSERT(hasStartBlockId()); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 93 | return m_startBlockId; |
| 94 | } |
| 95 | |
| 96 | RepoCommandParameter& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 97 | setStartBlockId(uint64_t startBlockId); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 98 | |
| 99 | bool |
| 100 | hasStartBlockId() const |
| 101 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 102 | return m_hasFields[REPO_PARAMETER_START_BLOCK_ID]; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | uint64_t |
| 106 | getEndBlockId() const |
| 107 | { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 108 | BOOST_ASSERT(hasEndBlockId()); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 109 | return m_endBlockId; |
| 110 | } |
| 111 | |
| 112 | RepoCommandParameter& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 113 | setEndBlockId(uint64_t endBlockId); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 114 | |
| 115 | bool |
| 116 | hasEndBlockId() const |
| 117 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 118 | return m_hasFields[REPO_PARAMETER_END_BLOCK_ID]; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | uint64_t |
| 122 | getProcessId() const |
| 123 | { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 124 | BOOST_ASSERT(hasProcessId()); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 125 | return m_processId; |
| 126 | } |
| 127 | |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 128 | RepoCommandParameter& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 129 | setProcessId(uint64_t processId); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 130 | |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 131 | bool |
| 132 | hasProcessId() const |
| 133 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 134 | return m_hasFields[REPO_PARAMETER_PROCESS_ID]; |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 137 | time::milliseconds |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 138 | getInterestLifetime() const |
| 139 | { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 140 | BOOST_ASSERT(hasInterestLifetime()); |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 141 | return m_interestLifetime; |
| 142 | } |
| 143 | |
| 144 | RepoCommandParameter& |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 145 | setInterestLifetime(time::milliseconds interestLifetime); |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 146 | |
| 147 | bool |
| 148 | hasInterestLifetime() const |
| 149 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 150 | return m_hasFields[REPO_PARAMETER_INTEREST_LIFETIME]; |
| 151 | } |
| 152 | |
| 153 | const std::vector<bool>& |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 154 | getPresentFields() const |
| 155 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 156 | return m_hasFields; |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Alexander Afanasyev | c0e2658 | 2017-08-13 21:16:49 -0400 | [diff] [blame] | 159 | template<ndn::encoding::Tag T> |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 160 | size_t |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 161 | wireEncode(ndn::EncodingImpl<T>& block) const; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 162 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 163 | Block |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 164 | wireEncode() const override; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 165 | |
| 166 | void |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 167 | wireDecode(const Block& wire) override; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 168 | |
| 169 | private: |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 170 | std::vector<bool> m_hasFields; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 171 | Name m_name; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 172 | uint64_t m_startBlockId; |
| 173 | uint64_t m_endBlockId; |
| 174 | uint64_t m_processId; |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 175 | time::milliseconds m_interestLifetime; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 176 | |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 177 | mutable Block m_wire; |
| 178 | }; |
| 179 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 180 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(RepoCommandParameter); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 181 | |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 182 | } // namespace repo |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 183 | |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 184 | #endif // REPO_REPO_COMMAND_PARAMETER_HPP |