blob: e2f422d916a952614ba7e63b9abb6b03c8be0910 [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 ~Report() = default;
35
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020036 Report(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020037 Report(Report&&) = delete;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020038 Report& operator=(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020039 Report& operator=(Report&&) = delete;
40
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010041 std::string getId() const override
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020042 {
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010043 return id;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020044 }
45
46 std::string getPath() const override
47 {
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010048 return reportDir + id;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020049 }
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020050
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010051 void updateReadings() override;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010052 bool storeConfiguration() const;
53
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020054 private:
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000055 std::unique_ptr<sdbusplus::asio::dbus_interface> makeReportInterface();
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020056 static void timerProc(boost::system::error_code, Report& self);
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000057 void scheduleTimer(Milliseconds interval);
Szymon Dompke3eb56862021-09-20 15:32:04 +020058 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);
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;
75 uint64_t appendLimit;
76 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};