control-command.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_NFD_CONTROL_COMMAND_HPP
23 #define NDN_CXX_MGMT_NFD_CONTROL_COMMAND_HPP
24 
26 
27 namespace ndn {
28 namespace nfd {
29 
35 class ControlCommand : noncopyable
36 {
37 public:
40  class ArgumentError : public std::invalid_argument
41  {
42  public:
43  using std::invalid_argument::invalid_argument;
44  };
45 
46  virtual
48 
52  virtual void
53  validateRequest(const ControlParameters& parameters) const;
54 
57  virtual void
58  applyDefaultsToRequest(ControlParameters& parameters) const;
59 
63  virtual void
64  validateResponse(const ControlParameters& parameters) const;
65 
68  virtual void
69  applyDefaultsToResponse(ControlParameters& parameters) const;
70 
74  Name
75  getRequestName(const Name& commandPrefix, const ControlParameters& parameters) const;
76 
77 protected:
78  ControlCommand(const std::string& module, const std::string& verb);
79 
81  {
82  public:
84 
89  {
90  m_required[field] = true;
91  return *this;
92  }
93 
98  {
99  m_optional[field] = true;
100  return *this;
101  }
102 
107  void
108  validate(const ControlParameters& parameters) const;
109 
110  private:
111  std::vector<bool> m_required;
112  std::vector<bool> m_optional;
113  };
114 
115 protected:
126 
127 private:
128  name::Component m_module;
129  name::Component m_verb;
130 };
131 
132 
139 {
140 public:
142 
143  void
144  applyDefaultsToRequest(ControlParameters& parameters) const override;
145 
146  void
147  validateResponse(const ControlParameters& parameters) const override;
148 };
149 
150 
157 {
158 public:
160 
161  void
162  applyDefaultsToRequest(ControlParameters& parameters) const override;
163 
168  void
169  validateResponse(const ControlParameters& parameters) const override;
170 };
171 
172 
179 {
180 public:
182 
183  void
184  validateRequest(const ControlParameters& parameters) const override;
185 
186  void
187  validateResponse(const ControlParameters& parameters) const override;
188 };
189 
190 
197 {
198 public:
200 
201  void
202  applyDefaultsToRequest(ControlParameters& parameters) const override;
203 
204  void
205  validateResponse(const ControlParameters& parameters) const override;
206 };
207 
208 
215 {
216 public:
218 
219  void
220  applyDefaultsToRequest(ControlParameters& parameters) const override;
221 
222  void
223  validateResponse(const ControlParameters& parameters) const override;
224 };
225 
226 
233 {
234 public:
235  CsConfigCommand();
236 };
237 
238 
245 {
246 public:
247  CsEraseCommand();
248 
249  void
250  validateRequest(const ControlParameters& parameters) const override;
251 
252  void
253  validateResponse(const ControlParameters& parameters) const override;
254 };
255 
256 
263 {
264 public:
266 };
267 
268 
275 {
276 public:
278 
279  void
280  validateRequest(const ControlParameters& parameters) const override;
281 
282  void
283  validateResponse(const ControlParameters& parameters) const override;
284 };
285 
286 
293 {
294 public:
296 
297  void
298  applyDefaultsToRequest(ControlParameters& parameters) const override;
299 
300  void
301  validateResponse(const ControlParameters& parameters) const override;
302 };
303 
304 
311 {
312 public:
314 
315  void
316  applyDefaultsToRequest(ControlParameters& parameters) const override;
317 
318  void
319  validateResponse(const ControlParameters& parameters) const override;
320 };
321 
322 } // namespace nfd
323 } // namespace ndn
324 
325 #endif // NDN_CXX_MGMT_NFD_CONTROL_COMMAND_HPP
Represents an absolute name.
Definition: name.hpp:44
Represents a name component.
Represents an error in ControlParameters.
FieldValidator & required(ControlParameterField field)
Declare a required field.
FieldValidator & optional(ControlParameterField field)
Declare an optional field.
void validate(const ControlParameters &parameters) const
Verify that all required fields are present, and all present fields are either required or optional.
Base class of NFD ControlCommand.
ControlCommand(const std::string &module, const std::string &verb)
Name getRequestName(const Name &commandPrefix, const ControlParameters &parameters) const
Construct the Name for a request Interest.
virtual void validateResponse(const ControlParameters &parameters) const
Validate response parameters.
virtual void applyDefaultsToRequest(ControlParameters &parameters) const
Apply default values to missing fields in request.
virtual void validateRequest(const ControlParameters &parameters) const
Validate request parameters.
virtual void applyDefaultsToResponse(ControlParameters &parameters) const
Apply default values to missing fields in response.
FieldValidator m_responseValidator
FieldValidator for response ControlParameters.
FieldValidator m_requestValidator
FieldValidator for request ControlParameters.
Represents parameters in a ControlCommand request or response.
Represents a cs/config command.
Represents a cs/erase command.
void validateResponse(const ControlParameters &parameters) const override
Validate response parameters.
void validateRequest(const ControlParameters &parameters) const override
Validate request parameters.
Represents a faces/create command.
void validateResponse(const ControlParameters &parameters) const override
Validate response parameters.
void applyDefaultsToRequest(ControlParameters &parameters) const override
Apply default values to missing fields in request.
Represents a faces/destroy command.
void validateRequest(const ControlParameters &parameters) const override
Validate request parameters.
void validateResponse(const ControlParameters &parameters) const override
Validate response parameters.
Represents a faces/update command.
void applyDefaultsToRequest(ControlParameters &parameters) const override
Apply default values to missing fields in request.
void validateResponse(const ControlParameters &parameters) const override
Represents a fib/add-nexthop command.
void applyDefaultsToRequest(ControlParameters &parameters) const override
Apply default values to missing fields in request.
void validateResponse(const ControlParameters &parameters) const override
Validate response parameters.
Represents a fib/remove-nexthop command.
void applyDefaultsToRequest(ControlParameters &parameters) const override
Apply default values to missing fields in request.
void validateResponse(const ControlParameters &parameters) const override
Validate response parameters.
Represents a rib/register command.
void applyDefaultsToRequest(ControlParameters &parameters) const override
Apply default values to missing fields in request.
void validateResponse(const ControlParameters &parameters) const override
Validate response parameters.
Represents a rib/unregister command.
void validateResponse(const ControlParameters &parameters) const override
Validate response parameters.
void applyDefaultsToRequest(ControlParameters &parameters) const override
Apply default values to missing fields in request.
Represents a strategy-choice/set command.
Represents a strategy-choice/set command.
void validateRequest(const ControlParameters &parameters) const override
Validate request parameters.
void validateResponse(const ControlParameters &parameters) const override
Validate response parameters.
Definition: data.cpp:25