blob: 6ce45f0537476c281ccd58e5c9f60e40f3cb4e14 [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>
weijia yuan82cf9142018-10-21 12:25:02 -070027#include <ndn-cxx/mgmt/control-parameters.hpp>
weijia yuan3aa8d2b2018-03-06 15:35:57 -080028#include <ndn-cxx/name.hpp>
Shuo Chenba793e92014-03-17 17:17:16 -070029
30namespace repo {
31
32using ndn::Name;
33using ndn::Block;
34using ndn::EncodingImpl;
Shuo Chenba793e92014-03-17 17:17:16 -070035using ndn::EncodingEstimator;
36using ndn::EncodingBuffer;
Weiqi Shi098f91c2014-07-23 17:41:35 -070037using namespace ndn::time;
Shuo Chenba793e92014-03-17 17:17:16 -070038
weijia yuan82cf9142018-10-21 12:25:02 -070039enum RepoParameterField {
40 REPO_PARAMETER_NAME,
41 REPO_PARAMETER_START_BLOCK_ID,
42 REPO_PARAMETER_END_BLOCK_ID,
43 REPO_PARAMETER_PROCESS_ID,
weijia yuan82cf9142018-10-21 12:25:02 -070044 REPO_PARAMETER_INTEREST_LIFETIME,
45 REPO_PARAMETER_UBOUND
46};
47
48const std::string REPO_PARAMETER_FIELD[REPO_PARAMETER_UBOUND] = {
49 "Name",
50 "StartBlockId",
51 "EndBlockId",
52 "ProcessId",
weijia yuan82cf9142018-10-21 12:25:02 -070053 "InterestLifetime"
54};
55
Shuo Chenba793e92014-03-17 17:17:16 -070056/**
57* @brief Class defining abstraction of parameter of command for NDN Repo Protocol
Alexander Afanasyev42290b22017-03-09 12:58:29 -080058* @sa link https://redmine.named-data.net/projects/repo-ng/wiki/Repo_Protocol_Specification#RepoCommandParameter
Shuo Chenba793e92014-03-17 17:17:16 -070059**/
60
weijia yuan82cf9142018-10-21 12:25:02 -070061class RepoCommandParameter : public ndn::mgmt::ControlParameters
Shuo Chenba793e92014-03-17 17:17:16 -070062{
63public:
Junxiao Shica188d72014-10-19 09:49:40 -070064 class Error : public ndn::tlv::Error
Shuo Chenba793e92014-03-17 17:17:16 -070065 {
66 public:
67 explicit
68 Error(const std::string& what)
Junxiao Shica188d72014-10-19 09:49:40 -070069 : ndn::tlv::Error(what)
Shuo Chenba793e92014-03-17 17:17:16 -070070 {
71 }
72 };
73
74 RepoCommandParameter()
weijia yuan82cf9142018-10-21 12:25:02 -070075 : m_hasFields(REPO_PARAMETER_UBOUND)
Shuo Chenba793e92014-03-17 17:17:16 -070076 {
77 }
78
79 explicit
80 RepoCommandParameter(const Block& block)
weijia yuan82cf9142018-10-21 12:25:02 -070081 : m_hasFields(REPO_PARAMETER_UBOUND)
Shuo Chenba793e92014-03-17 17:17:16 -070082 {
83 wireDecode(block);
84 }
85
86 const Name&
87 getName() const
88 {
89 return m_name;
90 }
91
92 RepoCommandParameter&
weijia yuan82cf9142018-10-21 12:25:02 -070093 setName(const Name& name);
Shuo Chenba793e92014-03-17 17:17:16 -070094
95 bool
96 hasName() const
97 {
weijia yuan82cf9142018-10-21 12:25:02 -070098 return m_hasFields[REPO_PARAMETER_NAME];
Shuo Chenba793e92014-03-17 17:17:16 -070099 }
100
Shuo Chenba793e92014-03-17 17:17:16 -0700101
102 uint64_t
103 getStartBlockId() const
104 {
105 assert(hasStartBlockId());
106 return m_startBlockId;
107 }
108
109 RepoCommandParameter&
weijia yuan82cf9142018-10-21 12:25:02 -0700110 setStartBlockId(uint64_t startBlockId);
Shuo Chenba793e92014-03-17 17:17:16 -0700111
112 bool
113 hasStartBlockId() const
114 {
weijia yuan82cf9142018-10-21 12:25:02 -0700115 return m_hasFields[REPO_PARAMETER_START_BLOCK_ID];
Shuo Chenba793e92014-03-17 17:17:16 -0700116 }
117
118 uint64_t
119 getEndBlockId() const
120 {
121 assert(hasEndBlockId());
122 return m_endBlockId;
123 }
124
125 RepoCommandParameter&
weijia yuan82cf9142018-10-21 12:25:02 -0700126 setEndBlockId(uint64_t endBlockId);
Shuo Chenba793e92014-03-17 17:17:16 -0700127
128 bool
129 hasEndBlockId() const
130 {
weijia yuan82cf9142018-10-21 12:25:02 -0700131 return m_hasFields[REPO_PARAMETER_END_BLOCK_ID];
Shuo Chenba793e92014-03-17 17:17:16 -0700132 }
133
134 uint64_t
135 getProcessId() const
136 {
137 assert(hasProcessId());
138 return m_processId;
139 }
140
Shuo Chenba793e92014-03-17 17:17:16 -0700141 RepoCommandParameter&
weijia yuan82cf9142018-10-21 12:25:02 -0700142 setProcessId(uint64_t processId);
Shuo Chenba793e92014-03-17 17:17:16 -0700143
Weiqi Shi098f91c2014-07-23 17:41:35 -0700144 bool
145 hasProcessId() const
146 {
weijia yuan82cf9142018-10-21 12:25:02 -0700147 return m_hasFields[REPO_PARAMETER_PROCESS_ID];
Weiqi Shi098f91c2014-07-23 17:41:35 -0700148 }
149
Weiqi Shi098f91c2014-07-23 17:41:35 -0700150 milliseconds
151 getInterestLifetime() const
152 {
153 assert(hasInterestLifetime());
154 return m_interestLifetime;
155 }
156
157 RepoCommandParameter&
weijia yuan82cf9142018-10-21 12:25:02 -0700158 setInterestLifetime(milliseconds interestLifetime);
Weiqi Shi098f91c2014-07-23 17:41:35 -0700159
160 bool
161 hasInterestLifetime() const
162 {
weijia yuan82cf9142018-10-21 12:25:02 -0700163 return m_hasFields[REPO_PARAMETER_INTEREST_LIFETIME];
164 }
165
166 const std::vector<bool>&
167 getPresentFields() const {
168 return m_hasFields;
Weiqi Shi098f91c2014-07-23 17:41:35 -0700169 }
170
Alexander Afanasyevc0e26582017-08-13 21:16:49 -0400171 template<ndn::encoding::Tag T>
Shuo Chenba793e92014-03-17 17:17:16 -0700172 size_t
173 wireEncode(EncodingImpl<T>& block) const;
174
weijia yuan82cf9142018-10-21 12:25:02 -0700175 Block
Shuo Chenba793e92014-03-17 17:17:16 -0700176 wireEncode() const;
177
178 void
179 wireDecode(const Block& wire);
180
181private:
weijia yuan82cf9142018-10-21 12:25:02 -0700182 std::vector<bool> m_hasFields;
Shuo Chenba793e92014-03-17 17:17:16 -0700183 Name m_name;
Shuo Chenba793e92014-03-17 17:17:16 -0700184 uint64_t m_startBlockId;
185 uint64_t m_endBlockId;
186 uint64_t m_processId;
Weiqi Shi098f91c2014-07-23 17:41:35 -0700187 milliseconds m_interestLifetime;
Shuo Chenba793e92014-03-17 17:17:16 -0700188
Shuo Chenba793e92014-03-17 17:17:16 -0700189 mutable Block m_wire;
190};
191
weijia yuan82cf9142018-10-21 12:25:02 -0700192NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(RepoCommandParameter);
Shuo Chenba793e92014-03-17 17:17:16 -0700193
Alexander Afanasyev39d98072014-05-04 12:46:29 -0700194} // namespace repo
Shuo Chenba793e92014-03-17 17:17:16 -0700195
Alexander Afanasyev39d98072014-05-04 12:46:29 -0700196#endif // REPO_REPO_COMMAND_PARAMETER_HPP