blob: 1e6e15d2628e39e76f81a08bc1d8fe606560a353 [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);
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000046 interfaces::Report& addReport(boost::asio::yield_context& yield,
47 const std::string& reportName,
48 const std::string& reportingType,
49 const bool emitsReadingsUpdate,
50 const bool logToMetricReportsCollection,
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000051 Milliseconds interval,
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000052 ReadingParameters metricParams);
53 interfaces::Report& addReport(
Wludzik, Jozefe2362792020-10-27 17:23:55 +010054 const std::string& reportName, const std::string& reportingType,
55 const bool emitsReadingsUpdate, const bool logToMetricReportsCollection,
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000056 Milliseconds interval,
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000057 std::vector<LabeledMetricParameters> metricParams);
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{
64 TELEMETRY_MAX_REPORT_NAME_LENGTH};
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000065 static constexpr Milliseconds minInterval{TELEMETRY_MIN_INTERVAL};
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020066 static constexpr const char* reportManagerIfaceName =
67 "xyz.openbmc_project.Telemetry.ReportManager";
68 static constexpr const char* reportManagerPath =
69 "/xyz/openbmc_project/Telemetry/Reports";
Wludzik, Jozefbc766b42020-12-08 16:06:22 +010070 static constexpr std::array<std::string_view, 2> supportedReportingType = {
71 "Periodic", "OnRequest"};
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020072};