Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 1 | #include "report.hpp" |
| 2 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 3 | #include "messages/collect_trigger_id.hpp" |
| 4 | #include "messages/trigger_presence_changed_ind.hpp" |
| 5 | #include "messages/update_report_ind.hpp" |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 6 | #include "report_manager.hpp" |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 7 | #include "utils/clock.hpp" |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 8 | #include "utils/contains.hpp" |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 9 | #include "utils/ensure.hpp" |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 10 | #include "utils/transform.hpp" |
| 11 | |
| 12 | #include <phosphor-logging/log.hpp> |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 13 | #include <sdbusplus/vtable.hpp> |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 14 | |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 15 | #include <limits> |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 16 | #include <numeric> |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 17 | #include <optional> |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 18 | |
| 19 | Report::Report(boost::asio::io_context& ioc, |
| 20 | const std::shared_ptr<sdbusplus::asio::object_server>& objServer, |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 21 | const std::string& reportId, const std::string& reportName, |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 22 | const ReportingType reportingTypeIn, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 23 | std::vector<ReportAction> reportActionsIn, |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 24 | const Milliseconds intervalIn, const uint64_t appendLimitIn, |
| 25 | const ReportUpdates reportUpdatesIn, |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 26 | interfaces::ReportManager& reportManager, |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 27 | interfaces::JsonStorage& reportStorageIn, |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 28 | std::vector<std::shared_ptr<interfaces::Metric>> metricsIn, |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 29 | const interfaces::ReportFactory& reportFactory, |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 30 | const bool enabledIn, std::unique_ptr<interfaces::Clock> clock, |
| 31 | Readings readingsIn) : |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 32 | id(reportId), |
| 33 | name(reportName), reportingType(reportingTypeIn), interval(intervalIn), |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 34 | reportActions(reportActionsIn.begin(), reportActionsIn.end()), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 35 | sensorCount(getSensorCount(metricsIn)), |
| 36 | appendLimit(deduceAppendLimit(appendLimitIn)), |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 37 | reportUpdates(reportUpdatesIn), readings(std::move(readingsIn)), |
| 38 | readingsBuffer(std::get<1>(readings), |
| 39 | deduceBufferSize(reportUpdates, reportingType)), |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 40 | objServer(objServer), metrics(std::move(metricsIn)), timer(ioc), |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 41 | triggerIds(collectTriggerIds(ioc)), reportStorage(reportStorageIn), |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 42 | clock(std::move(clock)), messanger(ioc) |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 43 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 44 | readingParameters = |
| 45 | toReadingParameters(utils::transform(metrics, [](const auto& metric) { |
| 46 | return metric->dumpConfiguration(); |
| 47 | })); |
| 48 | |
| 49 | readingParametersPastVersion = |
| 50 | utils::transform(readingParameters, [](const auto& item) { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 51 | const auto& [sensorData, operationType, id, collectionTimeScope, |
| 52 | collectionDuration] = item; |
| 53 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 54 | return ReadingParametersPastVersion::value_type( |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 55 | std::get<0>(sensorData.front()), operationType, id, |
| 56 | std::get<1>(sensorData.front())); |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 57 | }); |
| 58 | |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 59 | reportActions.insert(ReportAction::logToMetricReportsCollection); |
| 60 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 61 | deleteIface = objServer->add_unique_interface( |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 62 | getPath(), deleteIfaceName, |
| 63 | [this, &ioc, &reportManager](auto& dbusIface) { |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 64 | dbusIface.register_method("Delete", [this, &ioc, &reportManager] { |
| 65 | if (persistency) |
| 66 | { |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 67 | persistency = false; |
| 68 | |
| 69 | reportIface->signal_property("Persistency"); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 70 | } |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 71 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 72 | boost::asio::post(ioc, [this, &reportManager] { |
| 73 | reportManager.removeReport(this); |
| 74 | }); |
| 75 | }); |
| 76 | }); |
| 77 | |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 78 | errorMessages = verify(); |
| 79 | state.set<ReportFlags::enabled, ReportFlags::valid>(enabledIn, |
| 80 | errorMessages.empty()); |
| 81 | |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 82 | reportIface = makeReportInterface(reportFactory); |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 83 | persistency = storeConfiguration(); |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 84 | |
| 85 | messanger.on_receive<messages::TriggerPresenceChangedInd>( |
| 86 | [this](const auto& msg) { |
| 87 | const auto oldSize = triggerIds.size(); |
| 88 | |
| 89 | if (msg.presence == messages::Presence::Exist) |
| 90 | { |
| 91 | if (utils::contains(msg.reportIds, id)) |
| 92 | { |
| 93 | triggerIds.insert(msg.triggerId); |
| 94 | } |
| 95 | else if (!utils::contains(msg.reportIds, id)) |
| 96 | { |
| 97 | triggerIds.erase(msg.triggerId); |
| 98 | } |
| 99 | } |
| 100 | else if (msg.presence == messages::Presence::Removed) |
| 101 | { |
| 102 | triggerIds.erase(msg.triggerId); |
| 103 | } |
| 104 | |
| 105 | if (triggerIds.size() != oldSize) |
| 106 | { |
| 107 | reportIface->signal_property("TriggerIds"); |
| 108 | } |
| 109 | }); |
| 110 | |
| 111 | messanger.on_receive<messages::UpdateReportInd>([this](const auto& msg) { |
| 112 | if (utils::contains(msg.reportIds, id)) |
| 113 | { |
| 114 | updateReadings(); |
| 115 | } |
| 116 | }); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 117 | } |
| 118 | |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 119 | Report::~Report() |
| 120 | { |
| 121 | if (persistency) |
| 122 | { |
| 123 | if (shouldStoreMetricValues()) |
| 124 | { |
| 125 | storeConfiguration(); |
| 126 | } |
| 127 | } |
| 128 | else |
| 129 | { |
| 130 | reportStorage.remove(reportFileName()); |
| 131 | } |
| 132 | } |
| 133 | |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 134 | void Report::activate() |
| 135 | { |
| 136 | for (auto& metric : this->metrics) |
| 137 | { |
| 138 | metric->initialize(); |
| 139 | } |
| 140 | |
| 141 | scheduleTimer(); |
| 142 | |
| 143 | if (reportIface) |
| 144 | { |
| 145 | reportIface->signal_property("errors"); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | void Report::deactivate() |
| 150 | { |
| 151 | for (auto& metric : metrics) |
| 152 | { |
| 153 | metric->deinitialize(); |
| 154 | } |
| 155 | |
| 156 | unregisterFromMetrics = nullptr; |
| 157 | timer.cancel(); |
| 158 | |
| 159 | if (reportIface) |
| 160 | { |
| 161 | reportIface->signal_property("Errors"); |
| 162 | } |
| 163 | } |
| 164 | |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 165 | uint64_t Report::getSensorCount( |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 166 | const std::vector<std::shared_ptr<interfaces::Metric>>& metrics) |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 167 | { |
| 168 | uint64_t sensorCount = 0; |
| 169 | for (auto& metric : metrics) |
| 170 | { |
| 171 | sensorCount += metric->sensorCount(); |
| 172 | } |
| 173 | return sensorCount; |
| 174 | } |
| 175 | |
Krzysztof Grobelny | e6c417c | 2022-02-02 17:25:53 +0100 | [diff] [blame] | 176 | std::optional<uint64_t> |
| 177 | Report::deduceAppendLimit(const uint64_t appendLimitIn) const |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 178 | { |
| 179 | if (appendLimitIn == std::numeric_limits<uint64_t>::max()) |
| 180 | { |
Krzysztof Grobelny | e6c417c | 2022-02-02 17:25:53 +0100 | [diff] [blame] | 181 | return std::nullopt; |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 182 | } |
| 183 | else |
| 184 | { |
| 185 | return appendLimitIn; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | uint64_t Report::deduceBufferSize(const ReportUpdates reportUpdatesIn, |
| 190 | const ReportingType reportingTypeIn) const |
| 191 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 192 | if (reportUpdatesIn == ReportUpdates::overwrite || |
| 193 | reportingTypeIn == ReportingType::onRequest) |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 194 | { |
| 195 | return sensorCount; |
| 196 | } |
| 197 | else |
| 198 | { |
Krzysztof Grobelny | e6c417c | 2022-02-02 17:25:53 +0100 | [diff] [blame] | 199 | return appendLimit.value_or(sensorCount); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 203 | void Report::setReadingBuffer(const ReportUpdates newReportUpdates) |
| 204 | { |
| 205 | if (reportingType != ReportingType::onRequest && |
| 206 | (reportUpdates == ReportUpdates::overwrite || |
| 207 | newReportUpdates == ReportUpdates::overwrite)) |
| 208 | { |
| 209 | readingsBuffer.clearAndResize( |
| 210 | deduceBufferSize(newReportUpdates, reportingType)); |
| 211 | } |
| 212 | } |
| 213 | |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 214 | void Report::setReportUpdates(const ReportUpdates newReportUpdates) |
| 215 | { |
| 216 | if (reportUpdates != newReportUpdates) |
| 217 | { |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 218 | setReadingBuffer(newReportUpdates); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 219 | reportUpdates = newReportUpdates; |
| 220 | } |
| 221 | } |
| 222 | |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 223 | std::unique_ptr<sdbusplus::asio::dbus_interface> |
| 224 | Report::makeReportInterface(const interfaces::ReportFactory& reportFactory) |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 225 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 226 | auto dbusIface = |
| 227 | objServer->add_unique_interface(getPath(), reportIfaceName); |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 228 | dbusIface->register_property_rw<bool>( |
| 229 | "Enabled", sdbusplus::vtable::property_::emits_change, |
| 230 | [this](bool newVal, auto& oldValue) { |
| 231 | if (newVal != state.get<ReportFlags::enabled>()) |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 232 | { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 233 | state.set<ReportFlags::enabled>(oldValue = newVal); |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 234 | |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 235 | persistency = storeConfiguration(); |
| 236 | } |
Szymon Dompke | 3e2cc9d | 2021-12-14 12:00:52 +0100 | [diff] [blame] | 237 | return 1; |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 238 | }, |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 239 | [this](const auto&) { return state.get<ReportFlags::enabled>(); }); |
| 240 | dbusIface->register_property_r< |
| 241 | std::vector<std::tuple<std::string, std::string>>>( |
| 242 | "ErrorMessages", sdbusplus::vtable::property_::emits_change, |
| 243 | [this](const auto&) { |
| 244 | return utils::transform(errorMessages, [](const auto& em) { |
| 245 | return std::tuple<std::string, std::string>( |
| 246 | utils::enumToString(em.error), em.arg0); |
| 247 | }); |
| 248 | }); |
| 249 | dbusIface->register_property_rw<uint64_t>( |
| 250 | "Interval", sdbusplus::vtable::property_::emits_change, |
| 251 | [this](uint64_t newVal, auto& oldVal) { |
| 252 | const Milliseconds newValT{newVal}; |
| 253 | if (newValT < ReportManager::minInterval && |
| 254 | newValT != Milliseconds{0}) |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 255 | { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 256 | throw sdbusplus::exception::SdBusError( |
| 257 | static_cast<int>(std::errc::invalid_argument), |
| 258 | "Invalid interval"); |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 259 | } |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 260 | |
| 261 | if (newValT != interval) |
| 262 | { |
| 263 | oldVal = newVal; |
| 264 | interval = newValT; |
| 265 | |
| 266 | errorMessages = verify(); |
| 267 | if (state.set<ReportFlags::valid>(errorMessages.empty()) == |
| 268 | StateEvent::active) |
| 269 | { |
| 270 | scheduleTimer(); |
| 271 | } |
| 272 | |
| 273 | persistency = storeConfiguration(); |
| 274 | } |
| 275 | return 1; |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 276 | }, |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 277 | [this](const auto&) { return interval.count(); }); |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 278 | dbusIface->register_property_rw<bool>( |
| 279 | "Persistency", sdbusplus::vtable::property_::emits_change, |
| 280 | [this](bool newVal, auto& oldVal) { |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 281 | if (newVal == persistency) |
| 282 | { |
Szymon Dompke | 3e2cc9d | 2021-12-14 12:00:52 +0100 | [diff] [blame] | 283 | return 1; |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 284 | } |
| 285 | if (newVal) |
| 286 | { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 287 | persistency = oldVal = storeConfiguration(); |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 288 | } |
| 289 | else |
| 290 | { |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 291 | reportStorage.remove(reportFileName()); |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 292 | persistency = oldVal = false; |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 293 | } |
Szymon Dompke | 3e2cc9d | 2021-12-14 12:00:52 +0100 | [diff] [blame] | 294 | return 1; |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 295 | }, |
| 296 | [this](const auto&) { return persistency; }); |
| 297 | |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 298 | dbusIface->register_property_r("Readings", readings, |
| 299 | sdbusplus::vtable::property_::emits_change, |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 300 | [this](const auto&) { return readings; }); |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 301 | dbusIface->register_property_rw<std::string>( |
| 302 | "ReportingType", sdbusplus::vtable::property_::emits_change, |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 303 | [this](auto newVal, auto& oldVal) { |
| 304 | ReportingType tmp = utils::toReportingType(newVal); |
| 305 | if (tmp != reportingType) |
| 306 | { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 307 | reportingType = tmp; |
| 308 | oldVal = std::move(newVal); |
| 309 | |
| 310 | errorMessages = verify(); |
| 311 | if (state.set<ReportFlags::valid>(errorMessages.empty()) == |
| 312 | StateEvent::active) |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 313 | { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 314 | scheduleTimer(); |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 315 | } |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 316 | |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 317 | persistency = storeConfiguration(); |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 318 | |
| 319 | setReadingBuffer(reportUpdates); |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 320 | } |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 321 | return 1; |
| 322 | }, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 323 | [this](const auto&) { return utils::enumToString(reportingType); }); |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 324 | dbusIface->register_property_r( |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 325 | "ReadingParameters", readingParametersPastVersion, |
| 326 | sdbusplus::vtable::property_::const_, |
| 327 | [this](const auto&) { return readingParametersPastVersion; }); |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 328 | dbusIface->register_property_rw( |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 329 | "ReadingParametersFutureVersion", readingParameters, |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 330 | sdbusplus::vtable::property_::emits_change, |
| 331 | [this, &reportFactory](auto newVal, auto& oldVal) { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 332 | reportFactory.updateMetrics( |
| 333 | metrics, state.get<ReportFlags::enabled>(), newVal); |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 334 | readingParameters = toReadingParameters( |
| 335 | utils::transform(metrics, [](const auto& metric) { |
| 336 | return metric->dumpConfiguration(); |
| 337 | })); |
| 338 | persistency = storeConfiguration(); |
| 339 | oldVal = std::move(newVal); |
| 340 | return 1; |
| 341 | }, |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 342 | [this](const auto&) { return readingParameters; }); |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 343 | dbusIface->register_property_r<bool>( |
| 344 | "EmitsReadingsUpdate", sdbusplus::vtable::property_::none, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 345 | [this](const auto&) { |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 346 | return reportActions.contains(ReportAction::emitsReadingsUpdate); |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 347 | }); |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 348 | dbusIface->register_property_r<std::string>( |
| 349 | "Name", sdbusplus::vtable::property_::const_, |
| 350 | [this](const auto&) { return name; }); |
| 351 | dbusIface->register_property_r<bool>( |
| 352 | "LogToMetricReportsCollection", sdbusplus::vtable::property_::const_, |
| 353 | [this](const auto&) { |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 354 | return reportActions.contains( |
| 355 | ReportAction::logToMetricReportsCollection); |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 356 | }); |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 357 | dbusIface->register_property_rw<std::vector<std::string>>( |
| 358 | "ReportActions", sdbusplus::vtable::property_::emits_change, |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 359 | [this](auto newVal, auto& oldVal) { |
| 360 | auto tmp = utils::transform<std::unordered_set>( |
| 361 | newVal, [](const auto& reportAction) { |
| 362 | return utils::toReportAction(reportAction); |
| 363 | }); |
| 364 | tmp.insert(ReportAction::logToMetricReportsCollection); |
| 365 | |
| 366 | if (tmp != reportActions) |
| 367 | { |
| 368 | reportActions = tmp; |
| 369 | persistency = storeConfiguration(); |
| 370 | oldVal = std::move(newVal); |
| 371 | } |
| 372 | return 1; |
| 373 | }, |
| 374 | [this](const auto&) { |
| 375 | return utils::transform<std::vector>( |
| 376 | reportActions, [](const auto reportAction) { |
| 377 | return utils::enumToString(reportAction); |
| 378 | }); |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 379 | }); |
Krzysztof Grobelny | e6c417c | 2022-02-02 17:25:53 +0100 | [diff] [blame] | 380 | dbusIface->register_property_r( |
| 381 | "AppendLimit", appendLimit.value_or(sensorCount), |
| 382 | sdbusplus::vtable::property_::emits_change, |
| 383 | [this](const auto&) { return appendLimit.value_or(sensorCount); }); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 384 | dbusIface->register_property_rw( |
| 385 | "ReportUpdates", std::string(), |
| 386 | sdbusplus::vtable::property_::emits_change, |
| 387 | [this](auto newVal, auto& oldVal) { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 388 | setReportUpdates(utils::toReportUpdates(newVal)); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 389 | oldVal = newVal; |
Szymon Dompke | 3e2cc9d | 2021-12-14 12:00:52 +0100 | [diff] [blame] | 390 | return 1; |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 391 | }, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 392 | [this](const auto&) { return utils::enumToString(reportUpdates); }); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 393 | dbusIface->register_property_r( |
| 394 | "TriggerIds", std::vector<std::string>{}, |
| 395 | sdbusplus::vtable::property_::emits_change, [this](const auto&) { |
| 396 | return std::vector<std::string>(triggerIds.begin(), |
| 397 | triggerIds.end()); |
| 398 | }); |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 399 | dbusIface->register_method("Update", [this] { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 400 | if (reportingType == ReportingType::onRequest) |
Krzysztof Grobelny | 85db8bd | 2021-05-28 12:13:23 +0000 | [diff] [blame] | 401 | { |
| 402 | updateReadings(); |
| 403 | } |
| 404 | }); |
| 405 | constexpr bool skipPropertiesChangedSignal = true; |
| 406 | dbusIface->initialize(skipPropertiesChangedSignal); |
| 407 | return dbusIface; |
| 408 | } |
| 409 | |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 410 | void Report::timerProcForPeriodicReport(boost::system::error_code ec, |
| 411 | Report& self) |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 412 | { |
| 413 | if (ec) |
| 414 | { |
| 415 | return; |
| 416 | } |
| 417 | |
| 418 | self.updateReadings(); |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 419 | self.scheduleTimerForPeriodicReport(self.interval); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 420 | } |
| 421 | |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 422 | void Report::timerProcForOnChangeReport(boost::system::error_code ec, |
| 423 | Report& self) |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 424 | { |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 425 | if (ec) |
| 426 | { |
| 427 | return; |
| 428 | } |
| 429 | |
| 430 | const auto ensure = |
| 431 | utils::Ensure{[&self] { self.onChangeContext = std::nullopt; }}; |
| 432 | |
| 433 | self.onChangeContext.emplace(self); |
| 434 | |
| 435 | const auto steadyTimestamp = self.clock->steadyTimestamp(); |
| 436 | |
| 437 | for (auto& metric : self.metrics) |
| 438 | { |
| 439 | metric->updateReadings(steadyTimestamp); |
| 440 | } |
| 441 | |
| 442 | self.scheduleTimerForOnChangeReport(); |
| 443 | } |
| 444 | |
| 445 | void Report::scheduleTimerForPeriodicReport(Milliseconds timerInterval) |
| 446 | { |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 447 | timer.expires_after(timerInterval); |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 448 | timer.async_wait([this](boost::system::error_code ec) { |
| 449 | timerProcForPeriodicReport(ec, *this); |
| 450 | }); |
| 451 | } |
| 452 | |
| 453 | void Report::scheduleTimerForOnChangeReport() |
| 454 | { |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 455 | constexpr Milliseconds timerInterval{100}; |
| 456 | |
| 457 | timer.expires_after(timerInterval); |
| 458 | timer.async_wait([this](boost::system::error_code ec) { |
| 459 | timerProcForOnChangeReport(ec, *this); |
| 460 | }); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | void Report::updateReadings() |
| 464 | { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 465 | if (!state.isActive()) |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 466 | { |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 467 | return; |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 468 | } |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 469 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 470 | if (reportUpdates == ReportUpdates::overwrite || |
| 471 | reportingType == ReportingType::onRequest) |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 472 | { |
| 473 | readingsBuffer.clear(); |
| 474 | } |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 475 | |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 476 | for (const auto& metric : metrics) |
| 477 | { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 478 | if (!state.isActive()) |
| 479 | { |
| 480 | break; |
| 481 | } |
| 482 | |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 483 | for (const auto& [id, metadata, value, timestamp] : |
Krzysztof Grobelny | 9e8da54 | 2022-02-17 10:40:16 +0100 | [diff] [blame] | 484 | metric->getUpdatedReadings()) |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 485 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 486 | if (reportUpdates == ReportUpdates::appendStopsWhenFull && |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 487 | readingsBuffer.isFull()) |
| 488 | { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 489 | state.set<ReportFlags::enabled>(false); |
| 490 | reportIface->signal_property("Enabled"); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 491 | break; |
| 492 | } |
| 493 | readingsBuffer.emplace(id, metadata, value, timestamp); |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 494 | } |
| 495 | } |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 496 | |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 497 | std::get<0>(readings) = |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 498 | std::chrono::duration_cast<Milliseconds>(clock->systemTimestamp()) |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 499 | .count(); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 500 | |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 501 | if (utils::contains(reportActions, ReportAction::emitsReadingsUpdate)) |
| 502 | { |
| 503 | reportIface->signal_property("Readings"); |
| 504 | } |
Wludzik, Jozef | cb88cfd | 2020-09-28 16:38:57 +0200 | [diff] [blame] | 505 | } |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 506 | |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 507 | bool Report::shouldStoreMetricValues() const |
| 508 | { |
| 509 | return reportingType != ReportingType::onRequest && |
| 510 | reportUpdates == ReportUpdates::appendStopsWhenFull; |
| 511 | } |
| 512 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 513 | bool Report::storeConfiguration() const |
| 514 | { |
| 515 | try |
| 516 | { |
| 517 | nlohmann::json data; |
| 518 | |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 519 | data["Enabled"] = state.get<ReportFlags::enabled>(); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 520 | data["Version"] = reportVersion; |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 521 | data["Id"] = id; |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 522 | data["Name"] = name; |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 523 | data["ReportingType"] = utils::toUnderlying(reportingType); |
| 524 | data["ReportActions"] = |
| 525 | utils::transform(reportActions, [](const auto reportAction) { |
| 526 | return utils::toUnderlying(reportAction); |
| 527 | }); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 528 | data["Interval"] = interval.count(); |
Krzysztof Grobelny | e6c417c | 2022-02-02 17:25:53 +0100 | [diff] [blame] | 529 | data["AppendLimit"] = |
| 530 | appendLimit.value_or(std::numeric_limits<uint64_t>::max()); |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 531 | data["ReportUpdates"] = utils::toUnderlying(reportUpdates); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 532 | data["ReadingParameters"] = |
| 533 | utils::transform(metrics, [](const auto& metric) { |
| 534 | return metric->dumpConfiguration(); |
| 535 | }); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 536 | |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 537 | if (shouldStoreMetricValues()) |
| 538 | { |
| 539 | data["MetricValues"] = utils::toLabeledReadings(readings); |
| 540 | } |
| 541 | |
| 542 | reportStorage.store(reportFileName(), data); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 543 | } |
| 544 | catch (const std::exception& e) |
| 545 | { |
| 546 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 547 | "Failed to store a report in storage", |
Wludzik, Jozef | 982c5b5 | 2021-01-02 12:05:21 +0100 | [diff] [blame] | 548 | phosphor::logging::entry("EXCEPTION_MSG=%s", e.what())); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 549 | return false; |
| 550 | } |
| 551 | |
| 552 | return true; |
| 553 | } |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 554 | |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 555 | interfaces::JsonStorage::FilePath Report::reportFileName() const |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 556 | { |
| 557 | return interfaces::JsonStorage::FilePath{ |
| 558 | std::to_string(std::hash<std::string>{}(id))}; |
| 559 | } |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 560 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 561 | std::unordered_set<std::string> |
| 562 | Report::collectTriggerIds(boost::asio::io_context& ioc) const |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 563 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 564 | utils::Messanger tmp(ioc); |
| 565 | |
| 566 | auto result = std::unordered_set<std::string>(); |
| 567 | |
| 568 | tmp.on_receive<messages::CollectTriggerIdResp>( |
| 569 | [&result](const auto& msg) { result.insert(msg.triggerId); }); |
| 570 | |
| 571 | tmp.send(messages::CollectTriggerIdReq{id}); |
| 572 | |
| 573 | return result; |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 574 | } |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 575 | |
| 576 | void Report::metricUpdated() |
| 577 | { |
| 578 | if (onChangeContext) |
| 579 | { |
| 580 | onChangeContext->metricUpdated(); |
| 581 | return; |
| 582 | } |
| 583 | |
| 584 | updateReadings(); |
| 585 | } |
| 586 | |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 587 | void Report::scheduleTimer() |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 588 | { |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 589 | switch (reportingType) |
| 590 | { |
| 591 | case ReportingType::periodic: |
| 592 | { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 593 | unregisterFromMetrics = nullptr; |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 594 | scheduleTimerForPeriodicReport(interval); |
| 595 | break; |
| 596 | } |
| 597 | case ReportingType::onChange: |
| 598 | { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 599 | if (!unregisterFromMetrics) |
| 600 | { |
| 601 | unregisterFromMetrics = [this] { |
| 602 | for (auto& metric : metrics) |
| 603 | { |
| 604 | metric->unregisterFromUpdates(*this); |
| 605 | } |
| 606 | }; |
| 607 | |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 608 | for (auto& metric : metrics) |
| 609 | { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 610 | metric->registerForUpdates(*this); |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 611 | } |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 612 | } |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 613 | |
| 614 | bool isTimerRequired = false; |
| 615 | |
| 616 | for (auto& metric : metrics) |
| 617 | { |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 618 | if (metric->isTimerRequired()) |
| 619 | { |
| 620 | isTimerRequired = true; |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | if (isTimerRequired) |
| 625 | { |
| 626 | scheduleTimerForOnChangeReport(); |
| 627 | } |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 628 | else |
| 629 | { |
| 630 | timer.cancel(); |
| 631 | } |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 632 | break; |
| 633 | } |
| 634 | default: |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 635 | unregisterFromMetrics = nullptr; |
| 636 | timer.cancel(); |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 637 | break; |
| 638 | } |
| 639 | } |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame^] | 640 | |
| 641 | std::vector<ErrorMessage> Report::verify() const |
| 642 | { |
| 643 | std::vector<ErrorMessage> result; |
| 644 | |
| 645 | if ((reportingType == ReportingType::periodic && |
| 646 | interval == Milliseconds{0}) || |
| 647 | (reportingType != ReportingType::periodic && |
| 648 | interval != Milliseconds{0})) |
| 649 | { |
| 650 | result.emplace_back(ErrorType::propertyConflict, "Interval"); |
| 651 | result.emplace_back(ErrorType::propertyConflict, "ReportingType"); |
| 652 | } |
| 653 | |
| 654 | return result; |
| 655 | } |