Line data Source code
1 : /*
2 : * Copyright (c) 2021-2024 Project CHIP Authors
3 : * All rights reserved.
4 : *
5 : * Licensed under the Apache License, Version 2.0 (the "License");
6 : * you may not use this file except in compliance with the License.
7 : * You may obtain a copy of the License at
8 : *
9 : * http://www.apache.org/licenses/LICENSE-2.0
10 : *
11 : * Unless required by applicable law or agreed to in writing, software
12 : * distributed under the License is distributed on an "AS IS" BASIS,
13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : * See the License for the specific language governing permissions and
15 : * limitations under the License.
16 : */
17 : #include <app/AttributeReportBuilder.h>
18 :
19 : namespace chip {
20 : namespace app {
21 :
22 3421 : CHIP_ERROR AttributeReportBuilder::PrepareAttribute(AttributeReportIBs::Builder & aAttributeReportIBsBuilder,
23 : const ConcreteDataAttributePath & aPath, DataVersion aDataVersion)
24 : {
25 3421 : AttributeReportIB::Builder & attributeReportIBBuilder = aAttributeReportIBsBuilder.CreateAttributeReport();
26 3421 : ReturnErrorOnFailure(aAttributeReportIBsBuilder.GetError());
27 :
28 3410 : AttributeDataIB::Builder & attributeDataIBBuilder = attributeReportIBBuilder.CreateAttributeData();
29 3410 : ReturnErrorOnFailure(attributeReportIBBuilder.GetError());
30 :
31 3392 : attributeDataIBBuilder.DataVersion(aDataVersion);
32 :
33 3392 : AttributePathIB::Builder & attributePathIBBuilder = attributeDataIBBuilder.CreatePath();
34 3392 : ReturnErrorOnFailure(attributeDataIBBuilder.GetError());
35 :
36 3348 : attributePathIBBuilder.Endpoint(aPath.mEndpointId).Cluster(aPath.mClusterId).Attribute(aPath.mAttributeId);
37 :
38 3348 : if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem)
39 : {
40 : // 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
41 : // null list index in the path.
42 329 : attributePathIBBuilder.ListIndex(DataModel::Nullable<ListIndex>());
43 : }
44 :
45 3348 : ReturnErrorOnFailure(attributePathIBBuilder.EndOfAttributePathIB());
46 :
47 3292 : return attributeDataIBBuilder.GetError();
48 : }
49 :
50 3272 : CHIP_ERROR AttributeReportBuilder::FinishAttribute(AttributeReportIBs::Builder & aAttributeReportIBsBuilder)
51 : {
52 3272 : ReturnErrorOnFailure(aAttributeReportIBsBuilder.GetAttributeReport().GetAttributeData().EndOfAttributeDataIB());
53 3272 : return aAttributeReportIBsBuilder.GetAttributeReport().EndOfAttributeReportIB();
54 : }
55 :
56 : } // namespace app
57 : } // namespace chip
|