/src/connectedhomeip/src/app/MessageDef/InvokeResponseIB.cpp
Line | Count | Source |
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 <inttypes.h> |
18 | | #include <stdarg.h> |
19 | | #include <stdio.h> |
20 | | |
21 | | #include "InvokeResponseIB.h" |
22 | | #include "MessageDefHelper.h" |
23 | | |
24 | | #include <app/AppConfig.h> |
25 | | |
26 | | namespace chip { |
27 | | namespace app { |
28 | | #if CHIP_CONFIG_IM_PRETTY_PRINT |
29 | | CHIP_ERROR InvokeResponseIB::Parser::PrettyPrint() const |
30 | 0 | { |
31 | 0 | CHIP_ERROR err = CHIP_NO_ERROR; |
32 | 0 | TLV::TLVReader reader; |
33 | |
|
34 | 0 | PRETTY_PRINT("InvokeResponseIB ="); |
35 | 0 | PRETTY_PRINT("{"); |
36 | | |
37 | | // make a copy of the reader |
38 | 0 | reader.Init(mReader); |
39 | |
|
40 | 0 | while (CHIP_NO_ERROR == (err = reader.Next())) |
41 | 0 | { |
42 | 0 | if (!TLV::IsContextTag(reader.GetTag())) |
43 | 0 | { |
44 | 0 | continue; |
45 | 0 | } |
46 | 0 | uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); |
47 | 0 | switch (tagNum) |
48 | 0 | { |
49 | 0 | case to_underlying(Tag::kCommand): { |
50 | 0 | CommandDataIB::Parser command; |
51 | 0 | ReturnErrorOnFailure(command.Init(reader)); |
52 | | |
53 | 0 | PRETTY_PRINT_INCDEPTH(); |
54 | 0 | ReturnErrorOnFailure(command.PrettyPrint()); |
55 | 0 | PRETTY_PRINT_DECDEPTH(); |
56 | 0 | } |
57 | 0 | break; |
58 | 0 | case to_underlying(Tag::kStatus): { |
59 | 0 | CommandStatusIB::Parser status; |
60 | 0 | ReturnErrorOnFailure(status.Init(reader)); |
61 | | |
62 | 0 | PRETTY_PRINT_INCDEPTH(); |
63 | 0 | ReturnErrorOnFailure(status.PrettyPrint()); |
64 | 0 | PRETTY_PRINT_DECDEPTH(); |
65 | 0 | } |
66 | 0 | break; |
67 | 0 | default: |
68 | 0 | PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); |
69 | 0 | break; |
70 | 0 | } |
71 | 0 | } |
72 | | |
73 | 0 | PRETTY_PRINT("},"); |
74 | 0 | PRETTY_PRINT_BLANK_LINE(); |
75 | | |
76 | | // if we have exhausted this container |
77 | 0 | if (CHIP_END_OF_TLV == err) |
78 | 0 | { |
79 | 0 | err = CHIP_NO_ERROR; |
80 | 0 | } |
81 | 0 | ReturnErrorOnFailure(err); |
82 | 0 | return reader.ExitContainer(mOuterContainerType); |
83 | 0 | } |
84 | | #endif // CHIP_CONFIG_IM_PRETTY_PRINT |
85 | | |
86 | | CHIP_ERROR InvokeResponseIB::Parser::GetCommand(CommandDataIB::Parser * const apCommand) const |
87 | 0 | { |
88 | 0 | TLV::TLVReader reader; |
89 | 0 | ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kCommand), reader)); |
90 | 0 | return apCommand->Init(reader); |
91 | 0 | } |
92 | | |
93 | | CHIP_ERROR InvokeResponseIB::Parser::GetStatus(CommandStatusIB::Parser * const apStatus) const |
94 | 0 | { |
95 | 0 | TLV::TLVReader reader; |
96 | 0 | ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kStatus), reader)); |
97 | 0 | return apStatus->Init(reader); |
98 | 0 | } |
99 | | |
100 | | CommandDataIB::Builder & InvokeResponseIB::Builder::CreateCommand() |
101 | 0 | { |
102 | 0 | if (mError == CHIP_NO_ERROR) |
103 | 0 | { |
104 | 0 | mError = mCommand.Init(mpWriter, to_underlying(Tag::kCommand)); |
105 | 0 | } |
106 | 0 | return mCommand; |
107 | 0 | } |
108 | | |
109 | | CommandStatusIB::Builder & InvokeResponseIB::Builder::CreateStatus() |
110 | 0 | { |
111 | 0 | if (mError == CHIP_NO_ERROR) |
112 | 0 | { |
113 | 0 | mError = mStatus.Init(mpWriter, to_underlying(Tag::kStatus)); |
114 | 0 | } |
115 | 0 | return mStatus; |
116 | 0 | } |
117 | | |
118 | | CHIP_ERROR InvokeResponseIB::Builder::EndOfInvokeResponseIB() |
119 | 0 | { |
120 | 0 | EndOfContainer(); |
121 | 0 | return GetError(); |
122 | 0 | } |
123 | | } // namespace app |
124 | | } // namespace chip |