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 "SubscribeResponseMessage.h"
18 : #include "MessageDefHelper.h"
19 :
20 : namespace chip {
21 : namespace app {
22 : #if CHIP_CONFIG_IM_PRETTY_PRINT
23 277 : CHIP_ERROR SubscribeResponseMessage::Parser::PrettyPrint() const
24 : {
25 277 : CHIP_ERROR err = CHIP_NO_ERROR;
26 277 : TLV::TLVReader reader;
27 277 : PRETTY_PRINT("SubscribeResponseMessage =");
28 277 : PRETTY_PRINT("{");
29 :
30 : // make a copy of the reader
31 277 : reader.Init(mReader);
32 :
33 1108 : while (CHIP_NO_ERROR == (err = reader.Next()))
34 : {
35 831 : if (!TLV::IsContextTag(reader.GetTag()))
36 : {
37 0 : continue;
38 : }
39 831 : uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
40 831 : switch (tagNum)
41 : {
42 277 : case to_underlying(Tag::kSubscriptionId):
43 277 : VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
44 : #if CHIP_DETAIL_LOGGING
45 : {
46 : SubscriptionId subscriptionId;
47 277 : ReturnErrorOnFailure(reader.Get(subscriptionId));
48 277 : PRETTY_PRINT("\tSubscriptionId = 0x%" PRIx32 ",", subscriptionId);
49 : }
50 : #endif // CHIP_DETAIL_LOGGING
51 277 : break;
52 277 : case to_underlying(Tag::kMaxInterval):
53 277 : VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
54 : #if CHIP_DETAIL_LOGGING
55 : {
56 : uint16_t maxInterval;
57 277 : ReturnErrorOnFailure(reader.Get(maxInterval));
58 277 : PRETTY_PRINT("\tMaxInterval = 0x%x,", maxInterval);
59 : }
60 : #endif // CHIP_DETAIL_LOGGING
61 277 : break;
62 277 : case Revision::kInteractionModelRevisionTag:
63 277 : ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
64 277 : break;
65 0 : default:
66 0 : PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
67 0 : break;
68 : }
69 : }
70 277 : PRETTY_PRINT("}");
71 277 : PRETTY_PRINT_BLANK_LINE();
72 :
73 277 : if (CHIP_END_OF_TLV == err)
74 : {
75 277 : err = CHIP_NO_ERROR;
76 : }
77 277 : ReturnErrorOnFailure(err);
78 277 : return reader.ExitContainer(mOuterContainerType);
79 : }
80 : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
81 :
82 277 : CHIP_ERROR SubscribeResponseMessage::Parser::GetSubscriptionId(SubscriptionId * const apSubscribeId) const
83 : {
84 277 : return GetUnsignedInteger(to_underlying(Tag::kSubscriptionId), apSubscribeId);
85 : }
86 :
87 275 : CHIP_ERROR SubscribeResponseMessage::Parser::GetMaxInterval(uint16_t * const apMaxInterval) const
88 : {
89 275 : return GetUnsignedInteger(to_underlying(Tag::kMaxInterval), apMaxInterval);
90 : }
91 :
92 279 : SubscribeResponseMessage::Builder & SubscribeResponseMessage::Builder::SubscriptionId(const chip::SubscriptionId aSubscribeId)
93 : {
94 279 : if (mError == CHIP_NO_ERROR)
95 : {
96 279 : mError = mpWriter->Put(TLV::ContextTag(Tag::kSubscriptionId), aSubscribeId);
97 : }
98 279 : return *this;
99 : }
100 :
101 279 : SubscribeResponseMessage::Builder & SubscribeResponseMessage::Builder::MaxInterval(const uint16_t aMaxInterval)
102 : {
103 279 : if (mError == CHIP_NO_ERROR)
104 : {
105 279 : mError = mpWriter->Put(TLV::ContextTag(Tag::kMaxInterval), aMaxInterval);
106 : }
107 279 : return *this;
108 : }
109 :
110 279 : CHIP_ERROR SubscribeResponseMessage::Builder::EndOfSubscribeResponseMessage()
111 : {
112 279 : if (mError == CHIP_NO_ERROR)
113 : {
114 279 : mError = MessageBuilder::EncodeInteractionModelRevision();
115 : }
116 279 : if (mError == CHIP_NO_ERROR)
117 : {
118 279 : EndOfContainer();
119 : }
120 279 : return GetError();
121 : }
122 : } // namespace app
123 : } // namespace chip
|