blob: 5d675bfce5aee35139e5daaab9cf48f71aa00f76 [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,
Szymon Dompke3eb56862021-09-20 15:32:04 +020025 const std::string& reportName, const ReportingType reportingType,
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010026 std::vector<ReportAction> reportActions, const Milliseconds period,
Szymon Dompke3eb56862021-09-20 15:32:04 +020027 const uint64_t appendLimitIn, const ReportUpdates reportUpdatesIn,
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020028 interfaces::ReportManager& reportManager,
Wludzik, Jozefe2362792020-10-27 17:23:55 +010029 interfaces::JsonStorage& reportStorage,
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020030 std::vector<std::shared_ptr<interfaces::Metric>> metrics,
31 const bool enabled);
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020032 ~Report() = default;
33
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020034 Report(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020035 Report(Report&&) = delete;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020036 Report& operator=(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020037 Report& operator=(Report&&) = delete;
38
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020039 std::string getName() const override
40 {
41 return name;
42 }
43
44 std::string getPath() const override
45 {
46 return path;
47 }
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020048
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010049 void updateReadings() override;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010050 bool storeConfiguration() const;
51
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020052 private:
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000053 std::unique_ptr<sdbusplus::asio::dbus_interface> makeReportInterface();
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020054 static void timerProc(boost::system::error_code, Report& self);
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000055 void scheduleTimer(Milliseconds interval);
Szymon Dompke3eb56862021-09-20 15:32:04 +020056 uint64_t deduceAppendLimit(const uint64_t appendLimitIn) const;
57 uint64_t deduceBufferSize(const ReportUpdates reportUpdatesIn,
58 const ReportingType reportingTypeIn) const;
59 void setReportUpdates(const ReportUpdates newReportUpdates);
60 static uint64_t getSensorCount(
61 std::vector<std::shared_ptr<interfaces::Metric>>& metrics);
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020062
Szymon Dompkee28aa532021-10-27 12:33:12 +020063 std::string name;
64 std::string path;
Szymon Dompke3eb56862021-09-20 15:32:04 +020065 ReportingType reportingType;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000066 Milliseconds interval;
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010067 std::vector<ReportAction> reportActions;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000068 ReadingParametersPastVersion readingParametersPastVersion;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010069 ReadingParameters readingParameters;
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000070 bool persistency = false;
Szymon Dompke3eb56862021-09-20 15:32:04 +020071 uint64_t sensorCount;
72 uint64_t appendLimit;
73 ReportUpdates reportUpdates;
74 CircularVector<ReadingData> readingsBuffer;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020075 Readings readings = {};
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020076 std::shared_ptr<sdbusplus::asio::object_server> objServer;
77 std::unique_ptr<sdbusplus::asio::dbus_interface> reportIface;
78 std::unique_ptr<sdbusplus::asio::dbus_interface> deleteIface;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020079 std::vector<std::shared_ptr<interfaces::Metric>> metrics;
80 boost::asio::steady_timer timer;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020081
Wludzik, Jozefe2362792020-10-27 17:23:55 +010082 interfaces::JsonStorage::FilePath fileName;
83 interfaces::JsonStorage& reportStorage;
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020084 bool enabled;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010085
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020086 public:
87 static constexpr const char* reportIfaceName =
88 "xyz.openbmc_project.Telemetry.Report";
89 static constexpr const char* reportDir =
90 "/xyz/openbmc_project/Telemetry/Reports/";
91 static constexpr const char* deleteIfaceName =
92 "xyz.openbmc_project.Object.Delete";
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010093 static constexpr size_t reportVersion = 6;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020094};