blob: ff0ea1c31f706b4627a0e58ad54185b3f32207c3 [file] [log] [blame]
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry84d3adc2017-08-09 23:31:40 -04002/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Junxiao Shi38f4ce92016-08-04 10:01:52 +00004 * 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
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040029namespace nfd::tools::nfdc {
Junxiao Shi38f4ce92016-08-04 10:01:52 +000030
Junxiao Shi8c39bf02016-08-28 23:54:13 +000031ReportFormat
32parseReportFormat(const std::string& s)
33{
34 if (s == "xml") {
35 return ReportFormat::XML;
36 }
37 if (s == "text") {
38 return ReportFormat::TEXT;
39 }
Davide Pesavento19779d82019-02-14 13:40:04 -050040 NDN_THROW(std::invalid_argument("unrecognized ReportFormat '" + s + "'"));
Junxiao Shi8c39bf02016-08-28 23:54:13 +000041}
42
43std::ostream&
44operator<<(std::ostream& os, ReportFormat fmt)
45{
46 switch (fmt) {
47 case ReportFormat::XML:
48 return os << "xml";
49 case ReportFormat::TEXT:
50 return os << "text";
51 }
52 return os << static_cast<int>(fmt);
53}
54
Junxiao Shi38f4ce92016-08-04 10:01:52 +000055uint32_t
56StatusReport::collect(Face& face, KeyChain& keyChain, Validator& validator, const CommandOptions& options)
57{
58 Controller controller(face, keyChain, validator);
59 uint32_t errorCode = 0;
60
61 for (size_t i = 0; i < sections.size(); ++i) {
62 Module& module = *sections[i];
63 module.fetchStatus(
64 controller,
Eric Newberry84d3adc2017-08-09 23:31:40 -040065 []{},
Junxiao Shi38f4ce92016-08-04 10:01:52 +000066 [i, &errorCode] (uint32_t code, const std::string& reason) {
67 errorCode = i * 1000000 + code;
68 },
69 options);
70 }
71
72 this->processEvents(face);
73 return errorCode;
74}
75
76void
77StatusReport::processEvents(Face& face)
78{
79 face.processEvents();
80}
81
82void
83StatusReport::formatXml(std::ostream& os) const
84{
85 xml::printHeader(os);
Davide Pesavento19779d82019-02-14 13:40:04 -050086 for (const auto& module : sections) {
Junxiao Shi38f4ce92016-08-04 10:01:52 +000087 module->formatStatusXml(os);
88 }
89 xml::printFooter(os);
90}
91
92void
93StatusReport::formatText(std::ostream& os) const
94{
Davide Pesavento19779d82019-02-14 13:40:04 -050095 for (const auto& module : sections) {
Junxiao Shi38f4ce92016-08-04 10:01:52 +000096 module->formatStatusText(os);
97 }
98}
99
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400100} // namespace nfd::tools::nfdc