status-report.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "status-report.hpp"
27 #include "format-helpers.hpp"
28 
29 namespace nfd {
30 namespace tools {
31 namespace nfdc {
32 
34 parseReportFormat(const std::string& s)
35 {
36  if (s == "xml") {
37  return ReportFormat::XML;
38  }
39  if (s == "text") {
40  return ReportFormat::TEXT;
41  }
42  BOOST_THROW_EXCEPTION(std::invalid_argument("unrecognized ReportFormat"));
43 }
44 
45 std::ostream&
46 operator<<(std::ostream& os, ReportFormat fmt)
47 {
48  switch (fmt) {
49  case ReportFormat::XML:
50  return os << "xml";
51  case ReportFormat::TEXT:
52  return os << "text";
53  }
54  return os << static_cast<int>(fmt);
55 }
56 
57 uint32_t
58 StatusReport::collect(Face& face, KeyChain& keyChain, Validator& validator, const CommandOptions& options)
59 {
60  Controller controller(face, keyChain, validator);
61  uint32_t errorCode = 0;
62 
63  for (size_t i = 0; i < sections.size(); ++i) {
64  Module& module = *sections[i];
65  module.fetchStatus(
66  controller,
67  [] {},
68  [i, &errorCode] (uint32_t code, const std::string& reason) {
69  errorCode = i * 1000000 + code;
70  },
71  options);
72  }
73 
74  this->processEvents(face);
75  return errorCode;
76 }
77 
78 void
79 StatusReport::processEvents(Face& face)
80 {
81  face.processEvents();
82 }
83 
84 void
85 StatusReport::formatXml(std::ostream& os) const
86 {
87  xml::printHeader(os);
88  for (const unique_ptr<Module>& module : sections) {
89  module->formatStatusXml(os);
90  }
91  xml::printFooter(os);
92 }
93 
94 void
95 StatusReport::formatText(std::ostream& os) const
96 {
97  for (const unique_ptr<Module>& module : sections) {
98  module->formatStatusText(os);
99  }
100 }
101 
102 } // namespace nfdc
103 } // namespace tools
104 } // namespace nfd
ReportFormat parseReportFormat(const std::string &s)
std::vector< unique_ptr< Module > > sections
modules through which status is collected
virtual void fetchStatus(Controller &controller, const function< void()> &onSuccess, const Controller::DatasetFailCallback &onFailure, const CommandOptions &options)=0
collect status from NFD
void formatXml(std::ostream &os) const
print an XML report
uint32_t collect(Face &face, KeyChain &keyChain, Validator &validator, const CommandOptions &options)
collect status via chosen sections
std::ostream & operator<<(std::ostream &os, ArgValueType vt)
void printHeader(std::ostream &os)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
void formatText(std::ostream &os) const
print a text report
provides access to an NFD management module
Definition: module.hpp:42
void printFooter(std::ostream &os)