manager-base.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NLSR_MANAGER_BASE_HPP
23 #define NLSR_MANAGER_BASE_HPP
24 
25 #include "name-prefix-list.hpp"
26 #include "test-access-control.hpp"
27 #include "lsdb.hpp"
28 #include "nfd-rib-commands.hpp"
30 #include "logger.hpp"
31 
32 #include <ndn-cxx/face.hpp>
33 #include <ndn-cxx/interest.hpp>
34 #include <ndn-cxx/mgmt/nfd/control-command.hpp>
35 #include <ndn-cxx/mgmt/dispatcher.hpp>
36 #include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
37 #include <ndn-cxx/mgmt/nfd/control-response.hpp>
38 
39 #include <boost/noncopyable.hpp>
40 
41 namespace nlsr {
42 
43 class Lsdb;
44 
45 namespace update {
46 
47 class ManagerBase : boost::noncopyable
48 {
49 public:
50  class Error : public std::runtime_error
51  {
52  public:
53  explicit
54  Error(const std::string& what)
55  : std::runtime_error(what)
56  {
57  }
58  };
59 
60 public:
61  ManagerBase(ndn::mgmt::Dispatcher& m_dispatcher,
62  const std::string& module);
63 
64 protected:
67  ndn::PartialName
68  makeRelPrefix(const std::string& verb) const;
69 
73  template<typename T>
74  bool
75  validateParameters(const ndn::mgmt::ControlParameters& parameters)
76  {
77  const ndn::nfd::ControlParameters* castParams =
78  dynamic_cast<const ndn::nfd::ControlParameters*>(&parameters);
79 
80  BOOST_ASSERT(castParams != nullptr);
81  T command;
82  try {
83  command.validateRequest(*castParams);
84  }
85  catch (const ndn::nfd::ControlCommand::ArgumentError& ae) {
86  throw ae;
87  }
88  catch (const std::exception& e) {
89  std::cerr << e.what() << std::endl;
90  return false;
91  }
92  return true;
93  }
94 
95 protected:
96  ndn::mgmt::Dispatcher& m_dispatcher;
97 
98 private:
99  std::string m_module;
100 };
101 
103 {
104 public:
105  CommandManagerBase(ndn::mgmt::Dispatcher& m_dispatcher,
106  NamePrefixList& m_namePrefixList,
107  Lsdb& lsdb,
108  const std::string& module);
109 
113  void
114  advertiseAndInsertPrefix(const ndn::Name& prefix,
115  const ndn::Interest& interest,
116  const ndn::mgmt::ControlParameters& parameters,
117  const ndn::mgmt::CommandContinuation& done);
118 
122  void
123  withdrawAndRemovePrefix(const ndn::Name& prefix,
124  const ndn::Interest& interest,
125  const ndn::mgmt::ControlParameters& parameters,
126  const ndn::mgmt::CommandContinuation& done);
127 
128 protected:
131 };
132 
133 } // namespace update
134 } // namespace nlsr
135 
136 #endif // NLSR_MANAGER_BASE_HPP
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
bool validateParameters(const ndn::mgmt::ControlParameters &parameters)
validate the parameters for a given command
STL namespace.
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California.
Error(const std::string &what)
ManagerBase(ndn::mgmt::Dispatcher &m_dispatcher, const std::string &module)
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
#define PUBLIC_WITH_TESTS_ELSE_PROTECTED
ndn::PartialName makeRelPrefix(const std::string &verb) const
generate the relative prefix for a handler by appending the verb name to the module name ...
ndn::mgmt::Dispatcher & m_dispatcher