blob: 8cef26a26a53e06f32c2a1c948374a6a8b146383 [file] [log] [blame]
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +02001#pragma once
2
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +02003#include "interfaces/metric.hpp"
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +02004#include "interfaces/report.hpp"
5#include "interfaces/report_manager.hpp"
6#include "interfaces/types.hpp"
7
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +02008#include <boost/asio/io_context.hpp>
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +02009#include <boost/asio/steady_timer.hpp>
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020010#include <sdbusplus/asio/object_server.hpp>
11
12#include <chrono>
13#include <memory>
14
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020015class Report : public interfaces::Report
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020016{
17 public:
18 Report(boost::asio::io_context& ioc,
19 const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020020 const std::string& reportName, const std::string& reportingType,
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020021 const bool emitsReadingsSignal,
22 const bool logToMetricReportsCollection,
23 const std::chrono::milliseconds period,
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020024 const ReadingParameters& metricParams,
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020025 interfaces::ReportManager& reportManager,
26 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
44 private:
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020045 static void timerProc(boost::system::error_code, Report& self);
46 void scheduleTimer(std::chrono::milliseconds interval);
47 void updateReadings();
48
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020049 const std::string name;
50 const std::string path;
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020051 std::chrono::milliseconds interval;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020052 Readings readings = {};
53 std::tuple_element_t<1, Readings> readingsCache = {};
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020054 std::shared_ptr<sdbusplus::asio::object_server> objServer;
55 std::unique_ptr<sdbusplus::asio::dbus_interface> reportIface;
56 std::unique_ptr<sdbusplus::asio::dbus_interface> deleteIface;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020057 std::vector<std::shared_ptr<interfaces::Metric>> metrics;
58 boost::asio::steady_timer timer;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020059
60 public:
61 static constexpr const char* reportIfaceName =
62 "xyz.openbmc_project.Telemetry.Report";
63 static constexpr const char* reportDir =
64 "/xyz/openbmc_project/Telemetry/Reports/";
65 static constexpr const char* deleteIfaceName =
66 "xyz.openbmc_project.Object.Delete";
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +020067};