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-2018 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_MGMT_NFD_CONTROL_COMMAND_HPP
23 #define NDN_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  explicit
44  ArgumentError(const std::string& what)
45  : std::invalid_argument(what)
46  {
47  }
48  };
49 
50  virtual
52 
56  virtual void
57  validateRequest(const ControlParameters& parameters) const;
58 
61  virtual void
62  applyDefaultsToRequest(ControlParameters& parameters) const;
63 
67  virtual void
68  validateResponse(const ControlParameters& parameters) const;
69 
72  virtual void
73  applyDefaultsToResponse(ControlParameters& parameters) const;
74 
78  Name
79  getRequestName(const Name& commandPrefix, const ControlParameters& parameters) const;
80 
81 protected:
82  ControlCommand(const std::string& module, const std::string& verb);
83 
85  {
86  public:
88 
93  {
94  m_required[field] = true;
95  return *this;
96  }
97 
102  {
103  m_optional[field] = true;
104  return *this;
105  }
106 
111  void
112  validate(const ControlParameters& parameters) const;
113 
114  private:
115  std::vector<bool> m_required;
116  std::vector<bool> m_optional;
117  };
118 
119 protected:
130 
131 private:
132  name::Component m_module;
133  name::Component m_verb;
134 };
135 
136 
143 {
144 public:
146 
147  void
148  applyDefaultsToRequest(ControlParameters& parameters) const override;
149 
150  void
151  validateResponse(const ControlParameters& parameters) const override;
152 };
153 
154 
161 {
162 public:
164 
165  void
166  applyDefaultsToRequest(ControlParameters& parameters) const override;
167 
172  void
173  validateResponse(const ControlParameters& parameters) const override;
174 };
175 
176 
183 {
184 public:
186 
187  void
188  validateRequest(const ControlParameters& parameters) const override;
189 
190  void
191  validateResponse(const ControlParameters& parameters) const override;
192 };
193 
194 
201 {
202 public:
204 
205  void
206  applyDefaultsToRequest(ControlParameters& parameters) const override;
207 
208  void
209  validateResponse(const ControlParameters& parameters) const override;
210 };
211 
212 
219 {
220 public:
222 
223  void
224  applyDefaultsToRequest(ControlParameters& parameters) const override;
225 
226  void
227  validateResponse(const ControlParameters& parameters) const override;
228 };
229 
230 
237 {
238 public:
239  CsConfigCommand();
240 };
241 
242 
249 {
250 public:
251  CsEraseCommand();
252 
253  void
254  validateRequest(const ControlParameters& parameters) const override;
255 
256  void
257  validateResponse(const ControlParameters& parameters) const override;
258 };
259 
260 
267 {
268 public:
270 };
271 
272 
279 {
280 public:
282 
283  void
284  validateRequest(const ControlParameters& parameters) const override;
285 
286  void
287  validateResponse(const ControlParameters& parameters) const override;
288 };
289 
290 
297 {
298 public:
300 
301  void
302  applyDefaultsToRequest(ControlParameters& parameters) const override;
303 
304  void
305  validateResponse(const ControlParameters& parameters) const override;
306 };
307 
308 
315 {
316 public:
318 
319  void
320  applyDefaultsToRequest(ControlParameters& parameters) const override;
321 
322  void
323  validateResponse(const ControlParameters& parameters) const override;
324 };
325 
326 } // namespace nfd
327 } // namespace ndn
328 
329 #endif // NDN_MGMT_NFD_CONTROL_COMMAND_HPP
virtual void applyDefaultsToResponse(ControlParameters &parameters) const
apply default values to missing fields in response
represents a strategy-choice/set command
Definition: data.cpp:26
represents a fib/add-nexthop command
represents parameters in a ControlCommand request or response
FieldValidator m_requestValidator
FieldValidator for request ControlParameters.
represents a cs/config command
base class of NFD ControlCommand
virtual void validateResponse(const ControlParameters &parameters) const
validate response parameters
STL namespace.
virtual void validateRequest(const ControlParameters &parameters) const
validate request parameters
FieldValidator m_responseValidator
FieldValidator for response ControlParameters.
represents a strategy-choice/set command
represents a fib/remove-nexthop command
ControlCommand(const std::string &module, const std::string &verb)
represents a faces/create command
Name getRequestName(const Name &commandPrefix, const ControlParameters &parameters) const
construct the Name for a request Interest
FieldValidator & required(ControlParameterField field)
declare a required field
Represents an absolute name.
Definition: name.hpp:43
represents a rib/unregister command
represents a cs/erase command
represents a faces/update command
represents a rib/register command
Represents a name component.
virtual void applyDefaultsToRequest(ControlParameters &parameters) const
apply default values to missing fields in request
represents a faces/destroy command
represents an error in ControlParameters
FieldValidator & optional(ControlParameterField field)
declare an optional field