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