Fixed handling maxAppendLimit
maxLimit prevented using numeric_limits<uint64_t>::max as a way to let
telemetry service deduce appendLimit. This commit fixes constrain to
allow passing this special value.
Tested:
- Added new unit tests that confirm numeric_limits<uint64_t>::max is
correctly handled in telemetry service
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
Change-Id: I5d67e83475cdfcbb58a71b783ac9eef1e5ad7010
diff --git a/src/report.cpp b/src/report.cpp
index 2b7134a..8acf182 100644
--- a/src/report.cpp
+++ b/src/report.cpp
@@ -89,11 +89,12 @@
return sensorCount;
}
-uint64_t Report::deduceAppendLimit(const uint64_t appendLimitIn) const
+std::optional<uint64_t>
+ Report::deduceAppendLimit(const uint64_t appendLimitIn) const
{
if (appendLimitIn == std::numeric_limits<uint64_t>::max())
{
- return sensorCount;
+ return std::nullopt;
}
else
{
@@ -111,7 +112,7 @@
}
else
{
- return appendLimit;
+ return appendLimit.value_or(sensorCount);
}
}
@@ -243,9 +244,10 @@
return utils::enumToString(reportAction);
});
});
- dbusIface->register_property_r("AppendLimit", appendLimit,
- sdbusplus::vtable::property_::emits_change,
- [this](const auto&) { return appendLimit; });
+ dbusIface->register_property_r(
+ "AppendLimit", appendLimit.value_or(sensorCount),
+ sdbusplus::vtable::property_::emits_change,
+ [this](const auto&) { return appendLimit.value_or(sensorCount); });
dbusIface->register_property_rw(
"ReportUpdates", std::string(),
sdbusplus::vtable::property_::emits_change,
@@ -340,7 +342,8 @@
return utils::toUnderlying(reportAction);
});
data["Interval"] = interval.count();
- data["AppendLimit"] = appendLimit;
+ data["AppendLimit"] =
+ appendLimit.value_or(std::numeric_limits<uint64_t>::max());
data["ReportUpdates"] = utils::toUnderlying(reportUpdates);
data["ReadingParameters"] =
utils::transform(metrics, [](const auto& metric) {
diff --git a/src/report.hpp b/src/report.hpp
index 880ede7..98097ae 100644
--- a/src/report.hpp
+++ b/src/report.hpp
@@ -54,7 +54,8 @@
std::unique_ptr<sdbusplus::asio::dbus_interface> makeReportInterface();
static void timerProc(boost::system::error_code, Report& self);
void scheduleTimer(Milliseconds interval);
- uint64_t deduceAppendLimit(const uint64_t appendLimitIn) const;
+ std::optional<uint64_t>
+ deduceAppendLimit(const uint64_t appendLimitIn) const;
uint64_t deduceBufferSize(const ReportUpdates reportUpdatesIn,
const ReportingType reportingTypeIn) const;
void setReportUpdates(const ReportUpdates newReportUpdates);
@@ -71,7 +72,7 @@
ReadingParameters readingParameters;
bool persistency = false;
uint64_t sensorCount;
- uint64_t appendLimit;
+ std::optional<uint64_t> appendLimit;
ReportUpdates reportUpdates;
CircularVector<ReadingData> readingsBuffer;
Readings readings = {};
diff --git a/src/report_manager.cpp b/src/report_manager.cpp
index 8687316..f5dc105 100644
--- a/src/report_manager.cpp
+++ b/src/report_manager.cpp
@@ -144,7 +144,8 @@
"Reached maximal report count");
}
- if (appendLimit > maxAppendLimit)
+ if (appendLimit > maxAppendLimit &&
+ appendLimit != std::numeric_limits<uint64_t>::max())
{
throw sdbusplus::exception::SdBusError(
static_cast<int>(std::errc::invalid_argument),