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 "StatusResponseMessage.h"
18 : #include "MessageDefHelper.h"
19 : #include "protocols/interaction_model/Constants.h"
20 :
21 : using namespace chip::Protocols::InteractionModel;
22 :
23 : namespace chip {
24 : namespace app {
25 : #if CHIP_CONFIG_IM_PRETTY_PRINT
26 1312 : CHIP_ERROR StatusResponseMessage::Parser::PrettyPrint() const
27 : {
28 1312 : CHIP_ERROR err = CHIP_NO_ERROR;
29 1312 : TLV::TLVReader reader;
30 1312 : PRETTY_PRINT("StatusResponseMessage =");
31 1312 : PRETTY_PRINT("{");
32 :
33 : // make a copy of the reader
34 1312 : reader.Init(mReader);
35 :
36 3936 : while (CHIP_NO_ERROR == (err = reader.Next()))
37 : {
38 2624 : if (!TLV::IsContextTag(reader.GetTag()))
39 : {
40 0 : continue;
41 : }
42 2624 : uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
43 2624 : switch (tagNum)
44 : {
45 1312 : case to_underlying(Tag::kStatus):
46 1312 : VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
47 : #if CHIP_DETAIL_LOGGING
48 : {
49 : uint8_t status;
50 1312 : ReturnErrorOnFailure(reader.Get(status));
51 1312 : PRETTY_PRINT("\tStatus = " ChipLogFormatIMStatus ",", ChipLogValueIMStatus(static_cast<Status>(status)));
52 : }
53 : #endif // CHIP_DETAIL_LOGGING
54 1312 : break;
55 1312 : case Revision::kInteractionModelRevisionTag:
56 1312 : ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
57 1312 : break;
58 0 : default:
59 0 : PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
60 0 : break;
61 : }
62 : }
63 1312 : PRETTY_PRINT("}");
64 1312 : PRETTY_PRINT_BLANK_LINE();
65 :
66 1312 : if (CHIP_END_OF_TLV == err)
67 : {
68 1312 : err = CHIP_NO_ERROR;
69 : }
70 1312 : ReturnErrorOnFailure(err);
71 1312 : return reader.ExitContainer(mOuterContainerType);
72 : }
73 : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
74 :
75 1313 : CHIP_ERROR StatusResponseMessage::Parser::GetStatus(Protocols::InteractionModel::Status & aStatus) const
76 : {
77 1313 : uint16_t status = 0;
78 1313 : CHIP_ERROR err = GetUnsignedInteger(to_underlying(Tag::kStatus), &status);
79 1313 : aStatus = static_cast<Protocols::InteractionModel::Status>(status);
80 1313 : return err;
81 : }
82 :
83 1397 : StatusResponseMessage::Builder & StatusResponseMessage::Builder::Status(const Protocols::InteractionModel::Status aStatus)
84 : {
85 : // skip if error has already been set
86 1397 : if (mError == CHIP_NO_ERROR)
87 : {
88 1397 : mError = mpWriter->Put(TLV::ContextTag(Tag::kStatus), aStatus);
89 : }
90 1397 : if (mError == CHIP_NO_ERROR)
91 : {
92 1397 : mError = MessageBuilder::EncodeInteractionModelRevision();
93 : }
94 1397 : if (mError == CHIP_NO_ERROR)
95 : {
96 1397 : EndOfContainer();
97 : }
98 1397 : return *this;
99 : }
100 :
101 : } // namespace app
102 : } // namespace chip
|