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 "AttributeReportIB.h" 18 : #include "AttributeDataIB.h" 19 : #include "MessageDefHelper.h" 20 : #include "StructBuilder.h" 21 : #include "StructParser.h" 22 : 23 : #include <inttypes.h> 24 : #include <stdarg.h> 25 : #include <stdio.h> 26 : 27 : #include <app/AppConfig.h> 28 : 29 : namespace chip { 30 : namespace app { 31 : #if CHIP_CONFIG_IM_PRETTY_PRINT 32 3716 : CHIP_ERROR AttributeReportIB::Parser::PrettyPrint() const 33 : { 34 3716 : CHIP_ERROR err = CHIP_NO_ERROR; 35 : TLV::TLVReader reader; 36 : 37 3716 : PRETTY_PRINT("AttributeReportIB ="); 38 3716 : PRETTY_PRINT("{"); 39 : 40 : // make a copy of the reader 41 3716 : reader.Init(mReader); 42 : 43 7432 : while (CHIP_NO_ERROR == (err = reader.Next())) 44 : { 45 3716 : if (!TLV::IsContextTag(reader.GetTag())) 46 : { 47 0 : continue; 48 : } 49 3716 : uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); 50 3716 : switch (tagNum) 51 : { 52 274 : case to_underlying(Tag::kAttributeStatus): { 53 274 : AttributeStatusIB::Parser attributeStatus; 54 274 : ReturnErrorOnFailure(attributeStatus.Init(reader)); 55 : 56 274 : PRETTY_PRINT_INCDEPTH(); 57 274 : ReturnErrorOnFailure(attributeStatus.PrettyPrint()); 58 274 : PRETTY_PRINT_DECDEPTH(); 59 : } 60 274 : break; 61 3442 : case to_underlying(Tag::kAttributeData): { 62 3442 : AttributeDataIB::Parser attributeData; 63 3442 : ReturnErrorOnFailure(attributeData.Init(reader)); 64 : 65 3442 : PRETTY_PRINT_INCDEPTH(); 66 3442 : ReturnErrorOnFailure(attributeData.PrettyPrint()); 67 3442 : PRETTY_PRINT_DECDEPTH(); 68 : } 69 3442 : break; 70 0 : default: 71 0 : PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); 72 0 : break; 73 : } 74 : } 75 : 76 3716 : PRETTY_PRINT("},"); 77 3716 : PRETTY_PRINT_BLANK_LINE(); 78 : 79 3716 : if (CHIP_END_OF_TLV == err) 80 : { 81 3716 : err = CHIP_NO_ERROR; 82 : } 83 : 84 3716 : ReturnErrorOnFailure(err); 85 3716 : return reader.ExitContainer(mOuterContainerType); 86 : } 87 : #endif // CHIP_CONFIG_IM_PRETTY_PRINT 88 : 89 3709 : CHIP_ERROR AttributeReportIB::Parser::GetAttributeStatus(AttributeStatusIB::Parser * const apAttributeStatus) const 90 : { 91 : TLV::TLVReader reader; 92 3709 : ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kAttributeStatus), reader)); 93 274 : return apAttributeStatus->Init(reader); 94 : } 95 : 96 3436 : CHIP_ERROR AttributeReportIB::Parser::GetAttributeData(AttributeDataIB::Parser * const apAttributeData) const 97 : { 98 : TLV::TLVReader reader; 99 3436 : ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kAttributeData), reader)); 100 3436 : return apAttributeData->Init(reader); 101 : } 102 : 103 278 : AttributeStatusIB::Builder & AttributeReportIB::Builder::CreateAttributeStatus() 104 : { 105 278 : if (mError == CHIP_NO_ERROR) 106 : { 107 278 : mError = mAttributeStatus.Init(mpWriter, to_underlying(Tag::kAttributeStatus)); 108 : } 109 278 : return mAttributeStatus; 110 : } 111 : 112 3681 : AttributeDataIB::Builder & AttributeReportIB::Builder::CreateAttributeData() 113 : { 114 3681 : if (mError == CHIP_NO_ERROR) 115 : { 116 3681 : mError = mAttributeData.Init(mpWriter, to_underlying(Tag::kAttributeData)); 117 : } 118 3681 : return mAttributeData; 119 : } 120 : 121 3814 : CHIP_ERROR AttributeReportIB::Builder::EndOfAttributeReportIB() 122 : { 123 3814 : EndOfContainer(); 124 3814 : return GetError(); 125 : } 126 : } // namespace app 127 : } // namespace chip