28 #include <ndn-cxx/mgmt/nfd/strategy-choice.hpp> 29 #include <boost/lexical_cast.hpp> 36 Dispatcher& dispatcher,
39 , m_table(strategyChoice)
41 registerCommandHandler<ndn::nfd::StrategyChoiceSetCommand>(
"set",
42 bind(&StrategyChoiceManager::setStrategy,
this, _4, _5));
43 registerCommandHandler<ndn::nfd::StrategyChoiceUnsetCommand>(
"unset",
44 bind(&StrategyChoiceManager::unsetStrategy,
this, _4, _5));
47 bind(&StrategyChoiceManager::listChoices,
this, _3));
51 StrategyChoiceManager::setStrategy(ControlParameters parameters,
52 const ndn::mgmt::CommandContinuation& done)
54 const Name& prefix = parameters.getName();
55 const Name& strategy = parameters.getStrategy();
57 StrategyChoice::InsertResult res = m_table.
insert(prefix, strategy);
59 NFD_LOG_DEBUG(
"strategy-choice/set(" << prefix <<
"," << strategy <<
"): cannot-create " << res);
60 return done(ControlResponse(404, boost::lexical_cast<std::string>(res)));
63 NFD_LOG_DEBUG(
"strategy-choice/set(" << prefix <<
"," << strategy <<
"): OK");
64 bool hasEntry =
false;
66 std::tie(hasEntry, instanceName) = m_table.
get(prefix);
67 BOOST_ASSERT_MSG(hasEntry,
"StrategyChoice entry must exist after StrategyChoice::insert");
68 parameters.setStrategy(instanceName);
69 return done(ControlResponse(200,
"OK").setBody(parameters.wireEncode()));
73 StrategyChoiceManager::unsetStrategy(ControlParameters parameters,
74 const ndn::mgmt::CommandContinuation& done)
76 const Name& prefix = parameters.getName();
79 m_table.
erase(parameters.getName());
82 done(ControlResponse(200,
"OK").setBody(parameters.wireEncode()));
86 StrategyChoiceManager::listChoices(ndn::mgmt::StatusDatasetContext& context)
88 for (
const auto& i : m_table) {
89 ndn::nfd::StrategyChoice entry;
90 entry.setName(i.getPrefix())
91 .setStrategy(i.getStrategyInstanceName());
92 context.append(entry.wireEncode());
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
std::pair< bool, Name > get(const Name &prefix) const
get strategy Name of prefix
#define NFD_LOG_DEBUG(expression)
InsertResult insert(const Name &prefix, const Name &strategyName)
set strategy of prefix to be strategyName
provides ControlCommand authorization according to NFD configuration file
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
a collection of common functions shared by all NFD managers, such as communicating with the dispatche...
StrategyChoiceManager(strategy_choice::StrategyChoice &table, Dispatcher &dispatcher, CommandAuthenticator &authenticator)
#define NFD_LOG_INIT(name)
void erase(const Name &prefix)
make prefix to inherit strategy from its parent