blob: 5ac6fd07ddad86278619e3d60d242697da1804bb [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"
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +010013#include "utils/messanger.hpp"
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020014
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020015#include <boost/asio/io_context.hpp>
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020016#include <boost/asio/steady_timer.hpp>
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020017#include <sdbusplus/asio/object_server.hpp>
18
19#include <chrono>
20#include <memory>
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010021#include <unordered_set>
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020022
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020023class Report : public interfaces::Report
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020024{
25 public:
26 Report(boost::asio::io_context& ioc,
27 const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010028 const std::string& reportId, const std::string& reportName,
29 const ReportingType reportingType,
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010030 std::vector<ReportAction> reportActions, const Milliseconds period,
Szymon Dompke3eb56862021-09-20 15:32:04 +020031 const uint64_t appendLimitIn, const ReportUpdates reportUpdatesIn,
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020032 interfaces::ReportManager& reportManager,
Wludzik, Jozefe2362792020-10-27 17:23:55 +010033 interfaces::JsonStorage& reportStorage,
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020034 std::vector<std::shared_ptr<interfaces::Metric>> metrics,
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +010035 const bool enabled, std::unique_ptr<interfaces::Clock> clock);
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020036
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020037 Report(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020038 Report(Report&&) = delete;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020039 Report& operator=(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020040 Report& operator=(Report&&) = delete;
41
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010042 std::string getId() const override
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020043 {
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010044 return id;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020045 }
46
47 std::string getPath() const override
48 {
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010049 return reportDir + id;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020050 }
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020051
52 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);
Krzysztof Grobelnye6c417c2022-02-02 17:25:53 +010056 std::optional<uint64_t>
57 deduceAppendLimit(const uint64_t appendLimitIn) const;
Szymon Dompke3eb56862021-09-20 15:32:04 +020058 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 Grobelnye6d48872022-02-08 13:41:30 +010064 std::unordered_set<std::string>
65 collectTriggerIds(boost::asio::io_context& ioc) const;
66 bool storeConfiguration() const;
67 void updateReadings();
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020068
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010069 std::string id;
Szymon Dompkee28aa532021-10-27 12:33:12 +020070 std::string name;
Szymon Dompke3eb56862021-09-20 15:32:04 +020071 ReportingType reportingType;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000072 Milliseconds interval;
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010073 std::vector<ReportAction> reportActions;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000074 ReadingParametersPastVersion readingParametersPastVersion;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010075 ReadingParameters readingParameters;
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000076 bool persistency = false;
Szymon Dompke3eb56862021-09-20 15:32:04 +020077 uint64_t sensorCount;
Krzysztof Grobelnye6c417c2022-02-02 17:25:53 +010078 std::optional<uint64_t> appendLimit;
Szymon Dompke3eb56862021-09-20 15:32:04 +020079 ReportUpdates reportUpdates;
80 CircularVector<ReadingData> readingsBuffer;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020081 Readings readings = {};
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020082 std::shared_ptr<sdbusplus::asio::object_server> objServer;
83 std::unique_ptr<sdbusplus::asio::dbus_interface> reportIface;
84 std::unique_ptr<sdbusplus::asio::dbus_interface> deleteIface;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020085 std::vector<std::shared_ptr<interfaces::Metric>> metrics;
86 boost::asio::steady_timer timer;
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010087 std::unordered_set<std::string> triggerIds;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020088
Wludzik, Jozefe2362792020-10-27 17:23:55 +010089 interfaces::JsonStorage& reportStorage;
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020090 bool enabled;
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010091 std::unique_ptr<interfaces::Clock> clock;
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +010092 utils::Messanger messanger;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010093
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020094 public:
95 static constexpr const char* reportIfaceName =
96 "xyz.openbmc_project.Telemetry.Report";
97 static constexpr const char* reportDir =
98 "/xyz/openbmc_project/Telemetry/Reports/";
99 static constexpr const char* deleteIfaceName =
100 "xyz.openbmc_project.Object.Delete";
Krzysztof Grobelny51497a02021-11-09 14:56:22 +0100101 static constexpr size_t reportVersion = 6;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +0200102};