Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 1 | /* -*- 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 | |
| 29 | namespace nfd { |
| 30 | namespace tools { |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 31 | namespace nfdc { |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 32 | |
Junxiao Shi | 8c39bf0 | 2016-08-28 23:54:13 +0000 | [diff] [blame^] | 33 | ReportFormat |
| 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 | |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 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 | |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 102 | } // namespace nfdc |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 103 | } // namespace tools |
| 104 | } // namespace nfd |