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