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 2737 : CHIP_ERROR AttributeStatusIB::Parser::PrettyPrint() const
32 : {
33 2737 : CHIP_ERROR err = CHIP_NO_ERROR;
34 2737 : TLV::TLVReader reader;
35 :
36 2737 : PRETTY_PRINT("AttributeStatusIB =");
37 2737 : PRETTY_PRINT("{");
38 :
39 : // make a copy of the reader
40 2737 : reader.Init(mReader);
41 :
42 8211 : while (CHIP_NO_ERROR == (err = reader.Next()))
43 : {
44 5474 : if (!TLV::IsContextTag(reader.GetTag()))
45 : {
46 0 : continue;
47 : }
48 5474 : uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
49 5474 : switch (tagNum)
50 : {
51 2737 : case to_underlying(Tag::kPath): {
52 2737 : AttributePathIB::Parser path;
53 2737 : ReturnErrorOnFailure(path.Init(reader));
54 :
55 2737 : PRETTY_PRINT_INCDEPTH();
56 2737 : ReturnErrorOnFailure(path.PrettyPrint());
57 2737 : PRETTY_PRINT_DECDEPTH();
58 : }
59 2737 : break;
60 2737 : case to_underlying(Tag::kErrorStatus): {
61 2737 : StatusIB::Parser errorStatus;
62 2737 : ReturnErrorOnFailure(errorStatus.Init(reader));
63 :
64 2737 : PRETTY_PRINT_INCDEPTH();
65 2737 : ReturnErrorOnFailure(errorStatus.PrettyPrint());
66 2737 : PRETTY_PRINT_DECDEPTH();
67 : }
68 2737 : break;
69 0 : default:
70 0 : PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
71 0 : break;
72 : }
73 : }
74 :
75 2737 : PRETTY_PRINT("},");
76 2737 : PRETTY_PRINT_BLANK_LINE();
77 :
78 2737 : if (CHIP_END_OF_TLV == err)
79 : {
80 2737 : err = CHIP_NO_ERROR;
81 : }
82 :
83 2737 : ReturnErrorOnFailure(err);
84 2737 : return reader.ExitContainer(mOuterContainerType);
85 : }
86 : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
87 :
88 2735 : CHIP_ERROR AttributeStatusIB::Parser::GetPath(AttributePathIB::Parser * const apPath) const
89 : {
90 2735 : TLV::TLVReader reader;
91 2735 : ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kPath), reader));
92 2735 : return apPath->Init(reader);
93 : }
94 :
95 2735 : CHIP_ERROR AttributeStatusIB::Parser::GetErrorStatus(StatusIB::Parser * const apErrorStatus) const
96 : {
97 2735 : TLV::TLVReader reader;
98 2735 : ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kErrorStatus), reader));
99 2735 : return apErrorStatus->Init(reader);
100 : }
101 :
102 2757 : AttributePathIB::Builder & AttributeStatusIB::Builder::CreatePath()
103 : {
104 2757 : if (mError == CHIP_NO_ERROR)
105 : {
106 2757 : mError = mPath.Init(mpWriter, to_underlying(Tag::kPath));
107 : }
108 2757 : return mPath;
109 : }
110 :
111 2751 : StatusIB::Builder & AttributeStatusIB::Builder::CreateErrorStatus()
112 : {
113 2751 : if (mError == CHIP_NO_ERROR)
114 : {
115 2751 : mError = mErrorStatus.Init(mpWriter, to_underlying(Tag::kErrorStatus));
116 : }
117 2751 : return mErrorStatus;
118 : }
119 :
120 2751 : CHIP_ERROR AttributeStatusIB::Builder::EndOfAttributeStatusIB()
121 : {
122 2751 : EndOfContainer();
123 2751 : return GetError();
124 : }
125 : } // namespace app
126 : } // namespace chip
|