strategy-choice-module.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
27 #include "format-helpers.hpp"
28 
29 namespace nfd {
30 namespace tools {
31 namespace nfdc {
32 
33 void
34 StrategyChoiceModule::fetchStatus(Controller& controller,
35  const function<void()>& onSuccess,
36  const Controller::DatasetFailCallback& onFailure,
37  const CommandOptions& options)
38 {
39  controller.fetch<ndn::nfd::StrategyChoiceDataset>(
40  [this, onSuccess] (const std::vector<StrategyChoice>& result) {
41  m_status = result;
42  onSuccess();
43  },
44  onFailure, options);
45 }
46 
47 void
49 {
50  os << "<strategyChoices>";
51  for (const StrategyChoice& item : m_status) {
52  this->formatItemXml(os, item);
53  }
54  os << "</strategyChoices>";
55 }
56 
57 void
58 StrategyChoiceModule::formatItemXml(std::ostream& os, const StrategyChoice& item) const
59 {
60  os << "<strategyChoice>";
61  os << "<namespace>" << xml::Text{item.getName().toUri()} << "</namespace>";
62  os << "<strategy><name>" << xml::Text{item.getStrategy().toUri()} << "</name></strategy>";
63  os << "</strategyChoice>";
64 }
65 
66 void
68 {
69  os << "Strategy choices:\n";
70  for (const StrategyChoice& item : m_status) {
71  this->formatItemText(os, item);
72  }
73 }
74 
75 void
76 StrategyChoiceModule::formatItemText(std::ostream& os, const StrategyChoice& item) const
77 {
78  os << " " << item.getName()
79  << " strategy=" << item.getStrategy()
80  << "\n";
81 }
82 
83 } // namespace nfdc
84 } // namespace tools
85 } // namespace nfd
virtual void formatStatusXml(std::ostream &os) const override
format collected status as XML
void formatItemText(std::ostream &os, const StrategyChoice &item) const
format a single status item as text
virtual void fetchStatus(Controller &controller, const function< void()> &onSuccess, const Controller::DatasetFailCallback &onFailure, const CommandOptions &options) override
collect status from NFD
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
void formatItemXml(std::ostream &os, const StrategyChoice &item) const
format a single status item as XML
virtual void formatStatusText(std::ostream &os) const override
format collected status as text