blob: 2020f9927c3dcbf3d74ac591b05e92ab6df49c51 [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"
7#include "interfaces/types.hpp"
8
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, Jozefe2362792020-10-27 17:23:55 +010046 bool storeConfiguration() const;
47
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020048 private:
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020049 static void timerProc(boost::system::error_code, Report& self);
50 void scheduleTimer(std::chrono::milliseconds interval);
51 void updateReadings();
52
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 = {};
62 std::tuple_element_t<1, Readings> readingsCache = {};
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";
Wludzik, Jozefe2362792020-10-27 17:23:55 +010079 static constexpr size_t reportVersion = 1;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020080};