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