blob: 92293a09b166627d54d50c68d5152c167c44c429 [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"
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +02008
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +02009#include <boost/asio/io_context.hpp>
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020010#include <boost/asio/steady_timer.hpp>
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020011#include <sdbusplus/asio/object_server.hpp>
12
13#include <chrono>
14#include <memory>
15
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020016class Report : public interfaces::Report
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020017{
18 public:
19 Report(boost::asio::io_context& ioc,
20 const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020021 const std::string& reportName, const std::string& reportingType,
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020022 const bool emitsReadingsSignal,
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000023 const bool logToMetricReportsCollection, const Milliseconds period,
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020024 interfaces::ReportManager& reportManager,
Wludzik, Jozefe2362792020-10-27 17:23:55 +010025 interfaces::JsonStorage& reportStorage,
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020026 std::vector<std::shared_ptr<interfaces::Metric>> metrics);
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020027 ~Report() = default;
28
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020029 Report(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020030 Report(Report&&) = delete;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020031 Report& operator=(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020032 Report& operator=(Report&&) = delete;
33
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020034 std::string getName() const override
35 {
36 return name;
37 }
38
39 std::string getPath() const override
40 {
41 return path;
42 }
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020043
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010044 void updateReadings() override;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010045 bool storeConfiguration() const;
46
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020047 private:
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000048 std::unique_ptr<sdbusplus::asio::dbus_interface> makeReportInterface();
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020049 static void timerProc(boost::system::error_code, Report& self);
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000050 void scheduleTimer(Milliseconds interval);
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020051
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020052 const std::string name;
53 const std::string path;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010054 std::string reportingType;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000055 Milliseconds interval;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010056 bool emitsReadingsUpdate;
57 bool logToMetricReportsCollection;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000058 ReadingParametersPastVersion readingParametersPastVersion;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010059 ReadingParameters readingParameters;
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000060 bool persistency = false;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000061 Readings cachedReadings = {};
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020062 Readings readings = {};
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020063 std::shared_ptr<sdbusplus::asio::object_server> objServer;
64 std::unique_ptr<sdbusplus::asio::dbus_interface> reportIface;
65 std::unique_ptr<sdbusplus::asio::dbus_interface> deleteIface;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020066 std::vector<std::shared_ptr<interfaces::Metric>> metrics;
67 boost::asio::steady_timer timer;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020068
Wludzik, Jozefe2362792020-10-27 17:23:55 +010069 interfaces::JsonStorage::FilePath fileName;
70 interfaces::JsonStorage& reportStorage;
71
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020072 public:
73 static constexpr const char* reportIfaceName =
74 "xyz.openbmc_project.Telemetry.Report";
75 static constexpr const char* reportDir =
76 "/xyz/openbmc_project/Telemetry/Reports/";
77 static constexpr const char* deleteIfaceName =
78 "xyz.openbmc_project.Object.Delete";
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000079 static constexpr size_t reportVersion = 4;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020080};