Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 3 | #include "interfaces/json_storage.hpp" |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 4 | #include "interfaces/metric.hpp" |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 5 | #include "interfaces/report.hpp" |
| 6 | #include "interfaces/report_manager.hpp" |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame^] | 7 | #include "types/report_action.hpp" |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 8 | #include "types/report_types.hpp" |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame^] | 9 | #include "types/report_updates.hpp" |
| 10 | #include "types/reporting_type.hpp" |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 11 | #include "utils/circular_vector.hpp" |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 12 | |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 13 | #include <boost/asio/io_context.hpp> |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 14 | #include <boost/asio/steady_timer.hpp> |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 15 | #include <sdbusplus/asio/object_server.hpp> |
| 16 | |
| 17 | #include <chrono> |
| 18 | #include <memory> |
| 19 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 20 | class Report : public interfaces::Report |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 21 | { |
| 22 | public: |
| 23 | Report(boost::asio::io_context& ioc, |
| 24 | const std::shared_ptr<sdbusplus::asio::object_server>& objServer, |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 25 | const std::string& reportName, const ReportingType reportingType, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame^] | 26 | std::vector<ReportAction> reportActions, const Milliseconds period, |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 27 | const uint64_t appendLimitIn, const ReportUpdates reportUpdatesIn, |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 28 | interfaces::ReportManager& reportManager, |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 29 | interfaces::JsonStorage& reportStorage, |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 30 | std::vector<std::shared_ptr<interfaces::Metric>> metrics, |
| 31 | const bool enabled); |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 32 | ~Report() = default; |
| 33 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 34 | Report(const Report&) = delete; |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 35 | Report(Report&&) = delete; |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 36 | Report& operator=(const Report&) = delete; |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 37 | Report& operator=(Report&&) = delete; |
| 38 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 39 | std::string getName() const override |
| 40 | { |
| 41 | return name; |
| 42 | } |
| 43 | |
| 44 | std::string getPath() const override |
| 45 | { |
| 46 | return path; |
| 47 | } |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 48 | |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 49 | void updateReadings() override; |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 50 | bool storeConfiguration() const; |
| 51 | |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 52 | private: |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 53 | std::unique_ptr<sdbusplus::asio::dbus_interface> makeReportInterface(); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 54 | static void timerProc(boost::system::error_code, Report& self); |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 55 | void scheduleTimer(Milliseconds interval); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 56 | uint64_t deduceAppendLimit(const uint64_t appendLimitIn) const; |
| 57 | uint64_t deduceBufferSize(const ReportUpdates reportUpdatesIn, |
| 58 | const ReportingType reportingTypeIn) const; |
| 59 | void setReportUpdates(const ReportUpdates newReportUpdates); |
| 60 | static uint64_t getSensorCount( |
| 61 | std::vector<std::shared_ptr<interfaces::Metric>>& metrics); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 62 | |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 63 | std::string name; |
| 64 | std::string path; |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 65 | ReportingType reportingType; |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 66 | Milliseconds interval; |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame^] | 67 | std::vector<ReportAction> reportActions; |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 68 | ReadingParametersPastVersion readingParametersPastVersion; |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 69 | ReadingParameters readingParameters; |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 70 | bool persistency = false; |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 71 | uint64_t sensorCount; |
| 72 | uint64_t appendLimit; |
| 73 | ReportUpdates reportUpdates; |
| 74 | CircularVector<ReadingData> readingsBuffer; |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 75 | Readings readings = {}; |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 76 | std::shared_ptr<sdbusplus::asio::object_server> objServer; |
| 77 | std::unique_ptr<sdbusplus::asio::dbus_interface> reportIface; |
| 78 | std::unique_ptr<sdbusplus::asio::dbus_interface> deleteIface; |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 79 | std::vector<std::shared_ptr<interfaces::Metric>> metrics; |
| 80 | boost::asio::steady_timer timer; |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 81 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 82 | interfaces::JsonStorage::FilePath fileName; |
| 83 | interfaces::JsonStorage& reportStorage; |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 84 | bool enabled; |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 85 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 86 | public: |
| 87 | static constexpr const char* reportIfaceName = |
| 88 | "xyz.openbmc_project.Telemetry.Report"; |
| 89 | static constexpr const char* reportDir = |
| 90 | "/xyz/openbmc_project/Telemetry/Reports/"; |
| 91 | static constexpr const char* deleteIfaceName = |
| 92 | "xyz.openbmc_project.Object.Delete"; |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame^] | 93 | static constexpr size_t reportVersion = 6; |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 94 | }; |