blob: 97afe03473790929cbf5e07ccfa417e330ef2f1e [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 Grobelnyc8e3a642020-10-23 12:29:16 +020050 static void timerProc(boost::system::error_code, Report& self);
51 void scheduleTimer(std::chrono::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;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020056 std::chrono::milliseconds interval;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010057 bool emitsReadingsUpdate;
58 bool logToMetricReportsCollection;
59 ReadingParameters readingParameters;
60 bool persistency;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020061 Readings readings = {};
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020062 std::shared_ptr<sdbusplus::asio::object_server> objServer;
63 std::unique_ptr<sdbusplus::asio::dbus_interface> reportIface;
64 std::unique_ptr<sdbusplus::asio::dbus_interface> deleteIface;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020065 std::vector<std::shared_ptr<interfaces::Metric>> metrics;
66 boost::asio::steady_timer timer;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020067
Wludzik, Jozefe2362792020-10-27 17:23:55 +010068 interfaces::JsonStorage::FilePath fileName;
69 interfaces::JsonStorage& reportStorage;
70
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020071 public:
72 static constexpr const char* reportIfaceName =
73 "xyz.openbmc_project.Telemetry.Report";
74 static constexpr const char* reportDir =
75 "/xyz/openbmc_project/Telemetry/Reports/";
76 static constexpr const char* deleteIfaceName =
77 "xyz.openbmc_project.Object.Delete";
Krzysztof Grobelnye8fc5752021-02-05 14:30:45 +000078 static constexpr size_t reportVersion = 3;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020079};