blob: 3e649fd080d86a7dde73828b908ceee258128832 [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>
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010020#include <unordered_set>
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020021
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020022class Report : public interfaces::Report
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020023{
24 public:
25 Report(boost::asio::io_context& ioc,
26 const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010027 const std::string& reportId, const std::string& reportName,
28 const ReportingType reportingType,
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010029 std::vector<ReportAction> reportActions, const Milliseconds period,
Szymon Dompke3eb56862021-09-20 15:32:04 +020030 const uint64_t appendLimitIn, const ReportUpdates reportUpdatesIn,
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020031 interfaces::ReportManager& reportManager,
Wludzik, Jozefe2362792020-10-27 17:23:55 +010032 interfaces::JsonStorage& reportStorage,
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020033 std::vector<std::shared_ptr<interfaces::Metric>> metrics,
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010034 const bool enabled, std::unique_ptr<interfaces::Clock> clock,
35 const std::vector<std::string>& triggerIds);
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
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010052 void updateReadings() override;
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010053 void updateTriggerIds(const std::string& triggerId,
54 TriggerIdUpdate updateType) override;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010055 bool storeConfiguration() const;
56
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020057 private:
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000058 std::unique_ptr<sdbusplus::asio::dbus_interface> makeReportInterface();
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020059 static void timerProc(boost::system::error_code, Report& self);
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000060 void scheduleTimer(Milliseconds interval);
Krzysztof Grobelnye6c417c2022-02-02 17:25:53 +010061 std::optional<uint64_t>
62 deduceAppendLimit(const uint64_t appendLimitIn) const;
Szymon Dompke3eb56862021-09-20 15:32:04 +020063 uint64_t deduceBufferSize(const ReportUpdates reportUpdatesIn,
64 const ReportingType reportingTypeIn) const;
65 void setReportUpdates(const ReportUpdates newReportUpdates);
66 static uint64_t getSensorCount(
67 std::vector<std::shared_ptr<interfaces::Metric>>& metrics);
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010068 interfaces::JsonStorage::FilePath fileName() const;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020069
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010070 std::string id;
Szymon Dompkee28aa532021-10-27 12:33:12 +020071 std::string name;
Szymon Dompke3eb56862021-09-20 15:32:04 +020072 ReportingType reportingType;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000073 Milliseconds interval;
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010074 std::vector<ReportAction> reportActions;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000075 ReadingParametersPastVersion readingParametersPastVersion;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010076 ReadingParameters readingParameters;
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000077 bool persistency = false;
Szymon Dompke3eb56862021-09-20 15:32:04 +020078 uint64_t sensorCount;
Krzysztof Grobelnye6c417c2022-02-02 17:25:53 +010079 std::optional<uint64_t> appendLimit;
Szymon Dompke3eb56862021-09-20 15:32:04 +020080 ReportUpdates reportUpdates;
81 CircularVector<ReadingData> readingsBuffer;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020082 Readings readings = {};
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020083 std::shared_ptr<sdbusplus::asio::object_server> objServer;
84 std::unique_ptr<sdbusplus::asio::dbus_interface> reportIface;
85 std::unique_ptr<sdbusplus::asio::dbus_interface> deleteIface;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020086 std::vector<std::shared_ptr<interfaces::Metric>> metrics;
87 boost::asio::steady_timer timer;
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010088 std::unordered_set<std::string> triggerIds;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020089
Wludzik, Jozefe2362792020-10-27 17:23:55 +010090 interfaces::JsonStorage& reportStorage;
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020091 bool enabled;
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010092 std::unique_ptr<interfaces::Clock> clock;
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};