Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 3 | #include "interfaces/json_storage.hpp" |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 4 | #include "interfaces/report.hpp" |
| 5 | #include "interfaces/report_factory.hpp" |
| 6 | #include "interfaces/report_manager.hpp" |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 7 | |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 8 | #include <systemd/sd-bus-protocol.h> |
| 9 | |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 10 | #include <sdbusplus/asio/object_server.hpp> |
| 11 | |
| 12 | #include <chrono> |
| 13 | #include <memory> |
Wludzik, Jozef | bc766b4 | 2020-12-08 16:06:22 +0100 | [diff] [blame] | 14 | #include <string> |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 17 | class ReportManager : public interfaces::ReportManager |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 18 | { |
| 19 | public: |
| 20 | ReportManager( |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 21 | std::unique_ptr<interfaces::ReportFactory> reportFactory, |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 22 | std::unique_ptr<interfaces::JsonStorage> reportStorage, |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 23 | const std::shared_ptr<sdbusplus::asio::object_server>& objServer); |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 24 | ~ReportManager() = default; |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 25 | |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 26 | ReportManager(ReportManager&) = delete; |
| 27 | ReportManager(ReportManager&&) = delete; |
| 28 | ReportManager& operator=(ReportManager&) = delete; |
| 29 | ReportManager& operator=(ReportManager&&) = delete; |
| 30 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 31 | void removeReport(const interfaces::Report* report) override; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 32 | void updateReport(const std::string& name) override; |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 33 | |
| 34 | private: |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 35 | std::unique_ptr<interfaces::ReportFactory> reportFactory; |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 36 | std::unique_ptr<interfaces::JsonStorage> reportStorage; |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 37 | std::shared_ptr<sdbusplus::asio::object_server> objServer; |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 38 | std::unique_ptr<sdbusplus::asio::dbus_interface> reportManagerIface; |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 39 | std::vector<std::unique_ptr<interfaces::Report>> reports; |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 40 | |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 41 | void verifyReportNameLength(const std::string& reportName); |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 42 | void verifyAddReport( |
| 43 | const std::string& reportName, const std::string& reportingType, |
| 44 | Milliseconds interval, |
| 45 | const std::vector<LabeledMetricParameters>& readingParams); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 46 | 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 Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 51 | Milliseconds interval, |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 52 | ReadingParameters metricParams); |
| 53 | interfaces::Report& addReport( |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 54 | const std::string& reportName, const std::string& reportingType, |
| 55 | const bool emitsReadingsUpdate, const bool logToMetricReportsCollection, |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 56 | Milliseconds interval, |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 57 | std::vector<LabeledMetricParameters> metricParams); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 58 | void loadFromPersistent(); |
| 59 | |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 60 | public: |
Wludzik, Jozef | 503c158 | 2020-12-11 14:48:01 +0100 | [diff] [blame] | 61 | static constexpr size_t maxReports{TELEMETRY_MAX_REPORTS}; |
| 62 | static constexpr size_t maxReadingParams{TELEMETRY_MAX_READING_PARAMS}; |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 63 | static constexpr size_t maxReportNameLength{ |
| 64 | TELEMETRY_MAX_REPORT_NAME_LENGTH}; |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 65 | static constexpr Milliseconds minInterval{TELEMETRY_MIN_INTERVAL}; |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 66 | static constexpr const char* reportManagerIfaceName = |
| 67 | "xyz.openbmc_project.Telemetry.ReportManager"; |
| 68 | static constexpr const char* reportManagerPath = |
| 69 | "/xyz/openbmc_project/Telemetry/Reports"; |
Wludzik, Jozef | bc766b4 | 2020-12-08 16:06:22 +0100 | [diff] [blame] | 70 | static constexpr std::array<std::string_view, 2> supportedReportingType = { |
| 71 | "Periodic", "OnRequest"}; |
Krzysztof Grobelny | 64b75a5 | 2020-09-18 10:17:16 +0200 | [diff] [blame] | 72 | }; |