26 #ifndef NFD_DAEMON_MGMT_MANAGER_BASE_HPP
27 #define NFD_DAEMON_MGMT_MANAGER_BASE_HPP
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>
40 using ndn::mgmt::Dispatcher;
41 using ndn::nfd::ControlCommand;
42 using ndn::nfd::ControlParameters;
43 using ndn::nfd::ControlResponse;
52 class Error :
public std::runtime_error
55 using std::runtime_error::runtime_error;
68 ManagerBase(std::string_view module, Dispatcher& dispatcher);
70 ManagerBase(std::string_view module, Dispatcher& dispatcher,
81 const Name& prefix,
const Interest& interest,
82 const ControlParameters& parameters,
83 const ndn::mgmt::CommandContinuation done)>;
85 template<
typename Command>
92 const ndn::mgmt::StatusDatasetHandler& handler);
94 ndn::mgmt::PostNotification
111 virtual ndn::mgmt::Authorization
112 makeAuthorization(
const std::string& verb);
120 [[nodiscard]]
static bool
121 validateParameters(
const ControlCommand& command,
122 const ndn::mgmt::ControlParameters& parameters);
128 handleCommand(shared_ptr<ControlCommand> command,
130 const Name& prefix,
const Interest& interest,
131 const ndn::mgmt::ControlParameters& params,
132 const ndn::mgmt::CommandContinuation& done);
141 makeRelPrefix(
const std::string& verb)
143 return PartialName(m_module).append(verb);
147 std::string m_module;
148 Dispatcher& m_dispatcher;
152 template<
typename Command>
157 auto command = make_shared<Command>();
159 m_dispatcher.addControlCommand<ControlParameters>(
161 makeAuthorization(verb),
162 [=] (
const auto& params) {
return validateParameters(*command, params); },
163 [=] (
auto&&... args) { handleCommand(command, handler, std::forward<decltype(args)>(args)...); });
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...
const std::string & getModule() const
ndn::mgmt::PostNotification registerNotificationStream(const std::string &verb)
std::function< void(const ControlCommand &command, const Name &prefix, const Interest &interest, const ControlParameters ¶meters, const ndn::mgmt::CommandContinuation done)> ControlCommandHandler
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
void registerCommandHandler(const std::string &verb, const ControlCommandHandler &handler)
static std::string extractSigner(const Interest &interest)
Extracts the name from the KeyLocator of a ControlCommand request.
ManagerBase(std::string_view module, Dispatcher &dispatcher)
#define NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED
#define NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE