Line data Source code
1 : /**
2 : *
3 : * Copyright (c) 2021 Project CHIP Authors
4 : * Licensed under the Apache License, Version 2.0 (the "License");
5 : * you may not use this file except in compliance with the License.
6 : * You may obtain a copy of the License at
7 : *
8 : * http://www.apache.org/licenses/LICENSE-2.0
9 : *
10 : * Unless required by applicable law or agreed to in writing, software
11 : * distributed under the License is distributed on an "AS IS" BASIS,
12 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : * See the License for the specific language governing permissions and
14 : * limitations under the License.
15 : */
16 :
17 : #include "AttributeStatusIB.h"
18 : #include "MessageDefHelper.h"
19 : #include "StructBuilder.h"
20 : #include "StructParser.h"
21 :
22 : #include <inttypes.h>
23 : #include <stdarg.h>
24 : #include <stdio.h>
25 :
26 : #include <app/AppConfig.h>
27 :
28 : namespace chip {
29 : namespace app {
30 : #if CHIP_CONFIG_IM_PRETTY_PRINT
31 4254 : CHIP_ERROR AttributeStatusIB::Parser::PrettyPrint() const
32 : {
33 4254 : CHIP_ERROR err = CHIP_NO_ERROR;
34 4254 : TLV::TLVReader reader;
35 :
36 4254 : PRETTY_PRINT("AttributeStatusIB =");
37 4254 : PRETTY_PRINT("{");
38 :
39 : // make a copy of the reader
40 4254 : reader.Init(mReader);
41 :
42 12762 : while (CHIP_NO_ERROR == (err = reader.Next()))
43 : {
44 8508 : if (!TLV::IsContextTag(reader.GetTag()))
45 : {
46 0 : continue;
47 : }
48 8508 : uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
49 8508 : switch (tagNum)
50 : {
51 4254 : case to_underlying(Tag::kPath): {
52 4254 : AttributePathIB::Parser path;
53 4254 : ReturnErrorOnFailure(path.Init(reader));
54 :
55 4254 : PRETTY_PRINT_INCDEPTH();
56 4254 : ReturnErrorOnFailure(path.PrettyPrint());
57 4254 : PRETTY_PRINT_DECDEPTH();
58 : }
59 4254 : break;
60 4254 : case to_underlying(Tag::kErrorStatus): {
61 4254 : StatusIB::Parser errorStatus;
62 4254 : ReturnErrorOnFailure(errorStatus.Init(reader));
63 :
64 4254 : PRETTY_PRINT_INCDEPTH();
65 4254 : ReturnErrorOnFailure(errorStatus.PrettyPrint());
66 4254 : PRETTY_PRINT_DECDEPTH();
67 : }
68 4254 : break;
69 0 : default:
70 0 : PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
71 0 : break;
72 : }
73 : }
74 :
75 4254 : PRETTY_PRINT("},");
76 4254 : PRETTY_PRINT_BLANK_LINE();
77 :
78 4254 : if (CHIP_END_OF_TLV == err)
79 : {
80 4254 : err = CHIP_NO_ERROR;
81 : }
82 :
83 4254 : ReturnErrorOnFailure(err);
84 4254 : return reader.ExitContainer(mOuterContainerType);
85 : }
86 : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
87 :
88 4252 : CHIP_ERROR AttributeStatusIB::Parser::GetPath(AttributePathIB::Parser * const apPath) const
89 : {
90 4252 : TLV::TLVReader reader;
91 4252 : ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kPath), reader));
92 4252 : return apPath->Init(reader);
93 : }
94 :
95 4252 : CHIP_ERROR AttributeStatusIB::Parser::GetErrorStatus(StatusIB::Parser * const apErrorStatus) const
96 : {
97 4252 : TLV::TLVReader reader;
98 4252 : ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kErrorStatus), reader));
99 4252 : return apErrorStatus->Init(reader);
100 : }
101 :
102 4271 : AttributePathIB::Builder & AttributeStatusIB::Builder::CreatePath()
103 : {
104 4271 : if (mError == CHIP_NO_ERROR)
105 : {
106 4271 : mError = mPath.Init(mpWriter, to_underlying(Tag::kPath));
107 : }
108 4271 : return mPath;
109 : }
110 :
111 4271 : StatusIB::Builder & AttributeStatusIB::Builder::CreateErrorStatus()
112 : {
113 4271 : if (mError == CHIP_NO_ERROR)
114 : {
115 4271 : mError = mErrorStatus.Init(mpWriter, to_underlying(Tag::kErrorStatus));
116 : }
117 4271 : return mErrorStatus;
118 : }
119 :
120 4271 : CHIP_ERROR AttributeStatusIB::Builder::EndOfAttributeStatusIB()
121 : {
122 4271 : EndOfContainer();
123 4271 : return GetError();
124 : }
125 : } // namespace app
126 : } // namespace chip
|