blob: 5a850f0ad7ff1d4af5e3830306f7731c5f22789a [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
Krzysztof Grobelny31db7f72021-12-21 12:26:22 +010027 ReportManager(const ReportManager&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020028 ReportManager(ReportManager&&) = delete;
Krzysztof Grobelny31db7f72021-12-21 12:26:22 +010029 ReportManager& operator=(const ReportManager&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020030 ReportManager& operator=(ReportManager&&) = delete;
31
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020032 void removeReport(const interfaces::Report* report) override;
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010033 void updateReport(const std::string& id) 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
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010042 void verifyReportIdLength(const std::string& reportName);
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000043 void verifyAddReport(
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010044 const std::string& reportId, const std::string& reportName,
45 const ReportingType reportingType, Milliseconds interval,
46 const ReportUpdates reportUpdates,
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000047 const std::vector<LabeledMetricParameters>& readingParams);
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020048 interfaces::Report& addReport(
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010049 boost::asio::yield_context& yield, const std::string& reportId,
50 const std::string& reportName, const ReportingType reportingType,
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010051 const std::vector<ReportAction>& reportActions, Milliseconds interval,
52 const uint64_t appendLimit, const ReportUpdates reportUpdates,
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020053 ReadingParameters metricParams, const bool enabled);
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000054 interfaces::Report& addReport(
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010055 const std::string& reportId, const std::string& reportName,
56 const ReportingType reportingType,
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010057 const std::vector<ReportAction>& reportActions, Milliseconds interval,
58 const uint64_t appendLimit, const ReportUpdates reportUpdates,
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020059 std::vector<LabeledMetricParameters> metricParams, const bool enabled);
Wludzik, Jozefe2362792020-10-27 17:23:55 +010060 void loadFromPersistent();
61
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020062 public:
Wludzik, Jozef503c1582020-12-11 14:48:01 +010063 static constexpr size_t maxReports{TELEMETRY_MAX_REPORTS};
64 static constexpr size_t maxReadingParams{TELEMETRY_MAX_READING_PARAMS};
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010065 static constexpr size_t maxReportIdLength{
Szymon Dompkee28aa532021-10-27 12:33:12 +020066 TELEMETRY_MAX_DBUS_PATH_LENGTH -
67 std::string_view(Report::reportDir).length()};
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000068 static constexpr Milliseconds minInterval{TELEMETRY_MIN_INTERVAL};
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020069 static constexpr const char* reportManagerIfaceName =
70 "xyz.openbmc_project.Telemetry.ReportManager";
71 static constexpr const char* reportManagerPath =
72 "/xyz/openbmc_project/Telemetry/Reports";
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010073 static constexpr std::array<ReportUpdates, 3> supportedReportUpdates = {
74 ReportUpdates::overwrite, ReportUpdates::appendStopsWhenFull,
75 ReportUpdates::appendWrapsWhenFull};
Szymon Dompke3eb56862021-09-20 15:32:04 +020076
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010077 static void verifyReportUpdates(const ReportUpdates reportUpdates);
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020078};