blob: 9c21c5dfc37ab1934a40f612d45358e617b9fdd1 [file] [log] [blame]
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +02001#pragma once
2
Wludzik, Jozefe2362792020-10-27 17:23:55 +01003#include "interfaces/json_storage.hpp"
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +02004#include "interfaces/report.hpp"
5#include "interfaces/report_factory.hpp"
6#include "interfaces/report_manager.hpp"
Szymon Dompkee28aa532021-10-27 12:33:12 +02007#include "report.hpp"
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +02008
Karol Niczyj32859b62021-05-19 10:20:46 +02009#include <systemd/sd-bus-protocol.h>
10
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020011#include <sdbusplus/asio/object_server.hpp>
12
13#include <chrono>
14#include <memory>
Wludzik, Jozefbc766b42020-12-08 16:06:22 +010015#include <string>
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020016#include <vector>
17
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020018class ReportManager : public interfaces::ReportManager
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020019{
20 public:
21 ReportManager(
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020022 std::unique_ptr<interfaces::ReportFactory> reportFactory,
Wludzik, Jozefe2362792020-10-27 17:23:55 +010023 std::unique_ptr<interfaces::JsonStorage> reportStorage,
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020024 const std::shared_ptr<sdbusplus::asio::object_server>& objServer);
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020025 ~ReportManager() = default;
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020026
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020027 ReportManager(ReportManager&) = delete;
28 ReportManager(ReportManager&&) = delete;
29 ReportManager& operator=(ReportManager&) = delete;
30 ReportManager& operator=(ReportManager&&) = delete;
31
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020032 void removeReport(const interfaces::Report* report) override;
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010033 void updateReport(const std::string& name) override;
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020034
35 private:
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020036 std::unique_ptr<interfaces::ReportFactory> reportFactory;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010037 std::unique_ptr<interfaces::JsonStorage> reportStorage;
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020038 std::shared_ptr<sdbusplus::asio::object_server> objServer;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020039 std::unique_ptr<sdbusplus::asio::dbus_interface> reportManagerIface;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020040 std::vector<std::unique_ptr<interfaces::Report>> reports;
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020041
Karol Niczyj32859b62021-05-19 10:20:46 +020042 void verifyReportNameLength(const std::string& reportName);
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000043 void verifyAddReport(
44 const std::string& reportName, const std::string& reportingType,
45 Milliseconds interval,
46 const std::vector<LabeledMetricParameters>& readingParams);
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020047 interfaces::Report& addReport(
48 boost::asio::yield_context& yield, const std::string& reportName,
49 const std::string& reportingType, const bool emitsReadingsUpdate,
50 const bool logToMetricReportsCollection, Milliseconds interval,
51 ReadingParameters metricParams, const bool enabled);
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000052 interfaces::Report& addReport(
Wludzik, Jozefe2362792020-10-27 17:23:55 +010053 const std::string& reportName, const std::string& reportingType,
54 const bool emitsReadingsUpdate, const bool logToMetricReportsCollection,
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000055 Milliseconds interval,
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020056 std::vector<LabeledMetricParameters> metricParams, const bool enabled);
Wludzik, Jozefe2362792020-10-27 17:23:55 +010057 void loadFromPersistent();
58
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020059 public:
Wludzik, Jozef503c1582020-12-11 14:48:01 +010060 static constexpr size_t maxReports{TELEMETRY_MAX_REPORTS};
61 static constexpr size_t maxReadingParams{TELEMETRY_MAX_READING_PARAMS};
Karol Niczyj32859b62021-05-19 10:20:46 +020062 static constexpr size_t maxReportNameLength{
Szymon Dompkee28aa532021-10-27 12:33:12 +020063 TELEMETRY_MAX_DBUS_PATH_LENGTH -
64 std::string_view(Report::reportDir).length()};
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000065 static constexpr Milliseconds minInterval{TELEMETRY_MIN_INTERVAL};
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020066 static constexpr const char* reportManagerIfaceName =
67 "xyz.openbmc_project.Telemetry.ReportManager";
68 static constexpr const char* reportManagerPath =
69 "/xyz/openbmc_project/Telemetry/Reports";
Wludzik, Jozefbc766b42020-12-08 16:06:22 +010070 static constexpr std::array<std::string_view, 2> supportedReportingType = {
71 "Periodic", "OnRequest"};
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020072};