status-dataset-context.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2023 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_CXX_MGMT_STATUS_DATASET_CONTEXT_HPP
23 #define NDN_CXX_MGMT_STATUS_DATASET_CONTEXT_HPP
24 
25 #include "ndn-cxx/interest.hpp"
27 
28 namespace ndn::mgmt {
29 
33 class StatusDatasetContext : noncopyable
34 {
35 public:
39  const Name&
40  getPrefix() const
41  {
42  return m_prefix;
43  }
44 
59  setPrefix(const Name& prefix);
60 
65  void
66  append(span<const uint8_t> bytes);
67 
72  void
73  end();
74 
84  void
85  reject(const ControlResponse& resp = ControlResponse().setCode(400));
86 
88  using DataSender = std::function<void(const Name& dataName, const Block& content, bool isFinalBlock)>;
89  using NackSender = std::function<void(const ControlResponse&)>;
90 
91  StatusDatasetContext(const Interest& interest, DataSender dataSender, NackSender nackSender);
92 
93 private:
94  friend class Dispatcher;
95 
96  const Interest& m_interest;
97  DataSender m_dataSender;
98  NackSender m_nackSender;
99  Name m_prefix;
100  std::vector<uint8_t> m_buffer;
101  uint64_t m_segmentNo = 0;
102 
103  enum class State {
104  INITIAL,
105  RESPONDED,
106  FINALIZED,
107  };
108  State m_state = State::INITIAL;
109 };
110 
111 } // namespace ndn::mgmt
112 
113 #endif // NDN_CXX_MGMT_STATUS_DATASET_CONTEXT_HPP
Represents a TLV element of the NDN packet format.
Definition: block.hpp:45
Represents an Interest packet.
Definition: interest.hpp:50
Represents an absolute name.
Definition: name.hpp:45
ControlCommand response.
Implements a request dispatcher on server side of NFD Management protocol.
Definition: dispatcher.hpp:137
Provides a context for generating the response to a StatusDataset request.
StatusDatasetContext & setPrefix(const Name &prefix)
Changes the prefix of the response Data packets.
const Name & getPrefix() const
Returns the prefix of Data packets, with version component but without segment component.
void end()
Finalizes the response successfully after appending zero or more blocks.
void append(span< const uint8_t > bytes)
Appends a sequence of bytes to the response.
void reject(const ControlResponse &resp=ControlResponse().setCode(400))
Rejects the request.
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:49
mgmt::ControlResponse ControlResponse