Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix post-review comments on Q quality utils from #34266 #34416

Merged
merged 4 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/app/cluster-building-blocks/QuieterReporting.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ class QuieterReportingAttribute
* @return AttributeDirtyState::kMustReport if attribute must be marked dirty right away, or
* AttributeDirtyState::kNoReportNeeded otherwise.
*/
AttributeDirtyState SetValue(const chip::app::DataModel::Nullable<T> & newValue, Timestamp now,
SufficientChangePredicate changedPredicate)
AttributeDirtyState SetValue(const DataModel::Nullable<T> & newValue, Timestamp now, SufficientChangePredicate changedPredicate)
{
bool isChangeOfNull = newValue.IsNull() ^ mValue.IsNull();
bool areBothValuesNonNull = !newValue.IsNull() && !mValue.IsNull();
bool isChangeOfNull = newValue.IsNull() != mValue.IsNull();
bool areBothValuesNonNull = !newValue.IsNull() && !mValue.IsNull();
bool areBothValuesDifferent = areBothValuesNonNull && (newValue.Value() != mValue.Value());
tcarmelveilleux marked this conversation as resolved.
Show resolved Hide resolved

bool changeToFromZero = areBothValuesNonNull && (newValue.Value() == 0 || mValue.Value() == 0);
bool changeToFromZero = areBothValuesNonNull && areBothValuesDifferent && (newValue.Value() == 0 || mValue.Value() == 0);
bool isIncrement = areBothValuesNonNull && (newValue.Value() > mValue.Value());
bool isDecrement = areBothValuesNonNull && (newValue.Value() < mValue.Value());

Expand Down Expand Up @@ -217,20 +217,20 @@ class QuieterReportingAttribute
* @return AttributeDirtyState::kMustReport if attribute must be marked dirty right away, or
* AttributeDirtyState::kNoReportNeeded otherwise.
*/
AttributeDirtyState SetValue(const chip::app::DataModel::Nullable<T> & newValue, Timestamp now)
AttributeDirtyState SetValue(const DataModel::Nullable<T> & newValue, Timestamp now)
{
return SetValue(newValue, now, [](const SufficientChangePredicateCandidate &) -> bool { return false; });
}

protected:
// Current value of the attribute.
chip::app::DataModel::Nullable<T> mValue;
DataModel::Nullable<T> mValue;
// Last value that was marked as dirty (to use in comparisons for change, e.g. by SufficientChangePredicate).
chip::app::DataModel::Nullable<T> mLastDirtyValue;
DataModel::Nullable<T> mLastDirtyValue;
// Enabled internal change detection policies.
QuieterReportingPolicyFlags mPolicyFlags{ 0 };
// Timestamp associated with the last time the attribute was marked dirty (to use in comparisons for change).
chip::System::Clock::Milliseconds64 mLastDirtyTimestampMillis{};
chip::System::Clock::Timestamp mLastDirtyTimestampMillis{};
};

} // namespace detail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ TEST(TestQuieterReporting, ChangeToFromZeroPolicyWorks)
EXPECT_EQ(attribute.SetValue(0, now), AttributeDirtyState::kMustReport);
EXPECT_EQ(attribute.value().ValueOr(INT_MAX), 0);

// 0 --> 0, expect NOT marked dirty.
EXPECT_EQ(attribute.SetValue(0, now), AttributeDirtyState::kNoReportNeeded);
EXPECT_EQ(attribute.value().ValueOr(INT_MAX), 0);

// 0 --> 11, expect marked dirty.
EXPECT_EQ(attribute.SetValue(11, now), AttributeDirtyState::kMustReport);
EXPECT_EQ(attribute.value().ValueOr(INT_MAX), 11);
Expand Down
Loading