Skip to content

Commit

Permalink
Rename SetUserLabelCount/GetUserLabelCount to SetUserLabelLength/GetU…
Browse files Browse the repository at this point in the history
…serLabelLength
  • Loading branch information
yufengwangca committed Apr 1, 2022
1 parent 74ae92e commit 6d959e9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 25 deletions.
31 changes: 20 additions & 11 deletions src/app/clusters/user-label-server/user-label-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,31 @@ CHIP_ERROR UserLabelAttrAccess::ReadLabelList(EndpointId endpoint, AttributeValu
{
CHIP_ERROR err = CHIP_NO_ERROR;

DeviceLayer::DeviceInfoProvider::UserLabelIterator * it = DeviceLayer::GetDeviceInfoProvider()->IterateUserLabel(endpoint);
DeviceLayer::DeviceInfoProvider * provider = DeviceLayer::GetDeviceInfoProvider();

if (it)
if (provider)
{
err = aEncoder.EncodeList([&it](const auto & encoder) -> CHIP_ERROR {
UserLabel::Structs::LabelStruct::Type userlabel;
DeviceLayer::DeviceInfoProvider::UserLabelIterator * it = provider->IterateUserLabel(endpoint);

while (it->Next(userlabel))
{
ReturnErrorOnFailure(encoder.Encode(userlabel));
}
if (it)
{
err = aEncoder.EncodeList([&it](const auto & encoder) -> CHIP_ERROR {
UserLabel::Structs::LabelStruct::Type userlabel;

while (it->Next(userlabel))
{
ReturnErrorOnFailure(encoder.Encode(userlabel));
}

return CHIP_NO_ERROR;
});
return CHIP_NO_ERROR;
});

it->Release();
it->Release();
}
else
{
err = aEncoder.EncodeEmptyList();
}
}
else
{
Expand Down
11 changes: 6 additions & 5 deletions src/include/platform/DeviceInfoProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ class DeviceInfoProvider

// Iterators
/**
* Creates an iterator that may be used to obtain the list of user labels associated with the given endpoint.
* Creates an iterator that may be used to obtain the list of labels associated with the given endpoint.
* In order to release the allocated memory, the Release() method must be called after the iteration is finished.
* Modifying the user label during the iteration is currently not supported, and may yield unexpected behaviour.
* Modifying the label during the iteration is currently not supported, and may yield unexpected behaviour.
* @retval An instance of EndpointIterator on success
* @retval nullptr if no iterator instances are available.
*/
Expand All @@ -98,7 +98,8 @@ class DeviceInfoProvider
* @param endpoint - id to UserLabelList on which to set the UserLabel.
* @param index - index within the UserLabelList for which to set the UserLabel.
* @param userLabel - user label to set.
* @return CHIP_NO_ERROR on success, other CHIP_ERROR values from implementation on other errors.
* @return CHIP_NO_ERROR on success, CHIP_ERROR_INVALID_KEY_ID if index exceed the range (Total length - 1),
* or other CHIP_ERROR values from implementation on other errors.
*/
virtual CHIP_ERROR SetUserLabelAt(EndpointId endpoint, size_t index, const UserLabelType & userLabel) = 0;

Expand All @@ -109,7 +110,7 @@ class DeviceInfoProvider
* @param val - total count of the UserLabelList.
* @return CHIP_NO_ERROR on success, other CHIP_ERROR values from implementation on other errors.
*/
virtual CHIP_ERROR SetUserLabelCount(EndpointId endpoint, size_t val) = 0;
virtual CHIP_ERROR SetUserLabelLength(EndpointId endpoint, size_t val) = 0;

/**
* @brief Get the total length of the UserLabelList on a given endpoint
Expand All @@ -118,7 +119,7 @@ class DeviceInfoProvider
* @param val - output of the total count of the UserLabelList.
* @return CHIP_NO_ERROR on success, other CHIP_ERROR values from implementation on other errors.
*/
virtual CHIP_ERROR GetUserLabelCount(EndpointId endpoint, size_t & val) = 0;
virtual CHIP_ERROR GetUserLabelLength(EndpointId endpoint, size_t & val) = 0;
};

/**
Expand Down
12 changes: 8 additions & 4 deletions src/platform/DeviceInfoProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CHIP_ERROR DeviceInfoProvider::SetUserLabelList(EndpointId endpoint,
{
size_t index = 0;

ReturnErrorOnFailure(SetUserLabelCount(endpoint, labelList.size()));
ReturnErrorOnFailure(SetUserLabelLength(endpoint, labelList.size()));

for (const UserLabelType & label : labelList)
{
Expand All @@ -52,10 +52,14 @@ CHIP_ERROR DeviceInfoProvider::SetUserLabelList(EndpointId endpoint,

CHIP_ERROR DeviceInfoProvider::AppendUserLabel(EndpointId endpoint, const UserLabelType & label)
{
size_t index;
size_t length;

ReturnErrorOnFailure(GetUserLabelCount(endpoint, index));
ReturnErrorOnFailure(SetUserLabelAt(endpoint, index + 1, label));
// Increase the size of UserLabelList by 1
ReturnErrorOnFailure(GetUserLabelLength(endpoint, length));
ReturnErrorOnFailure(SetUserLabelLength(endpoint, length + 1));

// Append the user label at the end of UserLabelList
ReturnErrorOnFailure(SetUserLabelAt(endpoint, length, label));

return CHIP_NO_ERROR;
}
Expand Down
6 changes: 3 additions & 3 deletions src/platform/Linux/DeviceInfoProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ bool DeviceInfoProviderImpl::FixedLabelIteratorImpl::Next(FixedLabelType & outpu
}
}

CHIP_ERROR DeviceInfoProviderImpl::SetUserLabelCount(EndpointId endpoint, size_t val)
CHIP_ERROR DeviceInfoProviderImpl::SetUserLabelLength(EndpointId endpoint, size_t val)
{
// TODO:: store the user label count.
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR DeviceInfoProviderImpl::GetUserLabelCount(EndpointId endpoint, size_t & val)
CHIP_ERROR DeviceInfoProviderImpl::GetUserLabelLength(EndpointId endpoint, size_t & val)
{
// TODO:: read the user label count. temporarily return the size of hardcoded labelList.
val = 4;
Expand All @@ -136,7 +136,7 @@ DeviceInfoProviderImpl::UserLabelIteratorImpl::UserLabelIteratorImpl(DeviceInfoP
{
size_t total = 0;

ReturnOnFailure(mProvider.GetUserLabelCount(mEndpoint, total));
ReturnOnFailure(mProvider.GetUserLabelLength(mEndpoint, total));
mTotal = total;
mIndex = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/platform/Linux/DeviceInfoProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class DeviceInfoProviderImpl : public DeviceInfoProvider
char mUserLabelValueBuf[kMaxLabelValueLength + 1];
};

CHIP_ERROR SetUserLabelCount(EndpointId endpoint, size_t val) override;
CHIP_ERROR GetUserLabelCount(EndpointId endpoint, size_t & val) override;
CHIP_ERROR SetUserLabelLength(EndpointId endpoint, size_t val) override;
CHIP_ERROR GetUserLabelLength(EndpointId endpoint, size_t & val) override;
CHIP_ERROR SetUserLabelAt(EndpointId endpoint, size_t index, const UserLabelType & userLabel) override;
};

Expand Down

0 comments on commit 6d959e9

Please sign in to comment.