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 "WriteResponseMessage.h"
18 : #include "MessageDefHelper.h"
19 :
20 : #include <inttypes.h>
21 : #include <stdarg.h>
22 : #include <stdio.h>
23 :
24 : #include <app/AppConfig.h>
25 :
26 : namespace chip {
27 : namespace app {
28 : #if CHIP_CONFIG_IM_PRETTY_PRINT
29 1729 : CHIP_ERROR WriteResponseMessage::Parser::PrettyPrint() const
30 : {
31 1729 : CHIP_ERROR err = CHIP_NO_ERROR;
32 1729 : TLV::TLVReader reader;
33 1729 : AttributeStatusIBs::Parser writeResponses;
34 1729 : PRETTY_PRINT("WriteResponseMessage =");
35 1729 : PRETTY_PRINT("{");
36 :
37 : // make a copy of the reader
38 1729 : reader.Init(mReader);
39 :
40 5187 : while (CHIP_NO_ERROR == (err = reader.Next()))
41 : {
42 3458 : if (!TLV::IsContextTag(reader.GetTag()))
43 : {
44 0 : continue;
45 : }
46 3458 : uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
47 3458 : switch (tagNum)
48 : {
49 1729 : case to_underlying(Tag::kWriteResponses):
50 1729 : VerifyOrReturnError(TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
51 1729 : ReturnErrorOnFailure(writeResponses.Init(reader));
52 :
53 1729 : PRETTY_PRINT_INCDEPTH();
54 1729 : ReturnErrorOnFailure(writeResponses.PrettyPrint());
55 1729 : PRETTY_PRINT_DECDEPTH();
56 1729 : break;
57 1729 : case Revision::kInteractionModelRevisionTag:
58 1729 : ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
59 1729 : break;
60 0 : default:
61 0 : PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
62 0 : break;
63 : }
64 : }
65 :
66 1729 : PRETTY_PRINT("}");
67 1729 : PRETTY_PRINT_BLANK_LINE();
68 :
69 1729 : if (CHIP_END_OF_TLV == err)
70 : {
71 1729 : err = CHIP_NO_ERROR;
72 : }
73 :
74 1729 : ReturnErrorOnFailure(err);
75 1729 : return reader.ExitContainer(mOuterContainerType);
76 : }
77 : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
78 :
79 1729 : CHIP_ERROR WriteResponseMessage::Parser::GetWriteResponses(AttributeStatusIBs::Parser * const apWriteResponses) const
80 : {
81 1729 : TLV::TLVReader reader;
82 1729 : ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kWriteResponses), reader));
83 1729 : return apWriteResponses->Init(reader);
84 : }
85 :
86 1739 : AttributeStatusIBs::Builder & WriteResponseMessage::Builder::CreateWriteResponses()
87 : {
88 : // skip if error has already been set
89 1739 : if (mError == CHIP_NO_ERROR)
90 : {
91 1739 : mError = mWriteResponses.Init(mpWriter, to_underlying(Tag::kWriteResponses));
92 : }
93 1739 : return mWriteResponses;
94 : }
95 :
96 6707 : AttributeStatusIBs::Builder & WriteResponseMessage::Builder::GetWriteResponses()
97 : {
98 6707 : return mWriteResponses;
99 : }
100 :
101 1737 : CHIP_ERROR WriteResponseMessage::Builder::EndOfWriteResponseMessage()
102 : {
103 1737 : if (mError == CHIP_NO_ERROR)
104 : {
105 1737 : mError = MessageBuilder::EncodeInteractionModelRevision();
106 : }
107 1737 : if (mError == CHIP_NO_ERROR)
108 : {
109 1737 : EndOfContainer();
110 : }
111 1737 : return GetError();
112 : }
113 : } // namespace app
114 : } // namespace chip
|