1 #pragma once 2 3 #include "interfaces/clock.hpp" 4 #include "interfaces/json_storage.hpp" 5 #include "interfaces/metric.hpp" 6 #include "interfaces/report.hpp" 7 #include "interfaces/report_manager.hpp" 8 #include "types/report_action.hpp" 9 #include "types/report_types.hpp" 10 #include "types/report_updates.hpp" 11 #include "types/reporting_type.hpp" 12 #include "utils/circular_vector.hpp" 13 14 #include <boost/asio/io_context.hpp> 15 #include <boost/asio/steady_timer.hpp> 16 #include <sdbusplus/asio/object_server.hpp> 17 18 #include <chrono> 19 #include <memory> 20 21 class Report : public interfaces::Report 22 { 23 public: 24 Report(boost::asio::io_context& ioc, 25 const std::shared_ptr<sdbusplus::asio::object_server>& objServer, 26 const std::string& reportId, const std::string& reportName, 27 const ReportingType reportingType, 28 std::vector<ReportAction> reportActions, const Milliseconds period, 29 const uint64_t appendLimitIn, const ReportUpdates reportUpdatesIn, 30 interfaces::ReportManager& reportManager, 31 interfaces::JsonStorage& reportStorage, 32 std::vector<std::shared_ptr<interfaces::Metric>> metrics, 33 const bool enabled, std::unique_ptr<interfaces::Clock> clock); 34 ~Report() = default; 35 36 Report(const Report&) = delete; 37 Report(Report&&) = delete; 38 Report& operator=(const Report&) = delete; 39 Report& operator=(Report&&) = delete; 40 41 std::string getId() const override 42 { 43 return id; 44 } 45 46 std::string getPath() const override 47 { 48 return reportDir + id; 49 } 50 51 void updateReadings() override; 52 bool storeConfiguration() const; 53 54 private: 55 std::unique_ptr<sdbusplus::asio::dbus_interface> makeReportInterface(); 56 static void timerProc(boost::system::error_code, Report& self); 57 void scheduleTimer(Milliseconds interval); 58 uint64_t deduceAppendLimit(const uint64_t appendLimitIn) const; 59 uint64_t deduceBufferSize(const ReportUpdates reportUpdatesIn, 60 const ReportingType reportingTypeIn) const; 61 void setReportUpdates(const ReportUpdates newReportUpdates); 62 static uint64_t getSensorCount( 63 std::vector<std::shared_ptr<interfaces::Metric>>& metrics); 64 interfaces::JsonStorage::FilePath fileName() const; 65 66 std::string id; 67 std::string name; 68 ReportingType reportingType; 69 Milliseconds interval; 70 std::vector<ReportAction> reportActions; 71 ReadingParametersPastVersion readingParametersPastVersion; 72 ReadingParameters readingParameters; 73 bool persistency = false; 74 uint64_t sensorCount; 75 uint64_t appendLimit; 76 ReportUpdates reportUpdates; 77 CircularVector<ReadingData> readingsBuffer; 78 Readings readings = {}; 79 std::shared_ptr<sdbusplus::asio::object_server> objServer; 80 std::unique_ptr<sdbusplus::asio::dbus_interface> reportIface; 81 std::unique_ptr<sdbusplus::asio::dbus_interface> deleteIface; 82 std::vector<std::shared_ptr<interfaces::Metric>> metrics; 83 boost::asio::steady_timer timer; 84 85 interfaces::JsonStorage& reportStorage; 86 bool enabled; 87 std::unique_ptr<interfaces::Clock> clock; 88 89 public: 90 static constexpr const char* reportIfaceName = 91 "xyz.openbmc_project.Telemetry.Report"; 92 static constexpr const char* reportDir = 93 "/xyz/openbmc_project/Telemetry/Reports/"; 94 static constexpr const char* deleteIfaceName = 95 "xyz.openbmc_project.Object.Delete"; 96 static constexpr size_t reportVersion = 6; 97 }; 98