All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
manager-base.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2025, Regents of the University of California,
4  * Arizona Board of Regents,
5  * Colorado State University,
6  * University Pierre & Marie Curie, Sorbonne University,
7  * Washington University in St. Louis,
8  * Beijing Institute of Technology,
9  * The University of Memphis.
10  *
11  * This file is part of NFD (Named Data Networking Forwarding Daemon).
12  * See AUTHORS.md for complete list of NFD authors and contributors.
13  *
14  * NFD is free software: you can redistribute it and/or modify it under the terms
15  * of the GNU General Public License as published by the Free Software Foundation,
16  * either version 3 of the License, or (at your option) any later version.
17  *
18  * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20  * PURPOSE. See the GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along with
23  * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #ifndef NFD_DAEMON_MGMT_MANAGER_BASE_HPP
27 #define NFD_DAEMON_MGMT_MANAGER_BASE_HPP
28 
30 
31 #include <ndn-cxx/mgmt/dispatcher.hpp>
32 #include <ndn-cxx/mgmt/nfd/control-command.hpp>
33 #include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
34 #include <ndn-cxx/mgmt/nfd/control-response.hpp>
35 
36 #include <functional>
37 
38 namespace nfd {
39 
40 using ndn::mgmt::Dispatcher;
41 using ndn::mgmt::CommandContinuation;
42 using ndn::nfd::ControlParameters;
43 using ndn::nfd::ControlResponse;
44 
49 class ManagerBase : noncopyable
50 {
51 public:
52  class Error : public std::runtime_error
53  {
54  public:
55  using std::runtime_error::runtime_error;
56  };
57 
58  const std::string&
59  getModule() const
60  {
61  return m_module;
62  }
63 
64 protected:
68  ManagerBase(std::string_view module, Dispatcher& dispatcher);
69 
70  ManagerBase(std::string_view module, Dispatcher& dispatcher,
71  CommandAuthenticator& authenticator);
72 
73  // ManagerBase is not supposed to be used polymorphically, so we make the destructor
74  // protected to prevent deletion of derived objects through a pointer to the base class,
75  // which would be UB when the destructor is non-virtual.
77 
78 NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED: // registrations to the dispatcher
79  template<typename Command>
80  using ControlCommandHandler = std::function<void(const Name& prefix, const Interest& interest,
81  const typename Command::RequestParameters& parameters,
82  const CommandContinuation& done)>;
83 
84  template<typename Command>
85  void
87  {
88  auto handle = [h = std::move(handler)] (const auto& prefix, const auto& interest,
89  const auto& params, const auto& done) {
90  const auto& reqParams = static_cast<const typename Command::RequestParameters&>(params);
91  h(prefix, interest, reqParams, done);
92  };
93  m_dispatcher.addControlCommand<Command>(makeAuthorization(Command::verb.toUri()),
94  std::move(handle));
95  }
96 
97  void
98  registerStatusDatasetHandler(const std::string& verb,
99  const ndn::mgmt::StatusDatasetHandler& handler);
100 
101  ndn::mgmt::PostNotification
102  registerNotificationStream(const std::string& verb);
103 
111  static std::string
112  extractSigner(const Interest& interest);
113 
118  virtual ndn::mgmt::Authorization
119  makeAuthorization(const std::string& verb);
120 
127  PartialName
128  makeRelPrefix(const std::string& verb) const
129  {
130  return PartialName(m_module).append(verb);
131  }
132 
133 private:
134  std::string m_module;
135  Dispatcher& m_dispatcher;
136  CommandAuthenticator* m_authenticator = nullptr;
137 };
138 
139 } // namespace nfd
140 
141 #endif // NFD_DAEMON_MGMT_MANAGER_BASE_HPP
Provides ControlCommand authorization according to NFD's configuration file.
A collection of common functions shared by all NFD managers, such as communicating with the dispatche...
void registerCommandHandler(ControlCommandHandler< Command > handler)
const std::string & getModule() const
ndn::mgmt::PostNotification registerNotificationStream(const std::string &verb)
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
static std::string extractSigner(const Interest &interest)
Extracts the name from the KeyLocator of a ControlCommand request.
std::function< void(const Name &prefix, const Interest &interest, const typename Command::RequestParameters &parameters, const CommandContinuation &done)> ControlCommandHandler
ManagerBase(std::string_view module, Dispatcher &dispatcher)
#define NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED
Definition: common.hpp:40
#define NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
-status-http-server
Definition: common.hpp:71