Skip to content

Commit

Permalink
Update to latest version - mainly std::optional update
Browse files Browse the repository at this point in the history
  • Loading branch information
andreilitvin committed May 7, 2024
1 parent 26c8f16 commit 5892a36
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
22 changes: 11 additions & 11 deletions src/app/codegen-interaction-model/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -198,15 +198,15 @@ InteractionModel::ClusterEntry Model::NextCluster(const ConcreteClusterPath & be
return InteractionModel::ClusterEntry::Invalid();
}

Optional<InteractionModel::ClusterInfo> Model::GetClusterInfo(const ConcreteClusterPath & path)
std::optional<InteractionModel::ClusterInfo> Model::GetClusterInfo(const ConcreteClusterPath & path)
{
const EmberAfCluster * cluster = emberAfFindServerCluster(path.mEndpointId, path.mClusterId);
VerifyOrReturnValue(cluster != nullptr, Optional<InteractionModel::ClusterInfo>::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)
Expand Down Expand Up @@ -242,24 +242,24 @@ InteractionModel::AttributeEntry Model::NextAttribute(const ConcreteAttributePat
return InteractionModel::AttributeEntry::Invalid();
}

Optional<InteractionModel::AttributeInfo> Model::GetAttributeInfo(const ConcreteAttributePath & path)
std::optional<InteractionModel::AttributeInfo> Model::GetAttributeInfo(const ConcreteAttributePath & path)
{
const EmberAfCluster * cluster = emberAfFindServerCluster(path.mEndpointId, path.mClusterId);
VerifyOrReturnValue(cluster != nullptr, Optional<InteractionModel::AttributeInfo>::Missing());
VerifyOrReturnValue(cluster->attributeCount > 0, Optional<InteractionModel::AttributeInfo>::Missing());
VerifyOrReturnValue(cluster->attributes != nullptr, Optional<InteractionModel::AttributeInfo>::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++)
{
if (cluster->attributes[i].attributeId == path.mAttributeId)
{
InteractionModel::AttributeInfo info;
LoadAttributeInfo(path, cluster->attributes[i], &info);
return MakeOptional(info);
return std::make_optional(info);
}
}

return Optional<InteractionModel::AttributeInfo>::Missing();
return std::nullopt;
}

} // namespace CodegenDataModel
Expand Down
9 changes: 4 additions & 5 deletions src/app/codegen-interaction-model/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<InteractionModel::ClusterInfo> GetClusterInfo(const ConcreteClusterPath & path) override;
std::optional<InteractionModel::ClusterInfo> GetClusterInfo(const ConcreteClusterPath & path) override;

InteractionModel::AttributeEntry FirstAttribute(const ConcreteClusterPath & cluster) override;
InteractionModel::AttributeEntry NextAttribute(const ConcreteAttributePath & before) override;
Optional<InteractionModel::AttributeInfo> GetAttributeInfo(const ConcreteAttributePath & path) override;
std::optional<InteractionModel::AttributeInfo> GetAttributeInfo(const ConcreteAttributePath & path) override;
};

} // namespace CodegenDataModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClusterInfo> 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<ClusterInfo> 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)
Expand Down Expand Up @@ -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<AttributeInfo> info = model.GetAttributeInfo(ConcreteAttributePath(kMockEndpoint1, MockClusterId(1), FeatureMap::Id));
ASSERT_TRUE(info.HasValue());
ASSERT_FALSE(info.Value().flags.Has(AttributeQualityFlags::kListAttribute));
std::optional<AttributeInfo> 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));
}

0 comments on commit 5892a36

Please sign in to comment.