blob: 85fbfa9e81c95b585cddeda591137c5accfa2e3d [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 Dompkeb4ef22e2022-02-07 15:15:12 +01007#include "interfaces/trigger_manager.hpp"
Szymon Dompkee28aa532021-10-27 12:33:12 +02008#include "report.hpp"
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +02009
Karol Niczyj32859b62021-05-19 10:20:46 +020010#include <systemd/sd-bus-protocol.h>
11
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020012#include <sdbusplus/asio/object_server.hpp>
13
14#include <chrono>
15#include <memory>
Wludzik, Jozefbc766b42020-12-08 16:06:22 +010016#include <string>
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020017#include <vector>
18
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020019class ReportManager : public interfaces::ReportManager
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020020{
21 public:
22 ReportManager(
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020023 std::unique_ptr<interfaces::ReportFactory> reportFactory,
Wludzik, Jozefe2362792020-10-27 17:23:55 +010024 std::unique_ptr<interfaces::JsonStorage> reportStorage,
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010025 const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
26 std::unique_ptr<interfaces::TriggerManager>& triggerManager);
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020027 ~ReportManager() = default;
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020028
Krzysztof Grobelny31db7f72021-12-21 12:26:22 +010029 ReportManager(const ReportManager&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020030 ReportManager(ReportManager&&) = delete;
Krzysztof Grobelny31db7f72021-12-21 12:26:22 +010031 ReportManager& operator=(const ReportManager&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020032 ReportManager& operator=(ReportManager&&) = delete;
33
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020034 void removeReport(const interfaces::Report* report) override;
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010035 void updateReport(const std::string& id) override;
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010036 void updateTriggerIds(const std::string& reportId,
37 const std::string& triggerId,
38 TriggerIdUpdate updateType) override;
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020039
40 private:
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020041 std::unique_ptr<interfaces::ReportFactory> reportFactory;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010042 std::unique_ptr<interfaces::JsonStorage> reportStorage;
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020043 std::shared_ptr<sdbusplus::asio::object_server> objServer;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020044 std::unique_ptr<sdbusplus::asio::dbus_interface> reportManagerIface;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020045 std::vector<std::unique_ptr<interfaces::Report>> reports;
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010046 std::unique_ptr<interfaces::TriggerManager>& triggerManager;
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020047
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000048 void verifyAddReport(
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010049 const std::string& reportId, const std::string& reportName,
50 const ReportingType reportingType, Milliseconds interval,
Ankita Vilas Gawadecd5b0b72022-01-20 20:55:04 +000051 const ReportUpdates reportUpdates, const uint64_t appendLimit,
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000052 const std::vector<LabeledMetricParameters>& readingParams);
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020053 interfaces::Report& addReport(
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010054 boost::asio::yield_context& yield, const std::string& reportId,
55 const std::string& reportName, 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 ReadingParameters metricParams, const bool enabled);
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000059 interfaces::Report& addReport(
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010060 const std::string& reportId, const std::string& reportName,
61 const ReportingType reportingType,
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010062 const std::vector<ReportAction>& reportActions, Milliseconds interval,
63 const uint64_t appendLimit, const ReportUpdates reportUpdates,
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020064 std::vector<LabeledMetricParameters> metricParams, const bool enabled);
Wludzik, Jozefe2362792020-10-27 17:23:55 +010065 void loadFromPersistent();
66
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020067 public:
Wludzik, Jozef503c1582020-12-11 14:48:01 +010068 static constexpr size_t maxReports{TELEMETRY_MAX_REPORTS};
Ankita Vilas Gawadecd5b0b72022-01-20 20:55:04 +000069 static constexpr size_t maxNumberMetrics{TELEMETRY_MAX_READING_PARAMS};
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010070 static constexpr size_t maxReportIdLength{
Szymon Dompkee28aa532021-10-27 12:33:12 +020071 TELEMETRY_MAX_DBUS_PATH_LENGTH -
72 std::string_view(Report::reportDir).length()};
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000073 static constexpr Milliseconds minInterval{TELEMETRY_MIN_INTERVAL};
Ankita Vilas Gawadecd5b0b72022-01-20 20:55:04 +000074 static constexpr size_t maxAppendLimit{TELEMETRY_MAX_APPEND_LIMIT};
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020075 static constexpr const char* reportManagerIfaceName =
76 "xyz.openbmc_project.Telemetry.ReportManager";
77 static constexpr const char* reportManagerPath =
78 "/xyz/openbmc_project/Telemetry/Reports";
Krzysztof Grobelnya950e422021-12-31 13:49:00 +010079 static constexpr const char* reportNameDefault = "Report";
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020080};