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-2022 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 {
29 namespace mgmt {
30 
34 class StatusDatasetContext : noncopyable
35 {
36 public:
40  const Name&
41  getPrefix() const
42  {
43  return m_prefix;
44  }
45 
60  setPrefix(const Name& prefix);
61 
66  void
67  append(span<const uint8_t> bytes);
68 
73  void
74  end();
75 
85  void
86  reject(const ControlResponse& resp = ControlResponse().setCode(400));
87 
89  using DataSender = std::function<void(const Name& dataName, const Block& content, bool isFinalBlock)>;
90  using NackSender = std::function<void(const ControlResponse&)>;
91 
92  StatusDatasetContext(const Interest& interest, DataSender dataSender, NackSender nackSender);
93 
94 private:
95  friend class Dispatcher;
96 
97  const Interest& m_interest;
98  DataSender m_dataSender;
99  NackSender m_nackSender;
100  Name m_prefix;
101  std::vector<uint8_t> m_buffer;
102  uint64_t m_segmentNo = 0;
103 
104  enum class State {
105  INITIAL,
106  RESPONDED,
107  FINALIZED,
108  };
109  State m_state = State::INITIAL;
110 };
111 
112 } // namespace mgmt
113 } // namespace ndn
114 
115 #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:44
ControlCommand response.
Implements a request dispatcher on server side of NFD Management protocol.
Definition: dispatcher.hpp:131
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:48
mgmt::ControlResponse ControlResponse
Definition: data.cpp:25