blob: 2885e10aca1075a8c9dba36f462977a88388f89b [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/*
Davide Pesavento11904062022-04-14 22:33:28 -04003 * Copyright (c) 2014-2022, 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
Davide Pesavento11904062022-04-14 22:33:28 -040023#include "common.hpp"
Alexander Afanasyevc0e26582017-08-13 21:16:49 -040024#include "repo-tlv.hpp"
25
Alexander Afanasyeve291caf2014-04-25 11:17:36 -070026#include <ndn-cxx/encoding/encoding-buffer.hpp>
weijia yuan82cf9142018-10-21 12:25:02 -070027#include <ndn-cxx/mgmt/control-parameters.hpp>
Shuo Chenba793e92014-03-17 17:17:16 -070028
29namespace repo {
30
weijia yuan82cf9142018-10-21 12:25:02 -070031enum RepoParameterField {
32 REPO_PARAMETER_NAME,
33 REPO_PARAMETER_START_BLOCK_ID,
34 REPO_PARAMETER_END_BLOCK_ID,
35 REPO_PARAMETER_PROCESS_ID,
weijia yuan82cf9142018-10-21 12:25:02 -070036 REPO_PARAMETER_INTEREST_LIFETIME,
37 REPO_PARAMETER_UBOUND
38};
39
40const std::string REPO_PARAMETER_FIELD[REPO_PARAMETER_UBOUND] = {
41 "Name",
42 "StartBlockId",
43 "EndBlockId",
44 "ProcessId",
weijia yuan82cf9142018-10-21 12:25:02 -070045 "InterestLifetime"
46};
47
Shuo Chenba793e92014-03-17 17:17:16 -070048/**
Davide Pesavento11904062022-04-14 22:33:28 -040049 * @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 yuan82cf9142018-10-21 12:25:02 -070052class RepoCommandParameter : public ndn::mgmt::ControlParameters
Shuo Chenba793e92014-03-17 17:17:16 -070053{
54public:
Davide Pesavento11904062022-04-14 22:33:28 -040055 class Error : public tlv::Error
Shuo Chenba793e92014-03-17 17:17:16 -070056 {
57 public:
Davide Pesavento11904062022-04-14 22:33:28 -040058 using tlv::Error::Error;
Shuo Chenba793e92014-03-17 17:17:16 -070059 };
60
61 RepoCommandParameter()
weijia yuan82cf9142018-10-21 12:25:02 -070062 : m_hasFields(REPO_PARAMETER_UBOUND)
Shuo Chenba793e92014-03-17 17:17:16 -070063 {
64 }
65
66 explicit
67 RepoCommandParameter(const Block& block)
weijia yuan82cf9142018-10-21 12:25:02 -070068 : m_hasFields(REPO_PARAMETER_UBOUND)
Shuo Chenba793e92014-03-17 17:17:16 -070069 {
70 wireDecode(block);
71 }
72
73 const Name&
74 getName() const
75 {
76 return m_name;
77 }
78
79 RepoCommandParameter&
weijia yuan82cf9142018-10-21 12:25:02 -070080 setName(const Name& name);
Shuo Chenba793e92014-03-17 17:17:16 -070081
82 bool
83 hasName() const
84 {
weijia yuan82cf9142018-10-21 12:25:02 -070085 return m_hasFields[REPO_PARAMETER_NAME];
Shuo Chenba793e92014-03-17 17:17:16 -070086 }
87
Shuo Chenba793e92014-03-17 17:17:16 -070088
89 uint64_t
90 getStartBlockId() const
91 {
Davide Pesavento11904062022-04-14 22:33:28 -040092 BOOST_ASSERT(hasStartBlockId());
Shuo Chenba793e92014-03-17 17:17:16 -070093 return m_startBlockId;
94 }
95
96 RepoCommandParameter&
weijia yuan82cf9142018-10-21 12:25:02 -070097 setStartBlockId(uint64_t startBlockId);
Shuo Chenba793e92014-03-17 17:17:16 -070098
99 bool
100 hasStartBlockId() const
101 {
weijia yuan82cf9142018-10-21 12:25:02 -0700102 return m_hasFields[REPO_PARAMETER_START_BLOCK_ID];
Shuo Chenba793e92014-03-17 17:17:16 -0700103 }
104
105 uint64_t
106 getEndBlockId() const
107 {
Davide Pesavento11904062022-04-14 22:33:28 -0400108 BOOST_ASSERT(hasEndBlockId());
Shuo Chenba793e92014-03-17 17:17:16 -0700109 return m_endBlockId;
110 }
111
112 RepoCommandParameter&
weijia yuan82cf9142018-10-21 12:25:02 -0700113 setEndBlockId(uint64_t endBlockId);
Shuo Chenba793e92014-03-17 17:17:16 -0700114
115 bool
116 hasEndBlockId() const
117 {
weijia yuan82cf9142018-10-21 12:25:02 -0700118 return m_hasFields[REPO_PARAMETER_END_BLOCK_ID];
Shuo Chenba793e92014-03-17 17:17:16 -0700119 }
120
121 uint64_t
122 getProcessId() const
123 {
Davide Pesavento11904062022-04-14 22:33:28 -0400124 BOOST_ASSERT(hasProcessId());
Shuo Chenba793e92014-03-17 17:17:16 -0700125 return m_processId;
126 }
127
Shuo Chenba793e92014-03-17 17:17:16 -0700128 RepoCommandParameter&
weijia yuan82cf9142018-10-21 12:25:02 -0700129 setProcessId(uint64_t processId);
Shuo Chenba793e92014-03-17 17:17:16 -0700130
Weiqi Shi098f91c2014-07-23 17:41:35 -0700131 bool
132 hasProcessId() const
133 {
weijia yuan82cf9142018-10-21 12:25:02 -0700134 return m_hasFields[REPO_PARAMETER_PROCESS_ID];
Weiqi Shi098f91c2014-07-23 17:41:35 -0700135 }
136
Davide Pesavento11904062022-04-14 22:33:28 -0400137 time::milliseconds
Weiqi Shi098f91c2014-07-23 17:41:35 -0700138 getInterestLifetime() const
139 {
Davide Pesavento11904062022-04-14 22:33:28 -0400140 BOOST_ASSERT(hasInterestLifetime());
Weiqi Shi098f91c2014-07-23 17:41:35 -0700141 return m_interestLifetime;
142 }
143
144 RepoCommandParameter&
Davide Pesavento11904062022-04-14 22:33:28 -0400145 setInterestLifetime(time::milliseconds interestLifetime);
Weiqi Shi098f91c2014-07-23 17:41:35 -0700146
147 bool
148 hasInterestLifetime() const
149 {
weijia yuan82cf9142018-10-21 12:25:02 -0700150 return m_hasFields[REPO_PARAMETER_INTEREST_LIFETIME];
151 }
152
153 const std::vector<bool>&
Davide Pesavento11904062022-04-14 22:33:28 -0400154 getPresentFields() const
155 {
weijia yuan82cf9142018-10-21 12:25:02 -0700156 return m_hasFields;
Weiqi Shi098f91c2014-07-23 17:41:35 -0700157 }
158
Alexander Afanasyevc0e26582017-08-13 21:16:49 -0400159 template<ndn::encoding::Tag T>
Shuo Chenba793e92014-03-17 17:17:16 -0700160 size_t
Davide Pesavento11904062022-04-14 22:33:28 -0400161 wireEncode(ndn::EncodingImpl<T>& block) const;
Shuo Chenba793e92014-03-17 17:17:16 -0700162
weijia yuan82cf9142018-10-21 12:25:02 -0700163 Block
Davide Pesavento11904062022-04-14 22:33:28 -0400164 wireEncode() const override;
Shuo Chenba793e92014-03-17 17:17:16 -0700165
166 void
Davide Pesavento11904062022-04-14 22:33:28 -0400167 wireDecode(const Block& wire) override;
Shuo Chenba793e92014-03-17 17:17:16 -0700168
169private:
weijia yuan82cf9142018-10-21 12:25:02 -0700170 std::vector<bool> m_hasFields;
Shuo Chenba793e92014-03-17 17:17:16 -0700171 Name m_name;
Shuo Chenba793e92014-03-17 17:17:16 -0700172 uint64_t m_startBlockId;
173 uint64_t m_endBlockId;
174 uint64_t m_processId;
Davide Pesavento11904062022-04-14 22:33:28 -0400175 time::milliseconds m_interestLifetime;
Shuo Chenba793e92014-03-17 17:17:16 -0700176
Shuo Chenba793e92014-03-17 17:17:16 -0700177 mutable Block m_wire;
178};
179
weijia yuan82cf9142018-10-21 12:25:02 -0700180NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(RepoCommandParameter);
Shuo Chenba793e92014-03-17 17:17:16 -0700181
Alexander Afanasyev39d98072014-05-04 12:46:29 -0700182} // namespace repo
Shuo Chenba793e92014-03-17 17:17:16 -0700183
Alexander Afanasyev39d98072014-05-04 12:46:29 -0700184#endif // REPO_REPO_COMMAND_PARAMETER_HPP