29 #include <ndn-cxx/mgmt/nfd/status-dataset.hpp>
40 parser.
addAlias(
"strategy",
"list",
"");
44 .
setTitle(
"show strategy choice of an entry")
50 .
setTitle(
"set strategy choice for a name prefix")
57 .
setTitle(
"clear strategy choice at a name prefix")
65 ctx.
controller.fetch<ndn::nfd::StrategyChoiceDataset>(
66 [&] (
const std::vector<StrategyChoice>& dataset) {
67 for (
const StrategyChoice& entry : dataset) {
75 ctx.
face.processEvents();
81 auto prefix = ctx.
args.
get<Name>(
"prefix");
83 ctx.
controller.fetch<ndn::nfd::StrategyChoiceDataset>(
84 [&] (
const std::vector<StrategyChoice>& dataset) {
86 for (
const StrategyChoice& entry : dataset) {
87 if (entry.getName().isPrefixOf(prefix) &&
88 entry.getName().size() >= match.getName().size()) {
97 ctx.
face.processEvents();
103 auto prefix = ctx.
args.
get<Name>(
"prefix");
104 auto strategy = ctx.
args.
get<Name>(
"strategy");
106 ctx.
controller.start<ndn::nfd::StrategyChoiceSetCommand>(
107 ControlParameters().setName(prefix).setStrategy(strategy),
108 [&] (
const ControlParameters& resp) {
109 ctx.
out <<
"strategy-set ";
111 ctx.
out << ia(
"prefix") << resp.getName()
112 << ia(
"strategy") << resp.getStrategy() <<
'\n';
114 [&] (
const ControlResponse& resp) {
115 if (resp.getCode() == 404) {
117 ctx.
err <<
"Unknown strategy: " << strategy <<
'\n';
125 ctx.
face.processEvents();
131 auto prefix = ctx.
args.
get<Name>(
"prefix");
133 if (prefix.empty()) {
135 ctx.
err <<
"Unsetting default strategy is prohibited\n";
139 ctx.
controller.start<ndn::nfd::StrategyChoiceUnsetCommand>(
140 ControlParameters().setName(prefix),
141 [&] (
const ControlParameters& resp) {
142 ctx.
out <<
"strategy-unset ";
144 ctx.
out << ia(
"prefix") << resp.getName() <<
'\n';
149 ctx.
face.processEvents();
154 const std::function<
void()>& onSuccess,
155 const ndn::nfd::DatasetFailureCallback& onFailure,
156 const CommandOptions& options)
158 controller.fetch<ndn::nfd::StrategyChoiceDataset>(
159 [
this, onSuccess] (
const std::vector<StrategyChoice>& result) {
169 os <<
"<strategyChoices>";
170 for (
const StrategyChoice& item : m_status) {
173 os <<
"</strategyChoices>";
179 os <<
"<strategyChoice>";
180 os <<
"<namespace>" <<
xml::Text{item.getName().toUri()} <<
"</namespace>";
181 os <<
"<strategy><name>" <<
xml::Text{item.getStrategy().toUri()} <<
"</name></strategy>";
182 os <<
"</strategyChoice>";
188 os <<
"Strategy choices:\n";
189 for (
const StrategyChoice& item : m_status) {
200 os << ia(
"prefix") << item.getName()
201 << ia(
"strategy") << item.getStrategy()
Context for command execution.
std::ostream & out
output stream
ndn::nfd::DatasetFailureCallback makeDatasetFailureHandler(const std::string &datasetName)
ndn::nfd::Controller & controller
const CommandArguments & args
ndn::nfd::CommandFailureCallback makeCommandFailureHandler(const std::string &commandName)
int exitCode
program exit code
ndn::nfd::CommandOptions makeCommandOptions() const
std::ostream & err
error stream
Print attributes of an item.