blob: a2432a72c181bfc4e6194ace19fd01a9a90b1393 [file] [log] [blame]
Alexander Afanasyeve1e6f2a2014-04-25 11:28:12 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
weijia yuan82cf9142018-10-21 12:25:02 -07002/**
3 * 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_RESPONSE_HPP
21#define REPO_REPO_COMMAND_RESPONSE_HPP
Shuo Chenba793e92014-03-17 17:17:16 -070022
Alexander Afanasyevc0e26582017-08-13 21:16:49 -040023#include "repo-tlv.hpp"
24
weijia yuan82cf9142018-10-21 12:25:02 -070025#include <ndn-cxx/mgmt/control-response.hpp>
Alexander Afanasyeve291caf2014-04-25 11:17:36 -070026#include <ndn-cxx/encoding/block.hpp>
Wentao Shang91fb4f22014-05-20 10:55:22 -070027#include <ndn-cxx/encoding/block-helpers.hpp>
Alexander Afanasyeve291caf2014-04-25 11:17:36 -070028#include <ndn-cxx/encoding/encoding-buffer.hpp>
29#include <ndn-cxx/encoding/tlv-nfd.hpp>
Shuo Chenba793e92014-03-17 17:17:16 -070030
31namespace repo {
32
33using ndn::Block;
34using ndn::EncodingImpl;
35using ndn::EncodingEstimator;
36using ndn::EncodingBuffer;
37
38/**
39* @brief Class defining abstraction of Response for NDN Repo Protocol
Alexander Afanasyev42290b22017-03-09 12:58:29 -080040* @sa link https://redmine.named-data.net/projects/repo-ng/wiki/Repo_Protocol_Specification#Repo-Command-Response
Shuo Chenba793e92014-03-17 17:17:16 -070041*/
weijia yuan82cf9142018-10-21 12:25:02 -070042class RepoCommandResponse : public ndn::mgmt::ControlResponse
Shuo Chenba793e92014-03-17 17:17:16 -070043{
44public:
Junxiao Shica188d72014-10-19 09:49:40 -070045 class Error : public ndn::tlv::Error
Shuo Chenba793e92014-03-17 17:17:16 -070046 {
47 public:
48 explicit
49 Error(const std::string& what)
Junxiao Shica188d72014-10-19 09:49:40 -070050 : ndn::tlv::Error(what)
Shuo Chenba793e92014-03-17 17:17:16 -070051 {
52 }
53 };
54
weijia yuan82cf9142018-10-21 12:25:02 -070055 RepoCommandResponse(uint32_t code, const std::string& text)
56 : ndn::mgmt::ControlResponse(code, text)
57 , m_hasStartBlockId(false)
Shuo Chenba793e92014-03-17 17:17:16 -070058 , m_hasEndBlockId(false)
59 , m_hasProcessId(false)
60 , m_hasInsertNum(false)
61 , m_hasDeleteNum(false)
62 , m_hasStatusCode(false)
63 {
64 }
65
weijia yuan82cf9142018-10-21 12:25:02 -070066 RepoCommandResponse(){
67 }
68
Shuo Chenba793e92014-03-17 17:17:16 -070069 explicit
70 RepoCommandResponse(const Block& block)
71 {
72 wireDecode(block);
73 }
74
75 uint64_t
76 getStartBlockId() const
77 {
78 return m_startBlockId;
79 }
80
81 RepoCommandResponse&
weijia yuan82cf9142018-10-21 12:25:02 -070082 setStartBlockId(uint64_t startBlockId);
Shuo Chenba793e92014-03-17 17:17:16 -070083
84 bool
weijia yuan82cf9142018-10-21 12:25:02 -070085 hasStartBlockId() const;
Shuo Chenba793e92014-03-17 17:17:16 -070086
87 uint64_t
88 getEndBlockId() const
89 {
90 assert(hasEndBlockId());
91 return m_endBlockId;
92 }
93
94 RepoCommandResponse&
weijia yuan82cf9142018-10-21 12:25:02 -070095 setEndBlockId(uint64_t endBlockId);
Shuo Chenba793e92014-03-17 17:17:16 -070096
97 bool
weijia yuan82cf9142018-10-21 12:25:02 -070098 hasEndBlockId() const;
Shuo Chenba793e92014-03-17 17:17:16 -070099
100 uint64_t
101 getProcessId() const
102 {
103 return m_processId;
104 }
105
106 RepoCommandResponse&
weijia yuan82cf9142018-10-21 12:25:02 -0700107 setProcessId(uint64_t processId);
Shuo Chenba793e92014-03-17 17:17:16 -0700108
109 bool
weijia yuan82cf9142018-10-21 12:25:02 -0700110 hasProcessId() const;
Shuo Chenba793e92014-03-17 17:17:16 -0700111
112 RepoCommandResponse&
weijia yuan82cf9142018-10-21 12:25:02 -0700113 setCode(uint32_t statusCode);
Shuo Chenba793e92014-03-17 17:17:16 -0700114
115 bool
weijia yuan82cf9142018-10-21 12:25:02 -0700116 hasStatusCode() const;
Shuo Chenba793e92014-03-17 17:17:16 -0700117
118 uint64_t
119 getInsertNum() const
120 {
121 return m_insertNum;
122 }
123
124 RepoCommandResponse&
weijia yuan82cf9142018-10-21 12:25:02 -0700125 setInsertNum(uint64_t insertNum);
Shuo Chenba793e92014-03-17 17:17:16 -0700126
127 bool
weijia yuan82cf9142018-10-21 12:25:02 -0700128 hasInsertNum() const;
Shuo Chenba793e92014-03-17 17:17:16 -0700129
130 uint64_t
131 getDeleteNum() const
132 {
133 return m_deleteNum;
134 }
135
136 RepoCommandResponse&
weijia yuan82cf9142018-10-21 12:25:02 -0700137 setDeleteNum(uint64_t deleteNum);
Shuo Chenba793e92014-03-17 17:17:16 -0700138
139 bool
weijia yuan82cf9142018-10-21 12:25:02 -0700140 hasDeleteNum() const;
Shuo Chenba793e92014-03-17 17:17:16 -0700141
Alexander Afanasyevc0e26582017-08-13 21:16:49 -0400142 template<ndn::encoding::Tag T>
Shuo Chenba793e92014-03-17 17:17:16 -0700143 size_t
144 wireEncode(EncodingImpl<T>& block) const;
145
146 const Block&
147 wireEncode() const;
148
149 void
150 wireDecode(const Block& wire);
151
152private:
weijia yuan82cf9142018-10-21 12:25:02 -0700153 //uint64_t m_statusCode;
Shuo Chenba793e92014-03-17 17:17:16 -0700154 uint64_t m_startBlockId;
155 uint64_t m_endBlockId;
156 uint64_t m_processId;
157 uint64_t m_insertNum;
158 uint64_t m_deleteNum;
159
160 bool m_hasStartBlockId;
161 bool m_hasEndBlockId;
162 bool m_hasProcessId;
163 bool m_hasInsertNum;
164 bool m_hasDeleteNum;
165 bool m_hasStatusCode;
166
167 mutable Block m_wire;
168};
169
weijia yuan82cf9142018-10-21 12:25:02 -0700170NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(RepoCommandResponse);
Alexander Afanasyev39d98072014-05-04 12:46:29 -0700171
172} // namespace repo
173
174#endif // REPO_REPO_COMMAND_RESPONSE_HPP