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