blob: e66a6142b057cfe2c17b5abd71a4b172a16c9b36 [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 Grobelnyd2238192020-12-02 09:27:28 +000042 void verifyAddReport(const std::string& reportName,
Wludzik, Jozefbc766b42020-12-08 16:06:22 +010043 const std::string& reportingType,
44 std::chrono::milliseconds interval,
45 const ReadingParameters& 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,
51 std::chrono::milliseconds interval,
52 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,
56 std::chrono::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};
Wludzik, Jozef503c1582020-12-11 14:48:01 +010065 static constexpr std::chrono::milliseconds minInterval{
66 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";
Wludzik, Jozefbc766b42020-12-08 16:06:22 +010071 static constexpr std::array<std::string_view, 2> supportedReportingType = {
72 "Periodic", "OnRequest"};
Krzysztof Grobelny64b75a52020-09-18 10:17:16 +020073};