1cb88cfdfSWludzik, Jozef #pragma once 2cb88cfdfSWludzik, Jozef 351f0fd50SKrzysztof Grobelny #include "interfaces/clock.hpp" 4e2362796SWludzik, Jozef #include "interfaces/json_storage.hpp" 5c8e3a64aSKrzysztof Grobelny #include "interfaces/metric.hpp" 6f7ea2997SKrzysztof Grobelny #include "interfaces/metric_listener.hpp" 72f9f9b87SWludzik, Jozef #include "interfaces/report.hpp" 8fdb06a14SSzymon Dompke #include "interfaces/report_factory.hpp" 92f9f9b87SWludzik, Jozef #include "interfaces/report_manager.hpp" 10973b4bb0SKrzysztof Grobelny #include "state.hpp" 11973b4bb0SKrzysztof Grobelny #include "types/error_message.hpp" 12493e62ebSKrzysztof Grobelny #include "types/readings.hpp" 1351497a0cSKrzysztof Grobelny #include "types/report_action.hpp" 14dcc4e193SKrzysztof Grobelny #include "types/report_types.hpp" 1551497a0cSKrzysztof Grobelny #include "types/report_updates.hpp" 1651497a0cSKrzysztof Grobelny #include "types/reporting_type.hpp" 173eb56865SSzymon Dompke #include "utils/circular_vector.hpp" 181cdd7e4fSSzymon Dompke #include "utils/dbus_path_utils.hpp" 19f7ea2997SKrzysztof Grobelny #include "utils/ensure.hpp" 20e6d48874SKrzysztof Grobelny #include "utils/messanger.hpp" 212f9f9b87SWludzik, Jozef 22cb88cfdfSWludzik, Jozef #include <boost/asio/io_context.hpp> 23c8e3a64aSKrzysztof Grobelny #include <boost/asio/steady_timer.hpp> 24cb88cfdfSWludzik, Jozef #include <sdbusplus/asio/object_server.hpp> 25cb88cfdfSWludzik, Jozef 26cb88cfdfSWludzik, Jozef #include <chrono> 27cb88cfdfSWludzik, Jozef #include <memory> 28b4ef22e4SSzymon Dompke #include <unordered_set> 29cb88cfdfSWludzik, Jozef 30f7ea2997SKrzysztof Grobelny class Report : public interfaces::Report, public interfaces::MetricListener 31cb88cfdfSWludzik, Jozef { 32f7ea2997SKrzysztof Grobelny class OnChangeContext 33f7ea2997SKrzysztof Grobelny { 34f7ea2997SKrzysztof Grobelny public: OnChangeContext(Report & report)353a1c297aSPatrick Williams OnChangeContext(Report& report) : report(report) {} 36f7ea2997SKrzysztof Grobelny ~OnChangeContext()37f7ea2997SKrzysztof Grobelny ~OnChangeContext() 38f7ea2997SKrzysztof Grobelny { 39f7ea2997SKrzysztof Grobelny if (updated) 40f7ea2997SKrzysztof Grobelny { 41f7ea2997SKrzysztof Grobelny report.updateReadings(); 42f7ea2997SKrzysztof Grobelny } 43f7ea2997SKrzysztof Grobelny } 44f7ea2997SKrzysztof Grobelny metricUpdated()45f7ea2997SKrzysztof Grobelny void metricUpdated() 46f7ea2997SKrzysztof Grobelny { 47f7ea2997SKrzysztof Grobelny updated = true; 48f7ea2997SKrzysztof Grobelny } 49f7ea2997SKrzysztof Grobelny 50f7ea2997SKrzysztof Grobelny private: 51f7ea2997SKrzysztof Grobelny Report& report; 52f7ea2997SKrzysztof Grobelny bool updated = false; 53f7ea2997SKrzysztof Grobelny }; 54f7ea2997SKrzysztof Grobelny 55cb88cfdfSWludzik, Jozef public: 56cb88cfdfSWludzik, Jozef Report(boost::asio::io_context& ioc, 57cb88cfdfSWludzik, Jozef const std::shared_ptr<sdbusplus::asio::object_server>& objServer, 58b8cc78ddSKrzysztof Grobelny const std::string& reportId, const std::string& reportName, 59b8cc78ddSKrzysztof Grobelny const ReportingType reportingType, 6051497a0cSKrzysztof Grobelny std::vector<ReportAction> reportActions, const Milliseconds period, 613eb56865SSzymon Dompke const uint64_t appendLimitIn, const ReportUpdates reportUpdatesIn, 62c8e3a64aSKrzysztof Grobelny interfaces::ReportManager& reportManager, 63e2362796SWludzik, Jozef interfaces::JsonStorage& reportStorage, 647e098e93SLukasz Kazmierczak std::vector<std::shared_ptr<interfaces::Metric>> metrics, 65fdb06a14SSzymon Dompke const interfaces::ReportFactory& reportFactory, const bool enabled, 66493e62ebSKrzysztof Grobelny std::unique_ptr<interfaces::Clock> clock, Readings); 67493e62ebSKrzysztof Grobelny ~Report(); 68cb88cfdfSWludzik, Jozef 69c8e3a64aSKrzysztof Grobelny Report(const Report&) = delete; 70cb88cfdfSWludzik, Jozef Report(Report&&) = delete; 71c8e3a64aSKrzysztof Grobelny Report& operator=(const Report&) = delete; 72cb88cfdfSWludzik, Jozef Report& operator=(Report&&) = delete; 73cb88cfdfSWludzik, Jozef getId() const74b8cc78ddSKrzysztof Grobelny std::string getId() const override 752f9f9b87SWludzik, Jozef { 76b8cc78ddSKrzysztof Grobelny return id; 772f9f9b87SWludzik, Jozef } 782f9f9b87SWludzik, Jozef getPath() const792f9f9b87SWludzik, Jozef std::string getPath() const override 802f9f9b87SWludzik, Jozef { 811cdd7e4fSSzymon Dompke return path.str; 822f9f9b87SWludzik, Jozef } 83cb88cfdfSWludzik, Jozef 84f7ea2997SKrzysztof Grobelny void metricUpdated() override; 85f7ea2997SKrzysztof Grobelny 86973b4bb0SKrzysztof Grobelny void activate(); 87973b4bb0SKrzysztof Grobelny void deactivate(); 88973b4bb0SKrzysztof Grobelny 89cb88cfdfSWludzik, Jozef private: 90*583ba441SPatrick Williams std::unique_ptr<sdbusplus::asio::dbus_interface> makeReportInterface( 91*583ba441SPatrick Williams const interfaces::ReportFactory& reportFactory); 92f7ea2997SKrzysztof Grobelny static void timerProcForPeriodicReport(boost::system::error_code, 93f7ea2997SKrzysztof Grobelny Report& self); 94f7ea2997SKrzysztof Grobelny static void timerProcForOnChangeReport(boost::system::error_code, 95f7ea2997SKrzysztof Grobelny Report& self); 96f7ea2997SKrzysztof Grobelny void scheduleTimerForPeriodicReport(Milliseconds interval); 97f7ea2997SKrzysztof Grobelny void scheduleTimerForOnChangeReport(); 983eb56865SSzymon Dompke uint64_t deduceBufferSize(const ReportUpdates reportUpdatesIn, 993eb56865SSzymon Dompke const ReportingType reportingTypeIn) const; 100fdb06a14SSzymon Dompke void setReadingBuffer(const ReportUpdates newReportUpdates); 1013eb56865SSzymon Dompke void setReportUpdates(const ReportUpdates newReportUpdates); 10218e7101cSKrzysztof Grobelny static uint64_t getMetricCount( 103f7ea2997SKrzysztof Grobelny const std::vector<std::shared_ptr<interfaces::Metric>>& metrics); 104493e62ebSKrzysztof Grobelny interfaces::JsonStorage::FilePath reportFileName() const; 105*583ba441SPatrick Williams std::unordered_set<std::string> collectTriggerIds( 106*583ba441SPatrick Williams boost::asio::io_context& ioc) const; 107e6d48874SKrzysztof Grobelny bool storeConfiguration() const; 108493e62ebSKrzysztof Grobelny bool shouldStoreMetricValues() const; 109e6d48874SKrzysztof Grobelny void updateReadings(); 110973b4bb0SKrzysztof Grobelny void scheduleTimer(); 111cff70c14SKrzysztof Grobelny static std::vector<ErrorMessage> verify(ReportingType, Milliseconds); 112c8e3a64aSKrzysztof Grobelny 113b8cc78ddSKrzysztof Grobelny std::string id; 1141cdd7e4fSSzymon Dompke const sdbusplus::message::object_path path; 115e28aa53dSSzymon Dompke std::string name; 1163eb56865SSzymon Dompke ReportingType reportingType; 117dcc4e193SKrzysztof Grobelny Milliseconds interval; 118fdb06a14SSzymon Dompke std::unordered_set<ReportAction> reportActions; 119e2362796SWludzik, Jozef ReadingParameters readingParameters; 12085db8bdfSKrzysztof Grobelny bool persistency = false; 12118e7101cSKrzysztof Grobelny uint64_t metricCount; 12218e7101cSKrzysztof Grobelny uint64_t appendLimit; 1233eb56865SSzymon Dompke ReportUpdates reportUpdates; 124c8e3a64aSKrzysztof Grobelny Readings readings = {}; 125493e62ebSKrzysztof Grobelny CircularVector<ReadingData> readingsBuffer; 126cb88cfdfSWludzik, Jozef std::shared_ptr<sdbusplus::asio::object_server> objServer; 127cb88cfdfSWludzik, Jozef std::unique_ptr<sdbusplus::asio::dbus_interface> reportIface; 128cb88cfdfSWludzik, Jozef std::unique_ptr<sdbusplus::asio::dbus_interface> deleteIface; 129c8e3a64aSKrzysztof Grobelny std::vector<std::shared_ptr<interfaces::Metric>> metrics; 130c8e3a64aSKrzysztof Grobelny boost::asio::steady_timer timer; 131b4ef22e4SSzymon Dompke std::unordered_set<std::string> triggerIds; 1322f9f9b87SWludzik, Jozef 133e2362796SWludzik, Jozef interfaces::JsonStorage& reportStorage; 13451f0fd50SKrzysztof Grobelny std::unique_ptr<interfaces::Clock> clock; 135e6d48874SKrzysztof Grobelny utils::Messanger messanger; 136f7ea2997SKrzysztof Grobelny std::optional<OnChangeContext> onChangeContext; 137f7ea2997SKrzysztof Grobelny utils::Ensure<std::function<void()>> unregisterFromMetrics; 138973b4bb0SKrzysztof Grobelny State<ReportFlags, Report, ReportFlags::enabled, ReportFlags::valid> state{ 139973b4bb0SKrzysztof Grobelny *this}; 140e2362796SWludzik, Jozef 1412f9f9b87SWludzik, Jozef public: 1422f9f9b87SWludzik, Jozef static constexpr const char* reportIfaceName = 1432f9f9b87SWludzik, Jozef "xyz.openbmc_project.Telemetry.Report"; 1442f9f9b87SWludzik, Jozef static constexpr const char* deleteIfaceName = 1452f9f9b87SWludzik, Jozef "xyz.openbmc_project.Object.Delete"; 14618e7101cSKrzysztof Grobelny static constexpr size_t reportVersion = 7; 147cb88cfdfSWludzik, Jozef }; 148