blob: 3b8b45127e64a6f4b9654c8db6c82986995c1f90 [file] [log] [blame]
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +02001#pragma once
2
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +01003#include "interfaces/clock.hpp"
Wludzik, Jozefe2362792020-10-27 17:23:55 +01004#include "interfaces/json_storage.hpp"
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +02005#include "interfaces/metric.hpp"
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +02006#include "interfaces/report.hpp"
Szymon Dompkefdb06a12022-02-11 11:04:44 +01007#include "interfaces/report_factory.hpp"
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +02008#include "interfaces/report_manager.hpp"
Krzysztof Grobelny51497a02021-11-09 14:56:22 +01009#include "types/report_action.hpp"
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000010#include "types/report_types.hpp"
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010011#include "types/report_updates.hpp"
12#include "types/reporting_type.hpp"
Szymon Dompke3eb56862021-09-20 15:32:04 +020013#include "utils/circular_vector.hpp"
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +010014#include "utils/messanger.hpp"
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020015
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020016#include <boost/asio/io_context.hpp>
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020017#include <boost/asio/steady_timer.hpp>
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020018#include <sdbusplus/asio/object_server.hpp>
19
20#include <chrono>
21#include <memory>
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010022#include <unordered_set>
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020023
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020024class Report : public interfaces::Report
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020025{
26 public:
27 Report(boost::asio::io_context& ioc,
28 const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010029 const std::string& reportId, const std::string& reportName,
30 const ReportingType reportingType,
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010031 std::vector<ReportAction> reportActions, const Milliseconds period,
Szymon Dompke3eb56862021-09-20 15:32:04 +020032 const uint64_t appendLimitIn, const ReportUpdates reportUpdatesIn,
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020033 interfaces::ReportManager& reportManager,
Wludzik, Jozefe2362792020-10-27 17:23:55 +010034 interfaces::JsonStorage& reportStorage,
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020035 std::vector<std::shared_ptr<interfaces::Metric>> metrics,
Szymon Dompkefdb06a12022-02-11 11:04:44 +010036 const interfaces::ReportFactory& reportFactory, const bool enabled,
37 std::unique_ptr<interfaces::Clock> clock);
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020038
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020039 Report(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020040 Report(Report&&) = delete;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020041 Report& operator=(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020042 Report& operator=(Report&&) = delete;
43
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010044 std::string getId() const override
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020045 {
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010046 return id;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020047 }
48
49 std::string getPath() const override
50 {
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010051 return reportDir + id;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020052 }
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020053
54 private:
Szymon Dompkefdb06a12022-02-11 11:04:44 +010055 std::unique_ptr<sdbusplus::asio::dbus_interface>
56 makeReportInterface(const interfaces::ReportFactory& reportFactory);
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020057 static void timerProc(boost::system::error_code, Report& self);
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000058 void scheduleTimer(Milliseconds interval);
Krzysztof Grobelnye6c417c2022-02-02 17:25:53 +010059 std::optional<uint64_t>
60 deduceAppendLimit(const uint64_t appendLimitIn) const;
Szymon Dompke3eb56862021-09-20 15:32:04 +020061 uint64_t deduceBufferSize(const ReportUpdates reportUpdatesIn,
62 const ReportingType reportingTypeIn) const;
Szymon Dompkefdb06a12022-02-11 11:04:44 +010063 void setReadingBuffer(const ReportUpdates newReportUpdates);
Szymon Dompke3eb56862021-09-20 15:32:04 +020064 void setReportUpdates(const ReportUpdates newReportUpdates);
65 static uint64_t getSensorCount(
66 std::vector<std::shared_ptr<interfaces::Metric>>& metrics);
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010067 interfaces::JsonStorage::FilePath fileName() const;
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +010068 std::unordered_set<std::string>
69 collectTriggerIds(boost::asio::io_context& ioc) const;
70 bool storeConfiguration() const;
71 void updateReadings();
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020072
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010073 std::string id;
Szymon Dompkee28aa532021-10-27 12:33:12 +020074 std::string name;
Szymon Dompke3eb56862021-09-20 15:32:04 +020075 ReportingType reportingType;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000076 Milliseconds interval;
Szymon Dompkefdb06a12022-02-11 11:04:44 +010077 std::unordered_set<ReportAction> reportActions;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000078 ReadingParametersPastVersion readingParametersPastVersion;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010079 ReadingParameters readingParameters;
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000080 bool persistency = false;
Szymon Dompke3eb56862021-09-20 15:32:04 +020081 uint64_t sensorCount;
Krzysztof Grobelnye6c417c2022-02-02 17:25:53 +010082 std::optional<uint64_t> appendLimit;
Szymon Dompke3eb56862021-09-20 15:32:04 +020083 ReportUpdates reportUpdates;
84 CircularVector<ReadingData> readingsBuffer;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020085 Readings readings = {};
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020086 std::shared_ptr<sdbusplus::asio::object_server> objServer;
87 std::unique_ptr<sdbusplus::asio::dbus_interface> reportIface;
88 std::unique_ptr<sdbusplus::asio::dbus_interface> deleteIface;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020089 std::vector<std::shared_ptr<interfaces::Metric>> metrics;
90 boost::asio::steady_timer timer;
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010091 std::unordered_set<std::string> triggerIds;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020092
Wludzik, Jozefe2362792020-10-27 17:23:55 +010093 interfaces::JsonStorage& reportStorage;
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020094 bool enabled;
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010095 std::unique_ptr<interfaces::Clock> clock;
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +010096 utils::Messanger messanger;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010097
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020098 public:
99 static constexpr const char* reportIfaceName =
100 "xyz.openbmc_project.Telemetry.Report";
101 static constexpr const char* reportDir =
102 "/xyz/openbmc_project/Telemetry/Reports/";
103 static constexpr const char* deleteIfaceName =
104 "xyz.openbmc_project.Object.Delete";
Krzysztof Grobelny51497a02021-11-09 14:56:22 +0100105 static constexpr size_t reportVersion = 6;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +0200106};