blob: c758988bd5e2e4492b1b809daf046fb308c74b47 [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 Grobelnydcc4e192021-03-08 09:09:34 +00007#include "types/report_types.hpp"
Szymon Dompke3eb56862021-09-20 15:32:04 +02008#include "utils/circular_vector.hpp"
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +02009
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020010#include <boost/asio/io_context.hpp>
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020011#include <boost/asio/steady_timer.hpp>
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020012#include <sdbusplus/asio/object_server.hpp>
13
14#include <chrono>
15#include <memory>
16
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020017class Report : public interfaces::Report
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020018{
19 public:
20 Report(boost::asio::io_context& ioc,
21 const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
Szymon Dompke3eb56862021-09-20 15:32:04 +020022 const std::string& reportName, const ReportingType reportingType,
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020023 const bool emitsReadingsSignal,
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000024 const bool logToMetricReportsCollection, const Milliseconds period,
Szymon Dompke3eb56862021-09-20 15:32:04 +020025 const uint64_t appendLimitIn, const ReportUpdates reportUpdatesIn,
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020026 interfaces::ReportManager& reportManager,
Wludzik, Jozefe2362792020-10-27 17:23:55 +010027 interfaces::JsonStorage& reportStorage,
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020028 std::vector<std::shared_ptr<interfaces::Metric>> metrics,
29 const bool enabled);
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020030 ~Report() = default;
31
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020032 Report(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020033 Report(Report&&) = delete;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020034 Report& operator=(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020035 Report& operator=(Report&&) = delete;
36
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020037 std::string getName() const override
38 {
39 return name;
40 }
41
42 std::string getPath() const override
43 {
44 return path;
45 }
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020046
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010047 void updateReadings() override;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010048 bool storeConfiguration() const;
49
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020050 private:
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000051 std::unique_ptr<sdbusplus::asio::dbus_interface> makeReportInterface();
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020052 static void timerProc(boost::system::error_code, Report& self);
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000053 void scheduleTimer(Milliseconds interval);
Szymon Dompke3eb56862021-09-20 15:32:04 +020054 uint64_t deduceAppendLimit(const uint64_t appendLimitIn) const;
55 uint64_t deduceBufferSize(const ReportUpdates reportUpdatesIn,
56 const ReportingType reportingTypeIn) const;
57 void setReportUpdates(const ReportUpdates newReportUpdates);
58 static uint64_t getSensorCount(
59 std::vector<std::shared_ptr<interfaces::Metric>>& metrics);
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020060
Szymon Dompkee28aa532021-10-27 12:33:12 +020061 std::string name;
62 std::string path;
Szymon Dompke3eb56862021-09-20 15:32:04 +020063 ReportingType reportingType;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000064 Milliseconds interval;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010065 bool emitsReadingsUpdate;
66 bool logToMetricReportsCollection;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000067 ReadingParametersPastVersion readingParametersPastVersion;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010068 ReadingParameters readingParameters;
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000069 bool persistency = false;
Szymon Dompke3eb56862021-09-20 15:32:04 +020070 uint64_t sensorCount;
71 uint64_t appendLimit;
72 ReportUpdates reportUpdates;
73 CircularVector<ReadingData> readingsBuffer;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020074 Readings readings = {};
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020075 std::shared_ptr<sdbusplus::asio::object_server> objServer;
76 std::unique_ptr<sdbusplus::asio::dbus_interface> reportIface;
77 std::unique_ptr<sdbusplus::asio::dbus_interface> deleteIface;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020078 std::vector<std::shared_ptr<interfaces::Metric>> metrics;
79 boost::asio::steady_timer timer;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020080
Wludzik, Jozefe2362792020-10-27 17:23:55 +010081 interfaces::JsonStorage::FilePath fileName;
82 interfaces::JsonStorage& reportStorage;
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020083 bool enabled;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010084
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020085 public:
86 static constexpr const char* reportIfaceName =
87 "xyz.openbmc_project.Telemetry.Report";
88 static constexpr const char* reportDir =
89 "/xyz/openbmc_project/Telemetry/Reports/";
90 static constexpr const char* deleteIfaceName =
91 "xyz.openbmc_project.Object.Delete";
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000092 static constexpr size_t reportVersion = 4;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020093};