3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2018 Google LLC.
5 * Copyright (c) 2016-2017 Nest Labs, Inc.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 * This file defines CommandList parser and builder in CHIP interaction model
24 #include "CommandList.h"
26 #include "MessageDefHelper.h"
33 using namespace chip::TLV;
37 #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
38 CHIP_ERROR CommandList::Parser::CheckSchemaValidity() const
40 CHIP_ERROR err = CHIP_NO_ERROR;
41 size_t NumCommands = 0;
42 chip::TLV::TLVReader reader;
44 PRETTY_PRINT("CommandList =");
47 // make a copy of the reader
50 while (CHIP_NO_ERROR == (err = reader.Next()))
52 VerifyOrExit(chip::TLV::AnonymousTag == reader.GetTag(), err = CHIP_ERROR_INVALID_TLV_TAG);
53 VerifyOrExit(chip::TLV::kTLVType_Structure == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE);
56 CommandDataElement::Parser data;
57 err = data.Init(reader);
60 PRETTY_PRINT_INCDEPTH();
61 err = data.CheckSchemaValidity();
64 PRETTY_PRINT_DECDEPTH();
73 // if we have exhausted this container
74 if (CHIP_END_OF_TLV == err)
76 // if we have at least one data element
84 ChipLogFunctError(err);
88 #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
90 CommandDataElement::Builder & CommandList::Builder::CreateCommandDataElementBuilder()
92 // skip if error has already been set
93 VerifyOrExit(CHIP_NO_ERROR == mError, mCommandDataElementBuilder.ResetError(mError));
95 mError = mCommandDataElementBuilder.Init(mpWriter);
96 ChipLogFunctError(mError);
99 // on error, mCommandDataElementBuilder would be un-/partial initialized and cannot be used to write anything
100 return mCommandDataElementBuilder;
103 CommandList::Builder & CommandList::Builder::EndOfCommandList()