Skip to content

Commit

Permalink
Group Data Provider Listener: Code review changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcasallas-silabs committed Dec 14, 2021
1 parent 42f5add commit f739bac
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
16 changes: 4 additions & 12 deletions src/credentials/GroupDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ class GroupDataProvider
/**
* Interface to listen for changes in the Group info.
*/
class Listener
class GroupListener
{
public:
virtual ~Listener() = default;
virtual ~GroupListener() = default;
/**
* Callback invoked when a new group is added.
*
Expand Down Expand Up @@ -286,7 +286,7 @@ class GroupDataProvider
virtual CHIP_ERROR Decrypt(PacketHeader packetHeader, PayloadHeader & payloadHeader, System::PacketBufferHandle & msg) = 0;

// Listener
void SetListener(Listener * listener) { mListener = listener; };
void SetListener(GroupListener * listener) { mListener = listener; };
void RemoveListener() { mListener = nullptr; };

protected:
Expand All @@ -297,15 +297,7 @@ class GroupDataProvider
mListener->OnGroupAdded(fabric_index, new_group);
}
}
void GroupRemoved(chip::FabricIndex fabric_index, const GroupInfo & old_group)
{
if (mListener)
{
mListener->OnGroupRemoved(fabric_index, old_group);
}
}

Listener * mListener = nullptr;
GroupListener * mListener = nullptr;
};

/**
Expand Down
17 changes: 8 additions & 9 deletions src/credentials/GroupDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,6 @@ CHIP_ERROR GroupDataProviderImpl::SetGroupInfoAt(chip::FabricIndex fabric_index,

FabricData fabric(fabric_index);
GroupData group;
bool new_group = false;

// Load fabric, defaults to zero
fabric.Load(mStorage);
Expand All @@ -717,9 +716,9 @@ CHIP_ERROR GroupDataProviderImpl::SetGroupInfoAt(chip::FabricIndex fabric_index,
bool found = group.Find(mStorage, fabric, info.group_id);
VerifyOrReturnError(!found || (group.index == index), CHIP_ERROR_DUPLICATE_KEY_ID);

found = group.Get(mStorage, fabric, index);
new_group = (group.group_id != info.group_id);
group.group_id = info.group_id;
found = group.Get(mStorage, fabric, index);
const bool new_group = (group.group_id != info.group_id);
group.group_id = info.group_id;
group.SetName(info.name);

if (found)
Expand Down Expand Up @@ -824,7 +823,10 @@ CHIP_ERROR GroupDataProviderImpl::RemoveGroupInfoAt(chip::FabricIndex fabric_ind
}
// Update fabric info
ReturnErrorOnFailure(fabric.Save(mStorage));
GroupRemoved(fabric_index, group);
if (mListener)
{
mListener->OnGroupRemoved(fabric_index, group);
}
return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -1139,10 +1141,7 @@ CHIP_ERROR GroupDataProviderImpl::RemoveEndpoints(chip::FabricIndex fabric_index
size_t endpoint_index = 0;
while (endpoint_index < group.endpoint_count)
{
if (CHIP_NO_ERROR != endpoint.Load(mStorage))
{
break;
}
ReturnErrorOnFailure(endpoint.Load(mStorage));
endpoint.Delete(mStorage);
endpoint.id = endpoint.next;
endpoint_index++;
Expand Down
2 changes: 1 addition & 1 deletion src/credentials/tests/TestGroupDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static KeySet kKeySet1(kKeysetId1, KeySet::SecurityPolicy::kLowLatency, 1);
static KeySet kKeySet2(kKeysetId2, KeySet::SecurityPolicy::kLowLatency, 2);
static KeySet kKeySet3(kKeysetId3, KeySet::SecurityPolicy::kStandard, 3);

class TestListener : public GroupDataProvider::Listener
class TestListener : public GroupDataProvider::GroupListener
{
public:
chip::FabricIndex fabric_index = kUndefinedFabricIndex;
Expand Down

0 comments on commit f739bac

Please sign in to comment.