blob: 1ad212f41edb2cadafad9484b08be44bc3bf3982 [file] [log] [blame]
Alexander Afanasyeve1e6f2a2014-04-25 11:28:12 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyevc0e26582017-08-13 21:16:49 -04002/*
weijia yuan82cf9142018-10-21 12:25:02 -07003 * Copyright (c) 2014-2018, Regents of the University of California.
Alexander Afanasyeve1e6f2a2014-04-25 11:28:12 -07004 *
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 Chenba793e92014-03-17 17:17:16 -070018 */
19
Alexander Afanasyev39d98072014-05-04 12:46:29 -070020#ifndef REPO_REPO_COMMAND_PARAMETER_HPP
21#define REPO_REPO_COMMAND_PARAMETER_HPP
Shuo Chenba793e92014-03-17 17:17:16 -070022
Alexander Afanasyevc0e26582017-08-13 21:16:49 -040023#include "repo-tlv.hpp"
24
Alexander Afanasyeve291caf2014-04-25 11:17:36 -070025#include <ndn-cxx/encoding/encoding-buffer.hpp>
Alexander Afanasyevd3e9da12014-11-12 11:31:31 -080026#include <ndn-cxx/encoding/block-helpers.hpp>
Alexander Afanasyeve291caf2014-04-25 11:17:36 -070027#include <ndn-cxx/name.hpp>
28#include <ndn-cxx/selectors.hpp>
weijia yuan82cf9142018-10-21 12:25:02 -070029#include <ndn-cxx/mgmt/control-parameters.hpp>
Shuo Chenba793e92014-03-17 17:17:16 -070030
31namespace repo {
32
33using ndn::Name;
34using ndn::Block;
35using ndn::EncodingImpl;
36using ndn::Selectors;
37using ndn::EncodingEstimator;
38using ndn::EncodingBuffer;
Weiqi Shi098f91c2014-07-23 17:41:35 -070039using namespace ndn::time;
Shuo Chenba793e92014-03-17 17:17:16 -070040
weijia yuan82cf9142018-10-21 12:25:02 -070041enum 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
52const 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 Chenba793e92014-03-17 17:17:16 -070062/**
63* @brief Class defining abstraction of parameter of command for NDN Repo Protocol
Alexander Afanasyev42290b22017-03-09 12:58:29 -080064* @sa link https://redmine.named-data.net/projects/repo-ng/wiki/Repo_Protocol_Specification#RepoCommandParameter
Shuo Chenba793e92014-03-17 17:17:16 -070065**/
66
weijia yuan82cf9142018-10-21 12:25:02 -070067class RepoCommandParameter : public ndn::mgmt::ControlParameters
Shuo Chenba793e92014-03-17 17:17:16 -070068{
69public:
Junxiao Shica188d72014-10-19 09:49:40 -070070 class Error : public ndn::tlv::Error
Shuo Chenba793e92014-03-17 17:17:16 -070071 {
72 public:
73 explicit
74 Error(const std::string& what)
Junxiao Shica188d72014-10-19 09:49:40 -070075 : ndn::tlv::Error(what)
Shuo Chenba793e92014-03-17 17:17:16 -070076 {
77 }
78 };
79
80 RepoCommandParameter()
weijia yuan82cf9142018-10-21 12:25:02 -070081 : m_hasFields(REPO_PARAMETER_UBOUND)
Shuo Chenba793e92014-03-17 17:17:16 -070082 {
83 }
84
85 explicit
86 RepoCommandParameter(const Block& block)
weijia yuan82cf9142018-10-21 12:25:02 -070087 : m_hasFields(REPO_PARAMETER_UBOUND)
Shuo Chenba793e92014-03-17 17:17:16 -070088 {
89 wireDecode(block);
90 }
91
92 const Name&
93 getName() const
94 {
95 return m_name;
96 }
97
98 RepoCommandParameter&
weijia yuan82cf9142018-10-21 12:25:02 -070099 setName(const Name& name);
Shuo Chenba793e92014-03-17 17:17:16 -0700100
101 bool
102 hasName() const
103 {
weijia yuan82cf9142018-10-21 12:25:02 -0700104 return m_hasFields[REPO_PARAMETER_NAME];
Shuo Chenba793e92014-03-17 17:17:16 -0700105 }
106
107 const Selectors&
108 getSelectors() const
109 {
110 return m_selectors;
111 }
112
113 RepoCommandParameter&
weijia yuan82cf9142018-10-21 12:25:02 -0700114 setSelectors(const Selectors& selectors);
Shuo Chenba793e92014-03-17 17:17:16 -0700115
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 yuan82cf9142018-10-21 12:25:02 -0700130 setStartBlockId(uint64_t startBlockId);
Shuo Chenba793e92014-03-17 17:17:16 -0700131
132 bool
133 hasStartBlockId() const
134 {
weijia yuan82cf9142018-10-21 12:25:02 -0700135 return m_hasFields[REPO_PARAMETER_START_BLOCK_ID];
Shuo Chenba793e92014-03-17 17:17:16 -0700136 }
137
138 uint64_t
139 getEndBlockId() const
140 {
141 assert(hasEndBlockId());
142 return m_endBlockId;
143 }
144
145 RepoCommandParameter&
weijia yuan82cf9142018-10-21 12:25:02 -0700146 setEndBlockId(uint64_t endBlockId);
Shuo Chenba793e92014-03-17 17:17:16 -0700147
148 bool
149 hasEndBlockId() const
150 {
weijia yuan82cf9142018-10-21 12:25:02 -0700151 return m_hasFields[REPO_PARAMETER_END_BLOCK_ID];
Shuo Chenba793e92014-03-17 17:17:16 -0700152 }
153
154 uint64_t
155 getProcessId() const
156 {
157 assert(hasProcessId());
158 return m_processId;
159 }
160
Shuo Chenba793e92014-03-17 17:17:16 -0700161 RepoCommandParameter&
weijia yuan82cf9142018-10-21 12:25:02 -0700162 setProcessId(uint64_t processId);
Shuo Chenba793e92014-03-17 17:17:16 -0700163
Weiqi Shi098f91c2014-07-23 17:41:35 -0700164 bool
165 hasProcessId() const
166 {
weijia yuan82cf9142018-10-21 12:25:02 -0700167 return m_hasFields[REPO_PARAMETER_PROCESS_ID];
Weiqi Shi098f91c2014-07-23 17:41:35 -0700168 }
169
170 uint64_t
171 getMaxInterestNum() const
172 {
173 assert(hasMaxInterestNum());
174 return m_maxInterestNum;
175 }
176
177 RepoCommandParameter&
weijia yuan82cf9142018-10-21 12:25:02 -0700178 setMaxInterestNum(uint64_t maxInterestNum);
Weiqi Shi098f91c2014-07-23 17:41:35 -0700179
180 bool
181 hasMaxInterestNum() const
182 {
weijia yuan82cf9142018-10-21 12:25:02 -0700183 return m_hasFields[REPO_PARAMETER_MAX_INTEREST_NUM];
Weiqi Shi098f91c2014-07-23 17:41:35 -0700184 }
185
186 milliseconds
187 getWatchTimeout() const
188 {
189 assert(hasWatchTimeout());
190 return m_watchTimeout;
191 }
192
193 RepoCommandParameter&
weijia yuan82cf9142018-10-21 12:25:02 -0700194 setWatchTimeout(milliseconds watchTimeout);
Weiqi Shi098f91c2014-07-23 17:41:35 -0700195
196 bool
197 hasWatchTimeout() const
198 {
weijia yuan82cf9142018-10-21 12:25:02 -0700199 return m_hasFields[REPO_PARAMETER_WATCH_TIME_OUT];
Weiqi Shi098f91c2014-07-23 17:41:35 -0700200 }
201
202 milliseconds
203 getInterestLifetime() const
204 {
205 assert(hasInterestLifetime());
206 return m_interestLifetime;
207 }
208
209 RepoCommandParameter&
weijia yuan82cf9142018-10-21 12:25:02 -0700210 setInterestLifetime(milliseconds interestLifetime);
Weiqi Shi098f91c2014-07-23 17:41:35 -0700211
212 bool
213 hasInterestLifetime() const
214 {
weijia yuan82cf9142018-10-21 12:25:02 -0700215 return m_hasFields[REPO_PARAMETER_INTEREST_LIFETIME];
216 }
217
218 const std::vector<bool>&
219 getPresentFields() const {
220 return m_hasFields;
Weiqi Shi098f91c2014-07-23 17:41:35 -0700221 }
222
Alexander Afanasyevc0e26582017-08-13 21:16:49 -0400223 template<ndn::encoding::Tag T>
Shuo Chenba793e92014-03-17 17:17:16 -0700224 size_t
225 wireEncode(EncodingImpl<T>& block) const;
226
weijia yuan82cf9142018-10-21 12:25:02 -0700227 Block
Shuo Chenba793e92014-03-17 17:17:16 -0700228 wireEncode() const;
229
230 void
231 wireDecode(const Block& wire);
232
233private:
weijia yuan82cf9142018-10-21 12:25:02 -0700234 std::vector<bool> m_hasFields;
Shuo Chenba793e92014-03-17 17:17:16 -0700235 Name m_name;
236 Selectors m_selectors;
237 uint64_t m_startBlockId;
238 uint64_t m_endBlockId;
239 uint64_t m_processId;
Weiqi Shi098f91c2014-07-23 17:41:35 -0700240 uint64_t m_maxInterestNum;
241 milliseconds m_watchTimeout;
242 milliseconds m_interestLifetime;
Shuo Chenba793e92014-03-17 17:17:16 -0700243
Shuo Chenba793e92014-03-17 17:17:16 -0700244 mutable Block m_wire;
245};
246
weijia yuan82cf9142018-10-21 12:25:02 -0700247NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(RepoCommandParameter);
Shuo Chenba793e92014-03-17 17:17:16 -0700248
Alexander Afanasyev39d98072014-05-04 12:46:29 -0700249} // namespace repo
Shuo Chenba793e92014-03-17 17:17:16 -0700250
Alexander Afanasyev39d98072014-05-04 12:46:29 -0700251#endif // REPO_REPO_COMMAND_PARAMETER_HPP