blob: 26cc130fe95cda17cf87aadb20eeb35d1933f323 [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,
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020026 std::vector<std::shared_ptr<interfaces::Metric>> metrics,
27 const bool enabled);
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020028 ~Report() = default;
29
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020030 Report(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020031 Report(Report&&) = delete;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020032 Report& operator=(const Report&) = delete;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020033 Report& operator=(Report&&) = delete;
34
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020035 std::string getName() const override
36 {
37 return name;
38 }
39
40 std::string getPath() const override
41 {
42 return path;
43 }
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020044
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010045 void updateReadings() override;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010046 bool storeConfiguration() const;
47
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020048 private:
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000049 std::unique_ptr<sdbusplus::asio::dbus_interface> makeReportInterface();
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020050 static void timerProc(boost::system::error_code, Report& self);
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000051 void scheduleTimer(Milliseconds interval);
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020052
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020053 const std::string name;
54 const std::string path;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010055 std::string reportingType;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000056 Milliseconds interval;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010057 bool emitsReadingsUpdate;
58 bool logToMetricReportsCollection;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000059 ReadingParametersPastVersion readingParametersPastVersion;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010060 ReadingParameters readingParameters;
Krzysztof Grobelny85db8bd2021-05-28 12:13:23 +000061 bool persistency = false;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000062 Readings cachedReadings = {};
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020063 Readings readings = {};
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020064 std::shared_ptr<sdbusplus::asio::object_server> objServer;
65 std::unique_ptr<sdbusplus::asio::dbus_interface> reportIface;
66 std::unique_ptr<sdbusplus::asio::dbus_interface> deleteIface;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020067 std::vector<std::shared_ptr<interfaces::Metric>> metrics;
68 boost::asio::steady_timer timer;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020069
Wludzik, Jozefe2362792020-10-27 17:23:55 +010070 interfaces::JsonStorage::FilePath fileName;
71 interfaces::JsonStorage& reportStorage;
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020072 bool enabled;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010073
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020074 public:
75 static constexpr const char* reportIfaceName =
76 "xyz.openbmc_project.Telemetry.Report";
77 static constexpr const char* reportDir =
78 "/xyz/openbmc_project/Telemetry/Reports/";
79 static constexpr const char* deleteIfaceName =
80 "xyz.openbmc_project.Object.Delete";
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000081 static constexpr size_t reportVersion = 4;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020082};