Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | b347b7f | 2017-07-23 14:01:58 +0000 | [diff] [blame] | 2 | /* |
Junxiao Shi | 16a3adf | 2017-05-26 17:38:51 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 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 | |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 26 | #ifndef NFD_TOOLS_NFDC_STATUS_REPORT_HPP |
| 27 | #define NFD_TOOLS_NFDC_STATUS_REPORT_HPP |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 28 | |
| 29 | #include "module.hpp" |
Junxiao Shi | b347b7f | 2017-07-23 14:01:58 +0000 | [diff] [blame] | 30 | #include <ndn-cxx/face.hpp> |
| 31 | #include <ndn-cxx/security/key-chain.hpp> |
| 32 | #include <ndn-cxx/security/v2/validator.hpp> |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 33 | |
| 34 | namespace nfd { |
| 35 | namespace tools { |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 36 | namespace nfdc { |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 37 | |
| 38 | using ndn::Face; |
Junxiao Shi | 16a3adf | 2017-05-26 17:38:51 +0000 | [diff] [blame] | 39 | using ndn::KeyChain; |
Junxiao Shi | b347b7f | 2017-07-23 14:01:58 +0000 | [diff] [blame] | 40 | using ndn::security::v2::Validator; |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 41 | |
Junxiao Shi | 8c39bf0 | 2016-08-28 23:54:13 +0000 | [diff] [blame] | 42 | enum class ReportFormat { |
| 43 | XML = 1, |
| 44 | TEXT = 2 |
| 45 | }; |
| 46 | |
| 47 | ReportFormat |
| 48 | parseReportFormat(const std::string& s); |
| 49 | |
| 50 | std::ostream& |
| 51 | operator<<(std::ostream& os, ReportFormat fmt); |
| 52 | |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 53 | /** \brief collects and prints NFD status report |
| 54 | */ |
| 55 | class StatusReport : noncopyable |
| 56 | { |
| 57 | public: |
| 58 | #ifdef WITH_TESTS |
| 59 | virtual |
| 60 | ~StatusReport() = default; |
| 61 | #endif |
| 62 | |
| 63 | /** \brief collect status via chosen \p sections |
| 64 | * |
| 65 | * This function is blocking. It has exclusive use of \p face. |
| 66 | * |
| 67 | * \return if status has been fetched successfully, 0; |
| 68 | * otherwise, error code from any failed section, plus 1000000 * section index |
| 69 | */ |
| 70 | uint32_t |
| 71 | collect(Face& face, KeyChain& keyChain, Validator& validator, const CommandOptions& options); |
| 72 | |
| 73 | /** \brief print an XML report |
| 74 | * \param os output stream |
| 75 | */ |
| 76 | void |
| 77 | formatXml(std::ostream& os) const; |
| 78 | |
| 79 | /** \brief print a text report |
| 80 | * \param os output stream |
| 81 | */ |
| 82 | void |
| 83 | formatText(std::ostream& os) const; |
| 84 | |
| 85 | private: |
| 86 | VIRTUAL_WITH_TESTS void |
| 87 | processEvents(Face& face); |
| 88 | |
| 89 | public: |
| 90 | /** \brief modules through which status is collected |
| 91 | */ |
| 92 | std::vector<unique_ptr<Module>> sections; |
| 93 | }; |
| 94 | |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 95 | } // namespace nfdc |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 96 | } // namespace tools |
| 97 | } // namespace nfd |
| 98 | |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 99 | #endif // NFD_TOOLS_NFDC_STATUS_REPORT_HPP |