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