blob: 93b2986aee5d48d9b32978178af7fce13465bb28 [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 Grobelnydcc4e192021-03-08 09:09:34 +000042 void verifyAddReport(
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010043 const std::string& reportId, const std::string& reportName,
44 const ReportingType reportingType, Milliseconds interval,
Ankita Vilas Gawadecd5b0b72022-01-20 20:55:04 +000045 const ReportUpdates reportUpdates, const uint64_t appendLimit,
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000046 const std::vector<LabeledMetricParameters>& readingParams);
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020047 interfaces::Report& addReport(
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010048 boost::asio::yield_context& yield, const std::string& reportId,
49 const std::string& reportName, const ReportingType reportingType,
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010050 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 Grobelnyb8cc78d2021-11-29 15:54:53 +010054 const std::string& reportId, const std::string& reportName,
55 const ReportingType reportingType,
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010056 const std::vector<ReportAction>& reportActions, Milliseconds interval,
57 const uint64_t appendLimit, const ReportUpdates reportUpdates,
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020058 std::vector<LabeledMetricParameters> metricParams, const bool enabled);
Wludzik, Jozefe2362792020-10-27 17:23:55 +010059 void loadFromPersistent();
60
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020061 public:
Wludzik, Jozef503c1582020-12-11 14:48:01 +010062 static constexpr size_t maxReports{TELEMETRY_MAX_REPORTS};
Ankita Vilas Gawadecd5b0b72022-01-20 20:55:04 +000063 static constexpr size_t maxNumberMetrics{TELEMETRY_MAX_READING_PARAMS};
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010064 static constexpr size_t maxReportIdLength{
Szymon Dompkee28aa532021-10-27 12:33:12 +020065 TELEMETRY_MAX_DBUS_PATH_LENGTH -
66 std::string_view(Report::reportDir).length()};
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000067 static constexpr Milliseconds minInterval{TELEMETRY_MIN_INTERVAL};
Ankita Vilas Gawadecd5b0b72022-01-20 20:55:04 +000068 static constexpr size_t maxAppendLimit{TELEMETRY_MAX_APPEND_LIMIT};
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 Grobelnya950e422021-12-31 13:49:00 +010073 static constexpr const char* reportNameDefault = "Report";
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020074};