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 | /* |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 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_PARAMETER_HPP |
| 21 | #define REPO_REPO_COMMAND_PARAMETER_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 | |
Alexander Afanasyev | e291caf | 2014-04-25 11:17:36 -0700 | [diff] [blame] | 25 | #include <ndn-cxx/encoding/encoding-buffer.hpp> |
Alexander Afanasyev | d3e9da1 | 2014-11-12 11:31:31 -0800 | [diff] [blame] | 26 | #include <ndn-cxx/encoding/block-helpers.hpp> |
Alexander Afanasyev | e291caf | 2014-04-25 11:17:36 -0700 | [diff] [blame] | 27 | #include <ndn-cxx/name.hpp> |
| 28 | #include <ndn-cxx/selectors.hpp> |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 29 | #include <ndn-cxx/mgmt/control-parameters.hpp> |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 30 | |
| 31 | namespace repo { |
| 32 | |
| 33 | using ndn::Name; |
| 34 | using ndn::Block; |
| 35 | using ndn::EncodingImpl; |
| 36 | using ndn::Selectors; |
| 37 | using ndn::EncodingEstimator; |
| 38 | using ndn::EncodingBuffer; |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 39 | using namespace ndn::time; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 40 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 41 | enum RepoParameterField { |
| 42 | REPO_PARAMETER_NAME, |
| 43 | REPO_PARAMETER_START_BLOCK_ID, |
| 44 | REPO_PARAMETER_END_BLOCK_ID, |
| 45 | REPO_PARAMETER_PROCESS_ID, |
| 46 | REPO_PARAMETER_MAX_INTEREST_NUM, |
| 47 | REPO_PARAMETER_WATCH_TIME_OUT, |
| 48 | REPO_PARAMETER_INTEREST_LIFETIME, |
| 49 | REPO_PARAMETER_UBOUND |
| 50 | }; |
| 51 | |
| 52 | const std::string REPO_PARAMETER_FIELD[REPO_PARAMETER_UBOUND] = { |
| 53 | "Name", |
| 54 | "StartBlockId", |
| 55 | "EndBlockId", |
| 56 | "ProcessId", |
| 57 | "MaxInterestNum", |
| 58 | "WatchTimeout", |
| 59 | "InterestLifetime" |
| 60 | }; |
| 61 | |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 62 | /** |
| 63 | * @brief Class defining abstraction of parameter of command for NDN Repo Protocol |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 64 | * @sa link https://redmine.named-data.net/projects/repo-ng/wiki/Repo_Protocol_Specification#RepoCommandParameter |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 65 | **/ |
| 66 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 67 | class RepoCommandParameter : public ndn::mgmt::ControlParameters |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 68 | { |
| 69 | public: |
Junxiao Shi | ca188d7 | 2014-10-19 09:49:40 -0700 | [diff] [blame] | 70 | class Error : public ndn::tlv::Error |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 71 | { |
| 72 | public: |
| 73 | explicit |
| 74 | Error(const std::string& what) |
Junxiao Shi | ca188d7 | 2014-10-19 09:49:40 -0700 | [diff] [blame] | 75 | : ndn::tlv::Error(what) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 76 | { |
| 77 | } |
| 78 | }; |
| 79 | |
| 80 | RepoCommandParameter() |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 81 | : m_hasFields(REPO_PARAMETER_UBOUND) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 82 | { |
| 83 | } |
| 84 | |
| 85 | explicit |
| 86 | RepoCommandParameter(const Block& block) |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 87 | : m_hasFields(REPO_PARAMETER_UBOUND) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 88 | { |
| 89 | wireDecode(block); |
| 90 | } |
| 91 | |
| 92 | const Name& |
| 93 | getName() const |
| 94 | { |
| 95 | return m_name; |
| 96 | } |
| 97 | |
| 98 | RepoCommandParameter& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 99 | setName(const Name& name); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 100 | |
| 101 | bool |
| 102 | hasName() const |
| 103 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 104 | return m_hasFields[REPO_PARAMETER_NAME]; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | const Selectors& |
| 108 | getSelectors() const |
| 109 | { |
| 110 | return m_selectors; |
| 111 | } |
| 112 | |
| 113 | RepoCommandParameter& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 114 | setSelectors(const Selectors& selectors); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 115 | |
| 116 | bool |
| 117 | hasSelectors() const |
| 118 | { |
| 119 | return !m_selectors.empty(); |
| 120 | } |
| 121 | |
| 122 | uint64_t |
| 123 | getStartBlockId() const |
| 124 | { |
| 125 | assert(hasStartBlockId()); |
| 126 | return m_startBlockId; |
| 127 | } |
| 128 | |
| 129 | RepoCommandParameter& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 130 | setStartBlockId(uint64_t startBlockId); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 131 | |
| 132 | bool |
| 133 | hasStartBlockId() const |
| 134 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 135 | return m_hasFields[REPO_PARAMETER_START_BLOCK_ID]; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | uint64_t |
| 139 | getEndBlockId() const |
| 140 | { |
| 141 | assert(hasEndBlockId()); |
| 142 | return m_endBlockId; |
| 143 | } |
| 144 | |
| 145 | RepoCommandParameter& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 146 | setEndBlockId(uint64_t endBlockId); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 147 | |
| 148 | bool |
| 149 | hasEndBlockId() const |
| 150 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 151 | return m_hasFields[REPO_PARAMETER_END_BLOCK_ID]; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | uint64_t |
| 155 | getProcessId() const |
| 156 | { |
| 157 | assert(hasProcessId()); |
| 158 | return m_processId; |
| 159 | } |
| 160 | |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 161 | RepoCommandParameter& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 162 | setProcessId(uint64_t processId); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 163 | |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 164 | bool |
| 165 | hasProcessId() const |
| 166 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 167 | return m_hasFields[REPO_PARAMETER_PROCESS_ID]; |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | uint64_t |
| 171 | getMaxInterestNum() const |
| 172 | { |
| 173 | assert(hasMaxInterestNum()); |
| 174 | return m_maxInterestNum; |
| 175 | } |
| 176 | |
| 177 | RepoCommandParameter& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 178 | setMaxInterestNum(uint64_t maxInterestNum); |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 179 | |
| 180 | bool |
| 181 | hasMaxInterestNum() const |
| 182 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 183 | return m_hasFields[REPO_PARAMETER_MAX_INTEREST_NUM]; |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | milliseconds |
| 187 | getWatchTimeout() const |
| 188 | { |
| 189 | assert(hasWatchTimeout()); |
| 190 | return m_watchTimeout; |
| 191 | } |
| 192 | |
| 193 | RepoCommandParameter& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 194 | setWatchTimeout(milliseconds watchTimeout); |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 195 | |
| 196 | bool |
| 197 | hasWatchTimeout() const |
| 198 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 199 | return m_hasFields[REPO_PARAMETER_WATCH_TIME_OUT]; |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | milliseconds |
| 203 | getInterestLifetime() const |
| 204 | { |
| 205 | assert(hasInterestLifetime()); |
| 206 | return m_interestLifetime; |
| 207 | } |
| 208 | |
| 209 | RepoCommandParameter& |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 210 | setInterestLifetime(milliseconds interestLifetime); |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 211 | |
| 212 | bool |
| 213 | hasInterestLifetime() const |
| 214 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 215 | return m_hasFields[REPO_PARAMETER_INTEREST_LIFETIME]; |
| 216 | } |
| 217 | |
| 218 | const std::vector<bool>& |
| 219 | getPresentFields() const { |
| 220 | return m_hasFields; |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Alexander Afanasyev | c0e2658 | 2017-08-13 21:16:49 -0400 | [diff] [blame] | 223 | template<ndn::encoding::Tag T> |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 224 | size_t |
| 225 | wireEncode(EncodingImpl<T>& block) const; |
| 226 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 227 | Block |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 228 | wireEncode() const; |
| 229 | |
| 230 | void |
| 231 | wireDecode(const Block& wire); |
| 232 | |
| 233 | private: |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 234 | std::vector<bool> m_hasFields; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 235 | Name m_name; |
| 236 | Selectors m_selectors; |
| 237 | uint64_t m_startBlockId; |
| 238 | uint64_t m_endBlockId; |
| 239 | uint64_t m_processId; |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 240 | uint64_t m_maxInterestNum; |
| 241 | milliseconds m_watchTimeout; |
| 242 | milliseconds m_interestLifetime; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 243 | |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 244 | mutable Block m_wire; |
| 245 | }; |
| 246 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 247 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(RepoCommandParameter); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 248 | |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 249 | } // namespace repo |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 250 | |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 251 | #endif // REPO_REPO_COMMAND_PARAMETER_HPP |