blob: f056f786a4233aae94d564748950bd7b4e72314e [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"
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +02007
Karol Niczyj32859b62021-05-19 10:20:46 +02008#include <systemd/sd-bus-protocol.h>
9
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020010#include <sdbusplus/asio/object_server.hpp>
11
12#include <chrono>
13#include <memory>
Wludzik, Jozefbc766b42020-12-08 16:06:22 +010014#include <string>
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020015#include <vector>
16
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020017class ReportManager : public interfaces::ReportManager
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020018{
19 public:
20 ReportManager(
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020021 std::unique_ptr<interfaces::ReportFactory> reportFactory,
Wludzik, Jozefe2362792020-10-27 17:23:55 +010022 std::unique_ptr<interfaces::JsonStorage> reportStorage,
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020023 const std::shared_ptr<sdbusplus::asio::object_server>& objServer);
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020024 ~ReportManager() = default;
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020025
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020026 ReportManager(ReportManager&) = delete;
27 ReportManager(ReportManager&&) = delete;
28 ReportManager& operator=(ReportManager&) = delete;
29 ReportManager& operator=(ReportManager&&) = delete;
30
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020031 void removeReport(const interfaces::Report* report) override;
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010032 void updateReport(const std::string& name) override;
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020033
34 private:
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020035 std::unique_ptr<interfaces::ReportFactory> reportFactory;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010036 std::unique_ptr<interfaces::JsonStorage> reportStorage;
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020037 std::shared_ptr<sdbusplus::asio::object_server> objServer;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020038 std::unique_ptr<sdbusplus::asio::dbus_interface> reportManagerIface;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020039 std::vector<std::unique_ptr<interfaces::Report>> reports;
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020040
Karol Niczyj32859b62021-05-19 10:20:46 +020041 void verifyReportNameLength(const std::string& reportName);
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000042 void verifyAddReport(
43 const std::string& reportName, const std::string& reportingType,
44 Milliseconds interval,
45 const std::vector<LabeledMetricParameters>& readingParams);
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020046 interfaces::Report& addReport(
47 boost::asio::yield_context& yield, const std::string& reportName,
48 const std::string& reportingType, const bool emitsReadingsUpdate,
49 const bool logToMetricReportsCollection, Milliseconds interval,
50 ReadingParameters metricParams, const bool enabled);
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000051 interfaces::Report& addReport(
Wludzik, Jozefe2362792020-10-27 17:23:55 +010052 const std::string& reportName, const std::string& reportingType,
53 const bool emitsReadingsUpdate, const bool logToMetricReportsCollection,
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000054 Milliseconds interval,
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020055 std::vector<LabeledMetricParameters> metricParams, const bool enabled);
Wludzik, Jozefe2362792020-10-27 17:23:55 +010056 void loadFromPersistent();
57
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020058 public:
Wludzik, Jozef503c1582020-12-11 14:48:01 +010059 static constexpr size_t maxReports{TELEMETRY_MAX_REPORTS};
60 static constexpr size_t maxReadingParams{TELEMETRY_MAX_READING_PARAMS};
Karol Niczyj32859b62021-05-19 10:20:46 +020061 static constexpr size_t maxReportNameLength{
62 TELEMETRY_MAX_REPORT_NAME_LENGTH};
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000063 static constexpr Milliseconds minInterval{TELEMETRY_MIN_INTERVAL};
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020064 static constexpr const char* reportManagerIfaceName =
65 "xyz.openbmc_project.Telemetry.ReportManager";
66 static constexpr const char* reportManagerPath =
67 "/xyz/openbmc_project/Telemetry/Reports";
Wludzik, Jozefbc766b42020-12-08 16:06:22 +010068 static constexpr std::array<std::string_view, 2> supportedReportingType = {
69 "Periodic", "OnRequest"};
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020070};