xref: /openbmc/telemetry/src/report.hpp (revision 405c1e4bf8b993cb3800adead546e91b030ecb9b)
1 #pragma once
2 
3 #include "interfaces/json_storage.hpp"
4 #include "interfaces/metric.hpp"
5 #include "interfaces/report.hpp"
6 #include "interfaces/report_manager.hpp"
7 #include "interfaces/types.hpp"
8 
9 #include <boost/asio/io_context.hpp>
10 #include <boost/asio/steady_timer.hpp>
11 #include <sdbusplus/asio/object_server.hpp>
12 
13 #include <chrono>
14 #include <memory>
15 
16 class Report : public interfaces::Report
17 {
18   public:
19     Report(boost::asio::io_context& ioc,
20            const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
21            const std::string& reportName, const std::string& reportingType,
22            const bool emitsReadingsSignal,
23            const bool logToMetricReportsCollection,
24            const std::chrono::milliseconds period,
25            const ReadingParameters& metricParams,
26            interfaces::ReportManager& reportManager,
27            interfaces::JsonStorage& reportStorage,
28            std::vector<std::shared_ptr<interfaces::Metric>> metrics);
29     ~Report() = default;
30 
31     Report(const Report&) = delete;
32     Report(Report&&) = delete;
33     Report& operator=(const Report&) = delete;
34     Report& operator=(Report&&) = delete;
35 
36     std::string getName() const override
37     {
38         return name;
39     }
40 
41     std::string getPath() const override
42     {
43         return path;
44     }
45 
46     void updateReadings() override;
47     bool storeConfiguration() const;
48 
49   private:
50     static void timerProc(boost::system::error_code, Report& self);
51     void scheduleTimer(std::chrono::milliseconds interval);
52 
53     const std::string name;
54     const std::string path;
55     std::string reportingType;
56     std::chrono::milliseconds interval;
57     bool emitsReadingsUpdate;
58     bool logToMetricReportsCollection;
59     ReadingParameters readingParameters;
60     bool persistency;
61     Readings readings = {};
62     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;
65     std::vector<std::shared_ptr<interfaces::Metric>> metrics;
66     boost::asio::steady_timer timer;
67 
68     interfaces::JsonStorage::FilePath fileName;
69     interfaces::JsonStorage& reportStorage;
70 
71   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";
78     static constexpr size_t reportVersion = 3;
79 };
80