diff --git a/src/app/codegen-interaction-model/Model.cpp b/src/app/codegen-interaction-model/Model.cpp index ee205d50413214..dc3fbd9cbca7d0 100644 --- a/src/app/codegen-interaction-model/Model.cpp +++ b/src/app/codegen-interaction-model/Model.cpp @@ -110,13 +110,13 @@ InteractionModel::AttributeEntry AttributeEntryFrom(const ConcreteClusterPath & } // namespace CHIP_ERROR Model::ReadAttribute(const InteractionModel::ReadAttributeRequest & request, InteractionModel::ReadState & state, - chip::TLV::TLVWriter & attribute_data) + AttributeValueEncoder & encoder) { // TODO: this needs an implementation return CHIP_ERROR_NOT_IMPLEMENTED; } -CHIP_ERROR Model::WriteAttribute(const InteractionModel::WriteAttributeRequest & request, chip::TLV::TLVReader & attribute_data) +CHIP_ERROR Model::WriteAttribute(const InteractionModel::WriteAttributeRequest & request, AttributeValueDecoder & decoder) { // TODO: this needs an implementation return CHIP_ERROR_NOT_IMPLEMENTED; @@ -198,15 +198,15 @@ InteractionModel::ClusterEntry Model::NextCluster(const ConcreteClusterPath & be return InteractionModel::ClusterEntry::Invalid(); } -Optional Model::GetClusterInfo(const ConcreteClusterPath & path) +std::optional Model::GetClusterInfo(const ConcreteClusterPath & path) { const EmberAfCluster * cluster = emberAfFindServerCluster(path.mEndpointId, path.mClusterId); - VerifyOrReturnValue(cluster != nullptr, Optional::Missing()); + VerifyOrReturnValue(cluster != nullptr, std::nullopt); InteractionModel::ClusterInfo info; LoadClusterInfo(path, *cluster, &info); - return MakeOptional(info); + return std::make_optional(info); } InteractionModel::AttributeEntry Model::FirstAttribute(const ConcreteClusterPath & path) @@ -242,12 +242,12 @@ InteractionModel::AttributeEntry Model::NextAttribute(const ConcreteAttributePat return InteractionModel::AttributeEntry::Invalid(); } -Optional Model::GetAttributeInfo(const ConcreteAttributePath & path) +std::optional Model::GetAttributeInfo(const ConcreteAttributePath & path) { const EmberAfCluster * cluster = emberAfFindServerCluster(path.mEndpointId, path.mClusterId); - VerifyOrReturnValue(cluster != nullptr, Optional::Missing()); - VerifyOrReturnValue(cluster->attributeCount > 0, Optional::Missing()); - VerifyOrReturnValue(cluster->attributes != nullptr, Optional::Missing()); + VerifyOrReturnValue(cluster != nullptr, std::nullopt); + VerifyOrReturnValue(cluster->attributeCount > 0, std::nullopt); + VerifyOrReturnValue(cluster->attributes != nullptr, std::nullopt); const unsigned attributeCount = cluster->attributeCount; for (unsigned i = 0; i < attributeCount; i++) { @@ -255,11 +255,11 @@ Optional Model::GetAttributeInfo(const Concrete { InteractionModel::AttributeInfo info; LoadAttributeInfo(path, cluster->attributes[i], &info); - return MakeOptional(info); + return std::make_optional(info); } } - return Optional::Missing(); + return std::nullopt; } } // namespace CodegenDataModel diff --git a/src/app/codegen-interaction-model/Model.h b/src/app/codegen-interaction-model/Model.h index 83e08f8b91e8ec..3f48970852a7bc 100644 --- a/src/app/codegen-interaction-model/Model.h +++ b/src/app/codegen-interaction-model/Model.h @@ -29,9 +29,8 @@ class Model : public chip::app::InteractionModel::Model CHIP_ERROR Shutdown() override { return CHIP_NO_ERROR; } CHIP_ERROR ReadAttribute(const InteractionModel::ReadAttributeRequest & request, InteractionModel::ReadState & state, - chip::TLV::TLVWriter & attribute_data) override; - CHIP_ERROR WriteAttribute(const InteractionModel::WriteAttributeRequest & request, - chip::TLV::TLVReader & attribute_data) override; + AttributeValueEncoder & encoder) override; + CHIP_ERROR WriteAttribute(const InteractionModel::WriteAttributeRequest & request, AttributeValueDecoder & decoder) override; CHIP_ERROR Invoke(const InteractionModel::InvokeRequest & request, chip::TLV::TLVReader & input_arguments, InteractionModel::InvokeReply & reply) override; @@ -41,11 +40,11 @@ class Model : public chip::app::InteractionModel::Model InteractionModel::ClusterEntry FirstCluster(EndpointId endpoint) override; InteractionModel::ClusterEntry NextCluster(const ConcreteClusterPath & before) override; - Optional GetClusterInfo(const ConcreteClusterPath & path) override; + std::optional GetClusterInfo(const ConcreteClusterPath & path) override; InteractionModel::AttributeEntry FirstAttribute(const ConcreteClusterPath & cluster) override; InteractionModel::AttributeEntry NextAttribute(const ConcreteAttributePath & before) override; - Optional GetAttributeInfo(const ConcreteAttributePath & path) override; + std::optional GetAttributeInfo(const ConcreteAttributePath & path) override; }; } // namespace CodegenDataModel diff --git a/src/app/codegen-interaction-model/tests/TestCodegenModelViaMocks.cpp b/src/app/codegen-interaction-model/tests/TestCodegenModelViaMocks.cpp index 2d4041ff127d16..fc34b566963df2 100644 --- a/src/app/codegen-interaction-model/tests/TestCodegenModelViaMocks.cpp +++ b/src/app/codegen-interaction-model/tests/TestCodegenModelViaMocks.cpp @@ -180,22 +180,22 @@ TEST(TestCodegenModelViaMocks, GetCluterInfo) chip::Test::ResetVersion(); - ASSERT_FALSE(model.GetClusterInfo(ConcreteClusterPath(kInvalidEndpointId, kInvalidClusterId)).HasValue()); - ASSERT_FALSE(model.GetClusterInfo(ConcreteClusterPath(kInvalidEndpointId, MockClusterId(1))).HasValue()); - ASSERT_FALSE(model.GetClusterInfo(ConcreteClusterPath(kMockEndpoint1, kInvalidClusterId)).HasValue()); - ASSERT_FALSE(model.GetClusterInfo(ConcreteClusterPath(kMockEndpoint1, MockClusterId(10))).HasValue()); + ASSERT_FALSE(model.GetClusterInfo(ConcreteClusterPath(kInvalidEndpointId, kInvalidClusterId)).has_value()); + ASSERT_FALSE(model.GetClusterInfo(ConcreteClusterPath(kInvalidEndpointId, MockClusterId(1))).has_value()); + ASSERT_FALSE(model.GetClusterInfo(ConcreteClusterPath(kMockEndpoint1, kInvalidClusterId)).has_value()); + ASSERT_FALSE(model.GetClusterInfo(ConcreteClusterPath(kMockEndpoint1, MockClusterId(10))).has_value()); // now get the value - Optional info = model.GetClusterInfo(ConcreteClusterPath(kMockEndpoint1, MockClusterId(1))); - ASSERT_TRUE(info.HasValue()); - ASSERT_EQ(info.Value().dataVersion, 0u); - ASSERT_EQ(info.Value().flags.Raw(), 0u); + std::optional info = model.GetClusterInfo(ConcreteClusterPath(kMockEndpoint1, MockClusterId(1))); + ASSERT_TRUE(info.has_value()); + EXPECT_EQ(info->dataVersion, 0u); + EXPECT_EQ(info->flags.Raw(), 0u); chip::Test::BumpVersion(); info = model.GetClusterInfo(ConcreteClusterPath(kMockEndpoint1, MockClusterId(1))); - ASSERT_TRUE(info.HasValue()); - ASSERT_EQ(info.Value().dataVersion, 1u); - ASSERT_EQ(info.Value().flags.Raw(), 0u); + ASSERT_TRUE(info.has_value()); + EXPECT_EQ(info->dataVersion, 1u); + EXPECT_EQ(info->flags.Raw(), 0u); } TEST(TestCodegenModelViaMocks, IterateOverAttributes) @@ -270,20 +270,21 @@ TEST(TestCodegenModelViaMocks, GetAttributeInfo) // various non-existent or invalid paths should return no info data ASSERT_FALSE( - model.GetAttributeInfo(ConcreteAttributePath(kInvalidEndpointId, kInvalidClusterId, kInvalidAttributeId)).HasValue()); - ASSERT_FALSE(model.GetAttributeInfo(ConcreteAttributePath(kInvalidEndpointId, kInvalidClusterId, FeatureMap::Id)).HasValue()); - ASSERT_FALSE(model.GetAttributeInfo(ConcreteAttributePath(kInvalidEndpointId, MockClusterId(1), FeatureMap::Id)).HasValue()); - ASSERT_FALSE(model.GetAttributeInfo(ConcreteAttributePath(kMockEndpoint1, kInvalidClusterId, FeatureMap::Id)).HasValue()); - ASSERT_FALSE(model.GetAttributeInfo(ConcreteAttributePath(kMockEndpoint1, MockClusterId(10), FeatureMap::Id)).HasValue()); - ASSERT_FALSE(model.GetAttributeInfo(ConcreteAttributePath(kMockEndpoint1, MockClusterId(10), kInvalidAttributeId)).HasValue()); - ASSERT_FALSE(model.GetAttributeInfo(ConcreteAttributePath(kMockEndpoint1, MockClusterId(1), MockAttributeId(10))).HasValue()); + model.GetAttributeInfo(ConcreteAttributePath(kInvalidEndpointId, kInvalidClusterId, kInvalidAttributeId)).has_value()); + ASSERT_FALSE(model.GetAttributeInfo(ConcreteAttributePath(kInvalidEndpointId, kInvalidClusterId, FeatureMap::Id)).has_value()); + ASSERT_FALSE(model.GetAttributeInfo(ConcreteAttributePath(kInvalidEndpointId, MockClusterId(1), FeatureMap::Id)).has_value()); + ASSERT_FALSE(model.GetAttributeInfo(ConcreteAttributePath(kMockEndpoint1, kInvalidClusterId, FeatureMap::Id)).has_value()); + ASSERT_FALSE(model.GetAttributeInfo(ConcreteAttributePath(kMockEndpoint1, MockClusterId(10), FeatureMap::Id)).has_value()); + ASSERT_FALSE(model.GetAttributeInfo(ConcreteAttributePath(kMockEndpoint1, MockClusterId(10), kInvalidAttributeId)).has_value()); + ASSERT_FALSE(model.GetAttributeInfo(ConcreteAttributePath(kMockEndpoint1, MockClusterId(1), MockAttributeId(10))).has_value()); // valid info - Optional info = model.GetAttributeInfo(ConcreteAttributePath(kMockEndpoint1, MockClusterId(1), FeatureMap::Id)); - ASSERT_TRUE(info.HasValue()); - ASSERT_FALSE(info.Value().flags.Has(AttributeQualityFlags::kListAttribute)); + std::optional info = + model.GetAttributeInfo(ConcreteAttributePath(kMockEndpoint1, MockClusterId(1), FeatureMap::Id)); + ASSERT_TRUE(info.has_value()); + ASSERT_FALSE(info->flags.Has(AttributeQualityFlags::kListAttribute)); info = model.GetAttributeInfo(ConcreteAttributePath(kMockEndpoint2, MockClusterId(2), MockAttributeId(2))); - ASSERT_TRUE(info.HasValue()); - ASSERT_TRUE(info.Value().flags.Has(AttributeQualityFlags::kListAttribute)); + ASSERT_TRUE(info.has_value()); + ASSERT_TRUE(info->flags.Has(AttributeQualityFlags::kListAttribute)); }