Skip to content

Commit

Permalink
Remove GroupKeyCodec. (#13179)
Browse files Browse the repository at this point in the history
* Remove GroupKeyCodec.

It's not needed; all that code already exists in Structs::GroupKey.

The XML change is to fix a compile issue due to the type being wrong,
but pretty much all the XML is wrong there.
#13176 tracks
addressing that.

* Remove GroupKeyCodec again - apparently the conflict file was not zap generated

Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Dec 6, 2023
1 parent 1b62bcf commit 1282644
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 74 deletions.
75 changes: 9 additions & 66 deletions src/app/clusters/group-key-mgmt-server/group-key-mgmt-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,67 +40,6 @@ using namespace chip::app::Clusters;

namespace {

struct GroupKeyCodec
{
static constexpr TLV::Tag TagFabric()
{
return TLV::ContextTag(to_underlying(GroupKeyManagement::Structs::GroupKey::Fields::kFabricIndex));
}
static constexpr TLV::Tag TagGroup()
{
return TLV::ContextTag(to_underlying(GroupKeyManagement::Structs::GroupKey::Fields::kGroupId));
}
static constexpr TLV::Tag TagKeyset()
{
return TLV::ContextTag(to_underlying(GroupKeyManagement::Structs::GroupKey::Fields::kGroupKeySetID));
}

chip::FabricIndex mFabric = 0;
GroupDataProvider::GroupKey mMapping;

GroupKeyCodec() = default;
GroupKeyCodec(chip::FabricIndex fabric_index, const GroupDataProvider::GroupKey & mapping) :
mFabric(fabric_index), mMapping(mapping)
{}

CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const
{
TLV::TLVType outer;
ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outer));

// FabricIndex
ReturnErrorOnFailure(DataModel::Encode(writer, TagFabric(), mFabric));
// GroupId
ReturnErrorOnFailure(DataModel::Encode(writer, TagGroup(), mMapping.group_id));
// GroupKeySetID
ReturnErrorOnFailure(DataModel::Encode(writer, TagKeyset(), mMapping.keyset_id));

ReturnErrorOnFailure(writer.EndContainer(outer));
return CHIP_NO_ERROR;
}

CHIP_ERROR Decode(TLV::TLVReader & reader)
{
TLV::TLVType outer;

VerifyOrReturnError(TLV::kTLVType_Structure == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
ReturnErrorOnFailure(reader.EnterContainer(outer));

// FabricIndex
ReturnErrorOnFailure(reader.Next(TagFabric()));
ReturnErrorOnFailure(reader.Get(mFabric));
// GroupId
ReturnErrorOnFailure(reader.Next(TagGroup()));
ReturnErrorOnFailure(reader.Get(mMapping.group_id));
// GroupKeySetID
ReturnErrorOnFailure(reader.Next(TagKeyset()));
ReturnErrorOnFailure(reader.Get(mMapping.keyset_id));

ReturnErrorOnFailure(reader.ExitContainer(outer));
return CHIP_NO_ERROR;
}
};

struct GroupTableCodec
{
static constexpr TLV::Tag TagFabric()
Expand Down Expand Up @@ -221,7 +160,10 @@ class GroupKeyManagementAttributeAccess : public AttributeAccessInterface
GroupDataProvider::GroupKey mapping;
while (iter->Next(mapping))
{
encoder.Encode(GroupKeyCodec(fabric_index, mapping));
GroupKeyManagement::Structs::GroupKey::Type key = { .fabricIndex = fabric_index,
.groupId = mapping.group_id,
.groupKeySetID = mapping.keyset_id };
encoder.Encode(key);
}
iter->Release();
return CHIP_NO_ERROR;
Expand All @@ -233,7 +175,7 @@ class GroupKeyManagementAttributeAccess : public AttributeAccessInterface
{
auto fabric_index = aDecoder.AccessingFabricIndex();
auto provider = GetGroupDataProvider();
DataModel::DecodableList<GroupKeyCodec> list;
GroupKeyManagement::Attributes::GroupKeyMap::TypeInfo::DecodableType list;
size_t new_count;

VerifyOrReturnError(nullptr != provider, CHIP_ERROR_INTERNAL);
Expand All @@ -248,9 +190,10 @@ class GroupKeyManagementAttributeAccess : public AttributeAccessInterface
size_t i = 0;
while (iter.Next())
{
const GroupKeyCodec & value = iter.GetValue();
VerifyOrReturnError(fabric_index == value.mFabric, CHIP_ERROR_INVALID_FABRIC_ID);
ReturnErrorOnFailure(provider->SetGroupKeyAt(value.mFabric, i++, value.mMapping));
const auto & value = iter.GetValue();
VerifyOrReturnError(fabric_index == value.fabricIndex, CHIP_ERROR_INVALID_FABRIC_ID);
ReturnErrorOnFailure(
provider->SetGroupKeyAt(value.fabricIndex, i++, GroupDataProvider::GroupKey(value.groupId, value.groupKeySetID)));
}
ReturnErrorOnFailure(iter.GetStatus());
return CHIP_NO_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.

<struct name="GroupKey">
<cluster code="0x003F"/>
<item fieldId="0" name="fabricIndex" type="INT16U"/>
<item fieldId="0" name="fabricIndex" type="fabric_idx"/>
<item fieldId="1" name="groupId" type="INT16U"/>
<item fieldId="2" name="groupKeySetID" type="INT16U"/>
</struct>
Expand Down Expand Up @@ -96,4 +96,4 @@ limitations under the License.
</command>

</cluster>
</configurator>
</configurator>
2 changes: 1 addition & 1 deletion src/controller/java/zap-generated/CHIPReadCallbacks.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1282644

Please sign in to comment.