xref: /openbmc/telemetry/src/report.hpp (revision e2362796befa500153beb22d3eae0a959bf825f4)
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     bool storeConfiguration() const;
47 
48   private:
49     static void timerProc(boost::system::error_code, Report& self);
50     void scheduleTimer(std::chrono::milliseconds interval);
51     void updateReadings();
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::tuple_element_t<1, Readings> readingsCache = {};
63     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;
66     std::vector<std::shared_ptr<interfaces::Metric>> metrics;
67     boost::asio::steady_timer timer;
68 
69     interfaces::JsonStorage::FilePath fileName;
70     interfaces::JsonStorage& reportStorage;
71 
72   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";
79     static constexpr size_t reportVersion = 1;
80 };
81