blob: ff3e8a6d80ef236e92641b9d7d6c40810b2e62ec [file] [log] [blame]
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2016, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "status-report.hpp"
27#include "format-helpers.hpp"
28
29namespace nfd {
30namespace tools {
Junxiao Shi331ade72016-08-19 14:07:19 +000031namespace nfdc {
Junxiao Shi38f4ce92016-08-04 10:01:52 +000032
Junxiao Shi8c39bf02016-08-28 23:54:13 +000033ReportFormat
34parseReportFormat(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
45std::ostream&
46operator<<(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
Junxiao Shi38f4ce92016-08-04 10:01:52 +000057uint32_t
58StatusReport::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
78void
79StatusReport::processEvents(Face& face)
80{
81 face.processEvents();
82}
83
84void
85StatusReport::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
94void
95StatusReport::formatText(std::ostream& os) const
96{
97 for (const unique_ptr<Module>& module : sections) {
98 module->formatStatusText(os);
99 }
100}
101
Junxiao Shi331ade72016-08-19 14:07:19 +0000102} // namespace nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000103} // namespace tools
104} // namespace nfd