blob: cff12a620bb60eaf54c3a1e8c38a5a3fb335abac [file] [log] [blame]
Alexander Afanasyeve1e6f2a2014-04-25 11:28:12 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento11904062022-04-14 22:33:28 -04002/*
3 * 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_RESPONSE_HPP
21#define REPO_REPO_COMMAND_RESPONSE_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>
Davide Pesavento11904062022-04-14 22:33:28 -040027#include <ndn-cxx/mgmt/control-response.hpp>
Shuo Chenba793e92014-03-17 17:17:16 -070028
29namespace repo {
30
Shuo Chenba793e92014-03-17 17:17:16 -070031/**
Davide Pesavento11904062022-04-14 22:33:28 -040032 * @brief Class defining abstraction of Response for NDN Repo Protocol
33 * @sa link https://redmine.named-data.net/projects/repo-ng/wiki/Repo_Protocol_Specification#Repo-Command-Response
34 */
weijia yuan82cf9142018-10-21 12:25:02 -070035class RepoCommandResponse : public ndn::mgmt::ControlResponse
Shuo Chenba793e92014-03-17 17:17:16 -070036{
37public:
Davide Pesavento11904062022-04-14 22:33:28 -040038 class Error : public tlv::Error
Shuo Chenba793e92014-03-17 17:17:16 -070039 {
40 public:
Davide Pesavento11904062022-04-14 22:33:28 -040041 using tlv::Error::Error;
Shuo Chenba793e92014-03-17 17:17:16 -070042 };
43
Davide Pesavento11904062022-04-14 22:33:28 -040044 RepoCommandResponse() = default;
45
weijia yuan82cf9142018-10-21 12:25:02 -070046 RepoCommandResponse(uint32_t code, const std::string& text)
47 : ndn::mgmt::ControlResponse(code, text)
48 , m_hasStartBlockId(false)
Shuo Chenba793e92014-03-17 17:17:16 -070049 , m_hasEndBlockId(false)
50 , m_hasProcessId(false)
51 , m_hasInsertNum(false)
52 , m_hasDeleteNum(false)
53 , m_hasStatusCode(false)
54 {
55 }
56
57 explicit
58 RepoCommandResponse(const Block& block)
59 {
60 wireDecode(block);
61 }
62
63 uint64_t
64 getStartBlockId() const
65 {
66 return m_startBlockId;
67 }
68
69 RepoCommandResponse&
weijia yuan82cf9142018-10-21 12:25:02 -070070 setStartBlockId(uint64_t startBlockId);
Shuo Chenba793e92014-03-17 17:17:16 -070071
72 bool
weijia yuan82cf9142018-10-21 12:25:02 -070073 hasStartBlockId() const;
Shuo Chenba793e92014-03-17 17:17:16 -070074
75 uint64_t
76 getEndBlockId() const
77 {
Davide Pesavento11904062022-04-14 22:33:28 -040078 BOOST_ASSERT(hasEndBlockId());
Shuo Chenba793e92014-03-17 17:17:16 -070079 return m_endBlockId;
80 }
81
82 RepoCommandResponse&
weijia yuan82cf9142018-10-21 12:25:02 -070083 setEndBlockId(uint64_t endBlockId);
Shuo Chenba793e92014-03-17 17:17:16 -070084
85 bool
weijia yuan82cf9142018-10-21 12:25:02 -070086 hasEndBlockId() const;
Shuo Chenba793e92014-03-17 17:17:16 -070087
88 uint64_t
89 getProcessId() const
90 {
91 return m_processId;
92 }
93
94 RepoCommandResponse&
weijia yuan82cf9142018-10-21 12:25:02 -070095 setProcessId(uint64_t processId);
Shuo Chenba793e92014-03-17 17:17:16 -070096
97 bool
weijia yuan82cf9142018-10-21 12:25:02 -070098 hasProcessId() const;
Shuo Chenba793e92014-03-17 17:17:16 -070099
100 RepoCommandResponse&
weijia yuan82cf9142018-10-21 12:25:02 -0700101 setCode(uint32_t statusCode);
Shuo Chenba793e92014-03-17 17:17:16 -0700102
103 bool
weijia yuan82cf9142018-10-21 12:25:02 -0700104 hasStatusCode() const;
Shuo Chenba793e92014-03-17 17:17:16 -0700105
106 uint64_t
107 getInsertNum() const
108 {
109 return m_insertNum;
110 }
111
112 RepoCommandResponse&
weijia yuan82cf9142018-10-21 12:25:02 -0700113 setInsertNum(uint64_t insertNum);
Shuo Chenba793e92014-03-17 17:17:16 -0700114
115 bool
weijia yuan82cf9142018-10-21 12:25:02 -0700116 hasInsertNum() const;
Shuo Chenba793e92014-03-17 17:17:16 -0700117
118 uint64_t
119 getDeleteNum() const
120 {
121 return m_deleteNum;
122 }
123
124 RepoCommandResponse&
weijia yuan82cf9142018-10-21 12:25:02 -0700125 setDeleteNum(uint64_t deleteNum);
Shuo Chenba793e92014-03-17 17:17:16 -0700126
127 bool
weijia yuan82cf9142018-10-21 12:25:02 -0700128 hasDeleteNum() const;
Shuo Chenba793e92014-03-17 17:17:16 -0700129
Alexander Afanasyevc0e26582017-08-13 21:16:49 -0400130 template<ndn::encoding::Tag T>
Shuo Chenba793e92014-03-17 17:17:16 -0700131 size_t
Davide Pesavento11904062022-04-14 22:33:28 -0400132 wireEncode(ndn::EncodingImpl<T>& block) const;
Shuo Chenba793e92014-03-17 17:17:16 -0700133
134 const Block&
135 wireEncode() const;
136
137 void
138 wireDecode(const Block& wire);
139
140private:
Shuo Chenba793e92014-03-17 17:17:16 -0700141 uint64_t m_startBlockId;
142 uint64_t m_endBlockId;
143 uint64_t m_processId;
144 uint64_t m_insertNum;
145 uint64_t m_deleteNum;
146
147 bool m_hasStartBlockId;
148 bool m_hasEndBlockId;
149 bool m_hasProcessId;
150 bool m_hasInsertNum;
151 bool m_hasDeleteNum;
152 bool m_hasStatusCode;
153
154 mutable Block m_wire;
155};
156
weijia yuan82cf9142018-10-21 12:25:02 -0700157NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(RepoCommandResponse);
Alexander Afanasyev39d98072014-05-04 12:46:29 -0700158
159} // namespace repo
160
161#endif // REPO_REPO_COMMAND_RESPONSE_HPP