blob: cc613e8ae0cbd53301b4efcd9e9bb77e422dd564 [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(
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010044 const std::string& reportName, const ReportingType reportingType,
45 Milliseconds interval, const ReportUpdates reportUpdates,
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000046 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,
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010049 const ReportingType reportingType,
50 const std::vector<ReportAction>& reportActions, Milliseconds interval,
51 const uint64_t appendLimit, const ReportUpdates reportUpdates,
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020052 ReadingParameters metricParams, const bool enabled);
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000053 interfaces::Report& addReport(
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010054 const std::string& reportName, const ReportingType reportingType,
55 const std::vector<ReportAction>& reportActions, Milliseconds interval,
56 const uint64_t appendLimit, const ReportUpdates reportUpdates,
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020057 std::vector<LabeledMetricParameters> metricParams, const bool enabled);
Wludzik, Jozefe2362792020-10-27 17:23:55 +010058 void loadFromPersistent();
59
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020060 public:
Wludzik, Jozef503c1582020-12-11 14:48:01 +010061 static constexpr size_t maxReports{TELEMETRY_MAX_REPORTS};
62 static constexpr size_t maxReadingParams{TELEMETRY_MAX_READING_PARAMS};
Karol Niczyj32859b62021-05-19 10:20:46 +020063 static constexpr size_t maxReportNameLength{
Szymon Dompkee28aa532021-10-27 12:33:12 +020064 TELEMETRY_MAX_DBUS_PATH_LENGTH -
65 std::string_view(Report::reportDir).length()};
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000066 static constexpr Milliseconds minInterval{TELEMETRY_MIN_INTERVAL};
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020067 static constexpr const char* reportManagerIfaceName =
68 "xyz.openbmc_project.Telemetry.ReportManager";
69 static constexpr const char* reportManagerPath =
70 "/xyz/openbmc_project/Telemetry/Reports";
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010071 static constexpr std::array<ReportUpdates, 3> supportedReportUpdates = {
72 ReportUpdates::overwrite, ReportUpdates::appendStopsWhenFull,
73 ReportUpdates::appendWrapsWhenFull};
Szymon Dompke3eb56862021-09-20 15:32:04 +020074
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010075 static void verifyReportUpdates(const ReportUpdates reportUpdates);
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020076};