blob: 1d0cb9189401963692424171c99a1492dd06fff4 [file] [log] [blame]
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shib347b7f2017-07-23 14:01:58 +00002/*
Davide Pesavento40641272023-03-16 13:31:12 -04003 * Copyright (c) 2014-2023, 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
Junxiao Shi331ade72016-08-19 14:07:19 +000026#ifndef NFD_TOOLS_NFDC_STATUS_REPORT_HPP
27#define NFD_TOOLS_NFDC_STATUS_REPORT_HPP
Junxiao Shi38f4ce92016-08-04 10:01:52 +000028
Davide Pesavento40641272023-03-16 13:31:12 -040029#include "core/common.hpp"
Junxiao Shi38f4ce92016-08-04 10:01:52 +000030#include "module.hpp"
Davide Pesavento264af772021-02-09 21:48:24 -050031
Junxiao Shib347b7f2017-07-23 14:01:58 +000032#include <ndn-cxx/face.hpp>
33#include <ndn-cxx/security/key-chain.hpp>
Alexander Afanasyeva1583702020-06-03 13:55:45 -040034#include <ndn-cxx/security/validator.hpp>
Junxiao Shi38f4ce92016-08-04 10:01:52 +000035
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040036namespace nfd::tools::nfdc {
Junxiao Shi38f4ce92016-08-04 10:01:52 +000037
38using ndn::Face;
Junxiao Shi16a3adf2017-05-26 17:38:51 +000039using ndn::KeyChain;
Alexander Afanasyeva1583702020-06-03 13:55:45 -040040using ndn::security::Validator;
Junxiao Shi38f4ce92016-08-04 10:01:52 +000041
Junxiao Shi8c39bf02016-08-28 23:54:13 +000042enum class ReportFormat {
43 XML = 1,
Davide Pesavento990620a2022-06-05 00:25:53 -040044 TEXT = 2,
Junxiao Shi8c39bf02016-08-28 23:54:13 +000045};
46
Junxiao Shi8c39bf02016-08-28 23:54:13 +000047std::ostream&
48operator<<(std::ostream& os, ReportFormat fmt);
49
Davide Pesavento40641272023-03-16 13:31:12 -040050/**
51 * \brief Collects and prints NFD status report.
Junxiao Shi38f4ce92016-08-04 10:01:52 +000052 */
Davide Pesavento40641272023-03-16 13:31:12 -040053class StatusReport : boost::noncopyable
Junxiao Shi38f4ce92016-08-04 10:01:52 +000054{
55public:
Davide Pesavento264af772021-02-09 21:48:24 -050056#ifdef NFD_WITH_TESTS
Junxiao Shi38f4ce92016-08-04 10:01:52 +000057 virtual
58 ~StatusReport() = default;
59#endif
60
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040061 /** \brief Collect status via chosen \p sections.
Junxiao Shi38f4ce92016-08-04 10:01:52 +000062 *
63 * This function is blocking. It has exclusive use of \p face.
64 *
65 * \return if status has been fetched successfully, 0;
66 * otherwise, error code from any failed section, plus 1000000 * section index
67 */
68 uint32_t
69 collect(Face& face, KeyChain& keyChain, Validator& validator, const CommandOptions& options);
70
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040071 /** \brief Print an XML report.
Junxiao Shi38f4ce92016-08-04 10:01:52 +000072 * \param os output stream
73 */
74 void
75 formatXml(std::ostream& os) const;
76
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040077 /** \brief Print a text report.
Junxiao Shi38f4ce92016-08-04 10:01:52 +000078 * \param os output stream
79 */
80 void
81 formatText(std::ostream& os) const;
82
83private:
Davide Pesavento264af772021-02-09 21:48:24 -050084 NFD_VIRTUAL_WITH_TESTS void
Junxiao Shi38f4ce92016-08-04 10:01:52 +000085 processEvents(Face& face);
86
87public:
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040088 /** \brief Modules through which status is collected.
Junxiao Shi38f4ce92016-08-04 10:01:52 +000089 */
90 std::vector<unique_ptr<Module>> sections;
91};
92
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040093} // namespace nfd::tools::nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +000094
Junxiao Shi331ade72016-08-19 14:07:19 +000095#endif // NFD_TOOLS_NFDC_STATUS_REPORT_HPP