blob: 72563f50046783f1bfd81a376b97b41e2efdc758 [file] [log] [blame]
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +02001#pragma once
2
Wludzik, Jozefe2362792020-10-27 17:23:55 +01003#include "interfaces/json_storage.hpp"
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +02004#include "interfaces/metric.hpp"
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +02005#include "interfaces/report.hpp"
6#include "interfaces/report_manager.hpp"
Krzysztof Grobelny51497a02021-11-09 14:56:22 +01007#include "types/report_action.hpp"
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +00008#include "types/report_types.hpp"
Krzysztof Grobelny51497a02021-11-09 14:56:22 +01009#include "types/report_updates.hpp"
10#include "types/reporting_type.hpp"
Szymon Dompke3eb56862021-09-20 15:32:04 +020011#include "utils/circular_vector.hpp"
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020012
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020013#include <boost/asio/io_context.hpp>
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020014#include <boost/asio/steady_timer.hpp>
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020015#include <sdbusplus/asio/object_server.hpp>
16
17#include <chrono>
18#include <memory>
19
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020020class Report : public interfaces::Report
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020021{
22 public:
23 Report(boost::asio::io_context& ioc,
24 const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010025 const std::string& reportId, const std::string& reportName,
26 const ReportingType reportingType,
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010027 std::vector<ReportAction> reportActions, const Milliseconds period,
Szymon Dompke3eb56862021-09-20 15:32:04 +020028 const uint64_t appendLimitIn, const ReportUpdates reportUpdatesIn,
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020029 interfaces::ReportManager& reportManager,
Wludzik, Jozefe2362792020-10-27 17:23:55 +010030 interfaces::JsonStorage& reportStorage,
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020031 std::vector<std::shared_ptr<interfaces::Metric>> metrics,
32 const bool enabled);
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020033 ~Report() = default;
34
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);
Szymon Dompke3eb56862021-09-20 15:32:04 +020057 uint64_t deduceAppendLimit(const uint64_t appendLimitIn) const;
58 uint64_t deduceBufferSize(const ReportUpdates reportUpdatesIn,
59 const ReportingType reportingTypeIn) const;
60 void setReportUpdates(const ReportUpdates newReportUpdates);
61 static uint64_t getSensorCount(
62 std::vector<std::shared_ptr<interfaces::Metric>>& metrics);
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010063 interfaces::JsonStorage::FilePath fileName() const;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020064
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010065 std::string id;
Szymon Dompkee28aa532021-10-27 12:33:12 +020066 std::string name;
Szymon Dompke3eb56862021-09-20 15:32:04 +020067 ReportingType reportingType;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000068 Milliseconds interval;
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010069 std::vector<ReportAction> reportActions;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000070 ReadingParametersPastVersion readingParametersPastVersion;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010071 ReadingParameters readingParameters;
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000072 bool persistency = false;
Szymon Dompke3eb56862021-09-20 15:32:04 +020073 uint64_t sensorCount;
74 uint64_t appendLimit;
75 ReportUpdates reportUpdates;
76 CircularVector<ReadingData> readingsBuffer;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020077 Readings readings = {};
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020078 std::shared_ptr<sdbusplus::asio::object_server> objServer;
79 std::unique_ptr<sdbusplus::asio::dbus_interface> reportIface;
80 std::unique_ptr<sdbusplus::asio::dbus_interface> deleteIface;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020081 std::vector<std::shared_ptr<interfaces::Metric>> metrics;
82 boost::asio::steady_timer timer;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020083
Wludzik, Jozefe2362792020-10-27 17:23:55 +010084 interfaces::JsonStorage& reportStorage;
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020085 bool enabled;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010086
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020087 public:
88 static constexpr const char* reportIfaceName =
89 "xyz.openbmc_project.Telemetry.Report";
90 static constexpr const char* reportDir =
91 "/xyz/openbmc_project/Telemetry/Reports/";
92 static constexpr const char* deleteIfaceName =
93 "xyz.openbmc_project.Object.Delete";
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010094 static constexpr size_t reportVersion = 6;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020095};