/src/connectedhomeip/src/app/MessageDef/InvokeRequests.cpp
Line | Count | Source |
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 "InvokeRequests.h" |
18 | | |
19 | | #include "MessageDefHelper.h" |
20 | | |
21 | | #include <inttypes.h> |
22 | | #include <stdarg.h> |
23 | | #include <stdio.h> |
24 | | |
25 | | #include <app/AppConfig.h> |
26 | | |
27 | | namespace chip { |
28 | | namespace app { |
29 | | #if CHIP_CONFIG_IM_PRETTY_PRINT |
30 | | CHIP_ERROR InvokeRequests::Parser::PrettyPrint() const |
31 | 0 | { |
32 | 0 | CHIP_ERROR err = CHIP_NO_ERROR; |
33 | 0 | size_t numCommandDatas = 0; |
34 | 0 | TLV::TLVReader reader; |
35 | |
|
36 | 0 | PRETTY_PRINT("InvokeRequests ="); |
37 | 0 | PRETTY_PRINT("["); |
38 | | |
39 | | // make a copy of the reader |
40 | 0 | reader.Init(mReader); |
41 | |
|
42 | 0 | while (CHIP_NO_ERROR == (err = reader.Next())) |
43 | 0 | { |
44 | 0 | VerifyOrReturnError(TLV::AnonymousTag() == reader.GetTag(), CHIP_ERROR_INVALID_TLV_TAG); |
45 | 0 | { |
46 | 0 | CommandDataIB::Parser commandData; |
47 | 0 | ReturnErrorOnFailure(commandData.Init(reader)); |
48 | 0 | PRETTY_PRINT_INCDEPTH(); |
49 | 0 | ReturnErrorOnFailure(commandData.PrettyPrint()); |
50 | 0 | PRETTY_PRINT_DECDEPTH(); |
51 | 0 | } |
52 | | |
53 | 0 | ++numCommandDatas; |
54 | 0 | } |
55 | | |
56 | 0 | PRETTY_PRINT("],"); |
57 | 0 | PRETTY_PRINT_BLANK_LINE(); |
58 | | |
59 | | // if we have exhausted this container |
60 | 0 | if (CHIP_END_OF_TLV == err) |
61 | 0 | { |
62 | | // if we have at least one data element |
63 | 0 | if (numCommandDatas > 0) |
64 | 0 | { |
65 | 0 | err = CHIP_NO_ERROR; |
66 | 0 | } |
67 | 0 | } |
68 | 0 | ReturnErrorOnFailure(err); |
69 | 0 | return reader.ExitContainer(mOuterContainerType); |
70 | 0 | } |
71 | | #endif // CHIP_CONFIG_IM_PRETTY_PRINT |
72 | | |
73 | | CHIP_ERROR InvokeRequests::Builder::InitWithEndBufferReserved(TLV::TLVWriter * const apWriter, const uint8_t aContextTagToUse) |
74 | 0 | { |
75 | 0 | ReturnErrorOnFailure(Init(apWriter, aContextTagToUse)); |
76 | 0 | ReturnErrorOnFailure(GetWriter()->ReserveBuffer(GetSizeToEndInvokeRequests())); |
77 | 0 | mIsEndBufferReserved = true; |
78 | 0 | return CHIP_NO_ERROR; |
79 | 0 | } |
80 | | |
81 | | CommandDataIB::Builder & InvokeRequests::Builder::CreateCommandData() |
82 | 0 | { |
83 | 0 | if (mError == CHIP_NO_ERROR) |
84 | 0 | { |
85 | 0 | mError = mCommandData.Init(mpWriter); |
86 | 0 | } |
87 | 0 | return mCommandData; |
88 | 0 | } |
89 | | |
90 | | CHIP_ERROR InvokeRequests::Builder::EndOfInvokeRequests() |
91 | 0 | { |
92 | | // If any changes are made to how we end the invoke requests that involves how many bytes are |
93 | | // needed, a corresponding change to GetSizeToEndInvokeRequests indicating the new size that |
94 | | // will be required. |
95 | 0 | if (mIsEndBufferReserved) |
96 | 0 | { |
97 | 0 | ReturnErrorOnFailure(GetWriter()->UnreserveBuffer(GetSizeToEndInvokeRequests())); |
98 | 0 | mIsEndBufferReserved = false; |
99 | 0 | } |
100 | 0 | EndOfContainer(); |
101 | 0 | return GetError(); |
102 | 0 | } |
103 | | |
104 | | uint32_t InvokeRequests::Builder::GetSizeToEndInvokeRequests() |
105 | 0 | { |
106 | 0 | uint32_t kEndOfContainerSize = 1; |
107 | 0 | return kEndOfContainerSize; |
108 | 0 | } |
109 | | } // namespace app |
110 | | } // namespace chip |