Skip to content

Commit

Permalink
[IM] Implement list chunking feature (#12019)
Browse files Browse the repository at this point in the history
* Update AttributeValueEncoder

* TagBoundEncoder -> ListEncodeHelper

* Fix Null ListIndex support

* Offload build logic to separate class

* Add attribute for testing list chunking

* Fix Error

* Add even more tests

* auto -> const auto *

* Address comments

* Update

* Update Encode

* Update

* Update

* Update

* Fix style

* Fix

* Run Codegen
  • Loading branch information
erjiaqing authored Dec 6, 2021
1 parent 186c004 commit bfdbd45
Show file tree
Hide file tree
Showing 81 changed files with 3,615 additions and 1,947 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15961,6 +15961,21 @@
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "list_long_octet_string",
"code": 42,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "timed_write_boolean",
"code": 48,
Expand Down Expand Up @@ -20088,4 +20103,4 @@
}
],
"log": []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CHIP_ERROR ApplicationLauncherManager::Init()

CHIP_ERROR ApplicationLauncherManager::proxyGetApplicationList(chip::app::AttributeValueEncoder & aEncoder)
{
return aEncoder.EncodeList([](const chip::app::TagBoundEncoder & encoder) -> CHIP_ERROR {
return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR {
ReturnErrorOnFailure(encoder.Encode(123u));
ReturnErrorOnFailure(encoder.Encode(456u));
return CHIP_NO_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CHIP_ERROR AudioOutputManager::Init()

CHIP_ERROR AudioOutputManager::proxyGetListOfAudioOutputInfo(chip::app::AttributeValueEncoder & aEncoder)
{
return aEncoder.EncodeList([](const chip::app::TagBoundEncoder & encoder) -> CHIP_ERROR {
return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR {
// TODO: Insert code here
int maximumVectorSize = 3;
char name[] = "exampleName";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CHIP_ERROR TargetNavigatorManager::Init()

CHIP_ERROR TargetNavigatorManager::proxyGetTargetInfoList(chip::app::AttributeValueEncoder & aEncoder)
{
return aEncoder.EncodeList([](const chip::app::TagBoundEncoder & encoder) -> CHIP_ERROR {
return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR {
// TODO: Insert code here
int maximumVectorSize = 2;
char name[] = "exampleName";
Expand Down
4 changes: 2 additions & 2 deletions examples/tv-app/android/java/ContentLauncherManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ CHIP_ERROR ContentLauncherManager::GetAcceptsHeader(chip::app::AttributeValueEnc
VerifyOrExit(mGetAcceptsHeaderMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);

return aEncoder.EncodeList([this, env](const chip::app::TagBoundEncoder & encoder) -> CHIP_ERROR {
return aEncoder.EncodeList([this, env](const auto & encoder) -> CHIP_ERROR {
jobjectArray headersArray = (jobjectArray) env->CallObjectMethod(mContentLauncherManagerObject, mGetAcceptsHeaderMethod);
if (env->ExceptionCheck())
{
Expand Down Expand Up @@ -206,7 +206,7 @@ CHIP_ERROR ContentLauncherManager::GetSupportedStreamingTypes(chip::app::Attribu
VerifyOrExit(mGetSupportedStreamingTypesMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);

return aEncoder.EncodeList([this, env](const chip::app::TagBoundEncoder & encoder) -> CHIP_ERROR {
return aEncoder.EncodeList([this, env](const auto & encoder) -> CHIP_ERROR {
jintArray typesArray = (jintArray) env->CallObjectMethod(mContentLauncherManagerObject, mGetSupportedStreamingTypesMethod);
if (env->ExceptionCheck())
{
Expand Down
2 changes: 1 addition & 1 deletion examples/tv-app/android/java/MediaInputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ CHIP_ERROR MediaInputManager::GetInputList(app::AttributeValueEncoder & aEncoder
VerifyOrExit(mGetInputListMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);

return aEncoder.EncodeList([this, env](const app::TagBoundEncoder & encoder) -> CHIP_ERROR {
return aEncoder.EncodeList([this, env](const auto & encoder) -> CHIP_ERROR {
jobjectArray inputArray = (jobjectArray) env->CallObjectMethod(mMediaInputManagerObject, mGetInputListMethod);
if (env->ExceptionCheck())
{
Expand Down
2 changes: 1 addition & 1 deletion examples/tv-app/android/java/TvChannelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ CHIP_ERROR TvChannelManager::getTvChannelList(chip::app::AttributeValueEncoder &
VerifyOrExit(mGetChannelListMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);

return aEncoder.EncodeList([env, this](const chip::app::TagBoundEncoder & encoder) -> CHIP_ERROR {
return aEncoder.EncodeList([env, this](const auto & encoder) -> CHIP_ERROR {
jobjectArray channelInfoList = (jobjectArray) env->CallObjectMethod(mTvChannelManagerObject, mGetChannelListMethod);
jint length = env->GetArrayLength(channelInfoList);
for (jint i = 0; i < length; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CHIP_ERROR ApplicationLauncherManager::Init()

CHIP_ERROR ApplicationLauncherManager::proxyGetApplicationList(chip::app::AttributeValueEncoder & aEncoder)
{
return aEncoder.EncodeList([](const chip::app::TagBoundEncoder & encoder) -> CHIP_ERROR {
return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR {
ReturnErrorOnFailure(encoder.Encode(123u));
ReturnErrorOnFailure(encoder.Encode(456u));
return CHIP_NO_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CHIP_ERROR AudioOutputManager::Init()

CHIP_ERROR AudioOutputManager::proxyGetListOfAudioOutputInfo(chip::app::AttributeValueEncoder & aEncoder)
{
return aEncoder.EncodeList([](const chip::app::TagBoundEncoder & encoder) -> CHIP_ERROR {
return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR {
// TODO: Insert code here
int maximumVectorSize = 3;
char name[] = "exampleName";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ CHIP_ERROR ContentLauncherManager::Init()

CHIP_ERROR ContentLauncherManager::proxyGetAcceptsHeader(chip::app::AttributeValueEncoder & aEncoder)
{
return aEncoder.EncodeList([](const chip::app::TagBoundEncoder & encoder) -> CHIP_ERROR {
return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR {
// TODO: Insert code here
char headerExample[] = "exampleHeader";
int maximumVectorSize = 1;
Expand All @@ -68,7 +68,7 @@ CHIP_ERROR ContentLauncherManager::proxyGetAcceptsHeader(chip::app::AttributeVal

CHIP_ERROR ContentLauncherManager::proxyGetSupportedStreamingTypes(chip::app::AttributeValueEncoder & aEncoder)
{
return aEncoder.EncodeList([](const chip::app::TagBoundEncoder & encoder) -> CHIP_ERROR {
return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR {
// TODO: Insert code here
ReturnErrorOnFailure(encoder.Encode(EMBER_ZCL_CONTENT_LAUNCH_STREAMING_TYPE_DASH));
ReturnErrorOnFailure(encoder.Encode(EMBER_ZCL_CONTENT_LAUNCH_STREAMING_TYPE_HLS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ CHIP_ERROR MediaInputManager::Init()

CHIP_ERROR MediaInputManager::proxyGetInputList(chip::app::AttributeValueEncoder & aEncoder)
{
return aEncoder.EncodeList([](const chip::app::TagBoundEncoder & encoder) -> CHIP_ERROR {
return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR {
// TODO: Insert code here
int maximumVectorSize = 2;
char description[] = "exampleDescription";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CHIP_ERROR TargetNavigatorManager::Init()

CHIP_ERROR TargetNavigatorManager::proxyGetTargetInfoList(chip::app::AttributeValueEncoder & aEncoder)
{
return aEncoder.EncodeList([](const chip::app::TagBoundEncoder & encoder) -> CHIP_ERROR {
return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR {
// TODO: Insert code here
int maximumVectorSize = 2;
char name[] = "exampleName";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CHIP_ERROR TvChannelManager::Init()

CHIP_ERROR TvChannelManager::proxyGetTvChannelList(chip::app::AttributeValueEncoder & aEncoder)
{
return aEncoder.EncodeList([](const chip::app::TagBoundEncoder & encoder) -> CHIP_ERROR {
return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR {
// TODO: Insert code here
int maximumVectorSize = 2;
char affiliateCallSign[] = "exampleASign";
Expand Down
89 changes: 89 additions & 0 deletions src/app/AttributeAccessInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <app/AttributeAccessInterface.h>

namespace chip {
namespace app {

CHIP_ERROR AttributeReportBuilder::PrepareAttribute(AttributeReportIBs::Builder & aAttributeReportIBsBuilder,
const ConcreteDataAttributePath & aPath, DataVersion aDataVersion)
{
mAttributeReportIBBuilder = aAttributeReportIBsBuilder.CreateAttributeReport();
ReturnErrorOnFailure(aAttributeReportIBsBuilder.GetError());

mAttributeDataIBBuilder = mAttributeReportIBBuilder.CreateAttributeData();
ReturnErrorOnFailure(mAttributeReportIBBuilder.GetError());

mAttributeDataIBBuilder.DataVersion(aDataVersion);

auto attributePathIBBuilder = mAttributeDataIBBuilder.CreatePath();
ReturnErrorOnFailure(mAttributeDataIBBuilder.GetError());

attributePathIBBuilder.Endpoint(aPath.mEndpointId).Cluster(aPath.mClusterId).Attribute(aPath.mAttributeId);

if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem)
{
// An append to a list (or a data chunk consisting just one list entry that's part of a bigger list) is represented by a
// null list index in the path.
attributePathIBBuilder.ListIndex(DataModel::Nullable<ListIndex>());
}

ReturnErrorOnFailure(attributePathIBBuilder.EndOfAttributePathIB().GetError());

return mAttributeDataIBBuilder.GetError();
}

CHIP_ERROR AttributeReportBuilder::FinishAttribute()
{
ReturnErrorOnFailure(mAttributeDataIBBuilder.EndOfAttributeDataIB().GetError());
return mAttributeReportIBBuilder.EndOfAttributeReportIB().GetError();
}

CHIP_ERROR AttributeValueEncoder::EncodeEmptyList()
{
if (mCurrentEncodingListIndex == kInvalidListIndex)
{
if (mEncodeState.mCurrentEncodingListIndex == kInvalidListIndex)
{
// Clear mAllowPartialData flag here since this encode procedure is not atomic.
// The most common error in this function is CHIP_ERROR_NO_MEMORY / CHIP_ERROR_BUFFER_TOO_SMALL, just revert and try
// next time is ok.
mEncodeState.mAllowPartialData = false;
// Spec 10.5.4.3.1, 10.5.4.6 (Replace a list w/ Multiple IBs)
// Put an empty array before encoding the first array element for list chunking.
AttributeReportBuilder builder;

ReturnErrorOnFailure(builder.PrepareAttribute(mAttributeReportIBsBuilder, mPath, mDataVersion));
ReturnErrorOnFailure(builder.EncodeValue(DataModel::List<uint8_t>()));

ReturnErrorOnFailure(builder.FinishAttribute());
mEncodeState.mCurrentEncodingListIndex = 0;
}
mCurrentEncodingListIndex = 0;
}

// After encoding the empty list, the remaining items are atomically encoded into the buffer. Tell report engine to not
// revert partial data.
mEncodeState.mAllowPartialData = true;

return CHIP_NO_ERROR;
}

} // namespace app
} // namespace chip
Loading

0 comments on commit bfdbd45

Please sign in to comment.