Line data Source code
1 : /** 2 : * 3 : * Copyright (c) 2020-2021 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 9 : * 10 : * http://www.apache.org/licenses/LICENSE-2.0 11 : * 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. 17 : */ 18 : 19 : #include "AttributePathIBs.h" 20 : #include "MessageDefHelper.h" 21 : 22 : #include <inttypes.h> 23 : #include <stdarg.h> 24 : #include <stdio.h> 25 : 26 : #include <app/AppConfig.h> 27 : 28 : namespace chip { 29 : namespace app { 30 : #if CHIP_CONFIG_IM_PRETTY_PRINT 31 832 : CHIP_ERROR AttributePathIBs::Parser::PrettyPrint() const 32 : { 33 832 : CHIP_ERROR err = CHIP_NO_ERROR; 34 832 : size_t numAttributePath = 0; 35 : TLV::TLVReader reader; 36 : 37 832 : PRETTY_PRINT("AttributePathIBs ="); 38 832 : PRETTY_PRINT("["); 39 : 40 : // make a copy of the AttributePathIBs reader 41 832 : reader.Init(mReader); 42 : 43 2674 : while (CHIP_NO_ERROR == (err = reader.Next())) 44 : { 45 1842 : VerifyOrReturnError(TLV::AnonymousTag() == reader.GetTag(), CHIP_ERROR_INVALID_TLV_TAG); 46 1842 : VerifyOrReturnError(TLV::kTLVType_List == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); 47 : { 48 1842 : AttributePathIB::Parser path; 49 1842 : ReturnErrorOnFailure(path.Init(reader)); 50 1842 : PRETTY_PRINT_INCDEPTH(); 51 1842 : ReturnErrorOnFailure(path.PrettyPrint()); 52 1842 : PRETTY_PRINT_DECDEPTH(); 53 : } 54 : 55 1842 : ++numAttributePath; 56 : } 57 : 58 832 : PRETTY_PRINT("],"); 59 832 : PRETTY_PRINT("\t"); 60 : 61 : // if we have exhausted this container 62 832 : if (CHIP_END_OF_TLV == err) 63 : { 64 : // if we have at least one data element 65 832 : if (numAttributePath > 0) 66 : { 67 832 : err = CHIP_NO_ERROR; 68 : } 69 : } 70 832 : ReturnErrorOnFailure(err); 71 832 : return reader.ExitContainer(mOuterContainerType); 72 : } 73 : #endif // CHIP_CONFIG_IM_PRETTY_PRINT 74 : 75 1865 : AttributePathIB::Builder & AttributePathIBs::Builder::CreatePath() 76 : { 77 1865 : if (mError == CHIP_NO_ERROR) 78 : { 79 1865 : mError = mAttributePath.Init(mpWriter); 80 : } 81 1865 : return mAttributePath; 82 : } 83 : 84 : // Mark the end of this array and recover the type for outer container 85 848 : CHIP_ERROR AttributePathIBs::Builder::EndOfAttributePathIBs() 86 : { 87 848 : EndOfContainer(); 88 848 : return GetError(); 89 : } 90 : } // namespace app 91 : } // namespace chip