blob: 98097ae1cb607a1b648ab2aabcf93ec0e4610ff6 [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"
7#include "interfaces/report_manager.hpp"
Krzysztof Grobelny51497a02021-11-09 14:56:22 +01008#include "types/report_action.hpp"
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +00009#include "types/report_types.hpp"
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010010#include "types/report_updates.hpp"
11#include "types/reporting_type.hpp"
Szymon Dompke3eb56862021-09-20 15:32:04 +020012#include "utils/circular_vector.hpp"
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020013
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020014#include <boost/asio/io_context.hpp>
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020015#include <boost/asio/steady_timer.hpp>
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020016#include <sdbusplus/asio/object_server.hpp>
17
18#include <chrono>
19#include <memory>
20
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020021class Report : public interfaces::Report
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020022{
23 public:
24 Report(boost::asio::io_context& ioc,
25 const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010026 const std::string& reportId, const std::string& reportName,
27 const ReportingType reportingType,
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010028 std::vector<ReportAction> reportActions, const Milliseconds period,
Szymon Dompke3eb56862021-09-20 15:32:04 +020029 const uint64_t appendLimitIn, const ReportUpdates reportUpdatesIn,
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020030 interfaces::ReportManager& reportManager,
Wludzik, Jozefe2362792020-10-27 17:23:55 +010031 interfaces::JsonStorage& reportStorage,
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020032 std::vector<std::shared_ptr<interfaces::Metric>> metrics,
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010033 const bool enabled, std::unique_ptr<interfaces::Clock> clock);
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020034
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020035 Report(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020036 Report(Report&&) = delete;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020037 Report& operator=(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020038 Report& operator=(Report&&) = delete;
39
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010040 std::string getId() const override
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020041 {
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010042 return id;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020043 }
44
45 std::string getPath() const override
46 {
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010047 return reportDir + id;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020048 }
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020049
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010050 void updateReadings() override;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010051 bool storeConfiguration() const;
52
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020053 private:
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000054 std::unique_ptr<sdbusplus::asio::dbus_interface> makeReportInterface();
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020055 static void timerProc(boost::system::error_code, Report& self);
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000056 void scheduleTimer(Milliseconds interval);
Krzysztof Grobelnye6c417c2022-02-02 17:25:53 +010057 std::optional<uint64_t>
58 deduceAppendLimit(const uint64_t appendLimitIn) const;
Szymon Dompke3eb56862021-09-20 15:32:04 +020059 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);
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010064 interfaces::JsonStorage::FilePath fileName() const;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020065
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010066 std::string id;
Szymon Dompkee28aa532021-10-27 12:33:12 +020067 std::string name;
Szymon Dompke3eb56862021-09-20 15:32:04 +020068 ReportingType reportingType;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000069 Milliseconds interval;
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010070 std::vector<ReportAction> reportActions;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000071 ReadingParametersPastVersion readingParametersPastVersion;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010072 ReadingParameters readingParameters;
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000073 bool persistency = false;
Szymon Dompke3eb56862021-09-20 15:32:04 +020074 uint64_t sensorCount;
Krzysztof Grobelnye6c417c2022-02-02 17:25:53 +010075 std::optional<uint64_t> appendLimit;
Szymon Dompke3eb56862021-09-20 15:32:04 +020076 ReportUpdates reportUpdates;
77 CircularVector<ReadingData> readingsBuffer;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020078 Readings readings = {};
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020079 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;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020082 std::vector<std::shared_ptr<interfaces::Metric>> metrics;
83 boost::asio::steady_timer timer;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020084
Wludzik, Jozefe2362792020-10-27 17:23:55 +010085 interfaces::JsonStorage& reportStorage;
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020086 bool enabled;
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010087 std::unique_ptr<interfaces::Clock> clock;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010088
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020089 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";
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010096 static constexpr size_t reportVersion = 6;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020097};