blob: d9ecb33ea9caa30a40f6b2072583cfea335a4b54 [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 Grobelny9f9ff902021-03-05 14:57:53 +00007#include "interfaces/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,
23 const bool logToMetricReportsCollection,
24 const std::chrono::milliseconds period,
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020025 const ReadingParameters& metricParams,
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020026 interfaces::ReportManager& reportManager,
Wludzik, Jozefe2362792020-10-27 17:23:55 +010027 interfaces::JsonStorage& reportStorage,
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020028 std::vector<std::shared_ptr<interfaces::Metric>> metrics);
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020029 ~Report() = default;
30
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020031 Report(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020032 Report(Report&&) = delete;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020033 Report& operator=(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020034 Report& operator=(Report&&) = delete;
35
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020036 std::string getName() const override
37 {
38 return name;
39 }
40
41 std::string getPath() const override
42 {
43 return path;
44 }
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020045
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010046 void updateReadings() override;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010047 bool storeConfiguration() const;
48
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020049 private:
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000050 std::unique_ptr<sdbusplus::asio::dbus_interface> makeReportInterface();
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020051 static void timerProc(boost::system::error_code, Report& self);
52 void scheduleTimer(std::chrono::milliseconds interval);
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020053
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020054 const std::string name;
55 const std::string path;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010056 std::string reportingType;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020057 std::chrono::milliseconds interval;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010058 bool emitsReadingsUpdate;
59 bool logToMetricReportsCollection;
60 ReadingParameters readingParameters;
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000061 bool persistency = false;
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 Grobelnye8fc5752021-02-05 14:30:45 +000079 static constexpr size_t reportVersion = 3;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020080};