Line data Source code
1 : /**
2 : *
3 : * Copyright (c) 2020 Project CHIP Authors
4 : * Copyright (c) 2018 Google LLC.
5 : * Copyright (c) 2016-2017 Nest Labs, Inc.
6 : * Licensed under the Apache License, Version 2.0 (the "License");
7 : * you may not use this file except in compliance with the License.
8 : * You may obtain a copy of the License at
9 : *
10 : * http://www.apache.org/licenses/LICENSE-2.0
11 : *
12 : * Unless required by applicable law or agreed to in writing, software
13 : * distributed under the License is distributed on an "AS IS" BASIS,
14 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 : * See the License for the specific language governing permissions and
16 : * limitations under the License.
17 : */
18 : /**
19 : * @file
20 : * This file defines AttributeReportIBs parser and builder in CHIP interaction model
21 : *
22 : */
23 :
24 : #include "AttributeReportIBs.h"
25 : #include "MessageDefHelper.h"
26 :
27 : #include <inttypes.h>
28 : #include <stdarg.h>
29 : #include <stdio.h>
30 :
31 : #include <app/AppConfig.h>
32 :
33 : namespace chip {
34 : namespace app {
35 : #if CHIP_CONFIG_IM_PRETTY_PRINT
36 1218 : CHIP_ERROR AttributeReportIBs::Parser::PrettyPrint() const
37 : {
38 1218 : CHIP_ERROR err = CHIP_NO_ERROR;
39 1218 : TLV::TLVReader reader;
40 :
41 1218 : PRETTY_PRINT("AttributeReportIBs =");
42 1218 : PRETTY_PRINT("[");
43 :
44 : // make a copy of the reader
45 1218 : reader.Init(mReader);
46 :
47 5581 : while (CHIP_NO_ERROR == (err = reader.Next()))
48 : {
49 4363 : VerifyOrReturnError(TLV::AnonymousTag() == reader.GetTag(), CHIP_ERROR_INVALID_TLV_TAG);
50 : {
51 4363 : AttributeReportIB::Parser AttributeReport;
52 4363 : ReturnErrorOnFailure(AttributeReport.Init(reader));
53 4363 : PRETTY_PRINT_INCDEPTH();
54 4363 : ReturnErrorOnFailure(AttributeReport.PrettyPrint());
55 4363 : PRETTY_PRINT_DECDEPTH();
56 : }
57 : }
58 :
59 1218 : PRETTY_PRINT("],");
60 1218 : PRETTY_PRINT_BLANK_LINE();
61 :
62 : // if we have exhausted this container
63 1218 : if (CHIP_END_OF_TLV == err)
64 : {
65 1218 : err = CHIP_NO_ERROR;
66 : }
67 1218 : ReturnErrorOnFailure(err);
68 1218 : return reader.ExitContainer(mOuterContainerType);
69 : }
70 : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
71 :
72 4674 : AttributeReportIB::Builder & AttributeReportIBs::Builder::CreateAttributeReport()
73 : {
74 4674 : if (mError == CHIP_NO_ERROR)
75 : {
76 4674 : mError = mAttributeReport.Init(mpWriter);
77 : }
78 4674 : return mAttributeReport;
79 : }
80 :
81 1921 : CHIP_ERROR AttributeReportIBs::Builder::EndOfAttributeReportIBs()
82 : {
83 1921 : EndOfContainer();
84 1921 : return GetError();
85 : }
86 :
87 0 : CHIP_ERROR AttributeReportIBs::Builder::EncodeAttributeStatus(const ConcreteReadAttributePath & aPath, const StatusIB & aStatus)
88 : {
89 0 : AttributeReportIB::Builder & attributeReport = CreateAttributeReport();
90 0 : ReturnErrorOnFailure(GetError());
91 0 : AttributeStatusIB::Builder & attributeStatusIBBuilder = attributeReport.CreateAttributeStatus();
92 0 : ReturnErrorOnFailure(attributeReport.GetError());
93 0 : AttributePathIB::Builder & attributePathIBBuilder = attributeStatusIBBuilder.CreatePath();
94 0 : ReturnErrorOnFailure(attributeStatusIBBuilder.GetError());
95 :
96 0 : attributePathIBBuilder.Endpoint(aPath.mEndpointId)
97 0 : .Cluster(aPath.mClusterId)
98 0 : .Attribute(aPath.mAttributeId)
99 0 : .EndOfAttributePathIB();
100 0 : ReturnErrorOnFailure(attributePathIBBuilder.GetError());
101 0 : StatusIB::Builder & statusIBBuilder = attributeStatusIBBuilder.CreateErrorStatus();
102 0 : ReturnErrorOnFailure(attributeStatusIBBuilder.GetError());
103 0 : statusIBBuilder.EncodeStatusIB(aStatus);
104 0 : ReturnErrorOnFailure(statusIBBuilder.GetError());
105 :
106 0 : ReturnErrorOnFailure(attributeStatusIBBuilder.EndOfAttributeStatusIB());
107 0 : return attributeReport.EndOfAttributeReportIB();
108 : }
109 :
110 : } // namespace app
111 : } // namespace chip
|