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