LCOV - code coverage report
Current view: top level - app/MessageDef - WriteResponseMessage.cpp (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 41 45 91.1 %
Date: 2024-02-15 08:20:41 Functions: 5 5 100.0 %

          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 "WriteResponseMessage.h"
      18             : #include "MessageDefHelper.h"
      19             : 
      20             : #include <inttypes.h>
      21             : #include <stdarg.h>
      22             : #include <stdio.h>
      23             : 
      24             : #include <app/AppConfig.h>
      25             : 
      26             : namespace chip {
      27             : namespace app {
      28             : #if CHIP_CONFIG_IM_PRETTY_PRINT
      29        1727 : CHIP_ERROR WriteResponseMessage::Parser::PrettyPrint() const
      30             : {
      31        1727 :     CHIP_ERROR err = CHIP_NO_ERROR;
      32             :     TLV::TLVReader reader;
      33        1727 :     AttributeStatusIBs::Parser writeResponses;
      34        1727 :     PRETTY_PRINT("WriteResponseMessage =");
      35        1727 :     PRETTY_PRINT("{");
      36             : 
      37             :     // make a copy of the reader
      38        1727 :     reader.Init(mReader);
      39             : 
      40        5181 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      41             :     {
      42        3454 :         if (!TLV::IsContextTag(reader.GetTag()))
      43             :         {
      44           0 :             continue;
      45             :         }
      46        3454 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      47        3454 :         switch (tagNum)
      48             :         {
      49        1727 :         case to_underlying(Tag::kWriteResponses):
      50        1727 :             VerifyOrReturnError(TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      51        1727 :             ReturnErrorOnFailure(writeResponses.Init(reader));
      52             : 
      53        1727 :             PRETTY_PRINT_INCDEPTH();
      54        1727 :             ReturnErrorOnFailure(writeResponses.PrettyPrint());
      55        1727 :             PRETTY_PRINT_DECDEPTH();
      56        1727 :             break;
      57        1727 :         case kInteractionModelRevisionTag:
      58        1727 :             ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
      59        1727 :             break;
      60           0 :         default:
      61           0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
      62           0 :             break;
      63             :         }
      64             :     }
      65             : 
      66        1727 :     PRETTY_PRINT("}");
      67        1727 :     PRETTY_PRINT_BLANK_LINE();
      68             : 
      69        1727 :     if (CHIP_END_OF_TLV == err)
      70             :     {
      71        1727 :         err = CHIP_NO_ERROR;
      72             :     }
      73             : 
      74        1727 :     ReturnErrorOnFailure(err);
      75        1727 :     return reader.ExitContainer(mOuterContainerType);
      76             : }
      77             : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
      78             : 
      79        1727 : CHIP_ERROR WriteResponseMessage::Parser::GetWriteResponses(AttributeStatusIBs::Parser * const apWriteResponses) const
      80             : {
      81             :     TLV::TLVReader reader;
      82        1727 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kWriteResponses), reader));
      83        1727 :     return apWriteResponses->Init(reader);
      84             : }
      85             : 
      86        1737 : AttributeStatusIBs::Builder & WriteResponseMessage::Builder::CreateWriteResponses()
      87             : {
      88             :     // skip if error has already been set
      89        1737 :     if (mError == CHIP_NO_ERROR)
      90             :     {
      91        1737 :         mError = mWriteResponses.Init(mpWriter, to_underlying(Tag::kWriteResponses));
      92             :     }
      93        1737 :     return mWriteResponses;
      94             : }
      95             : 
      96        6717 : AttributeStatusIBs::Builder & WriteResponseMessage::Builder::GetWriteResponses()
      97             : {
      98        6717 :     return mWriteResponses;
      99             : }
     100             : 
     101        1735 : CHIP_ERROR WriteResponseMessage::Builder::EndOfWriteResponseMessage()
     102             : {
     103        1735 :     if (mError == CHIP_NO_ERROR)
     104             :     {
     105        1735 :         mError = MessageBuilder::EncodeInteractionModelRevision();
     106             :     }
     107        1735 :     if (mError == CHIP_NO_ERROR)
     108             :     {
     109        1735 :         EndOfContainer();
     110             :     }
     111        1735 :     return GetError();
     112             : }
     113             : } // namespace app
     114             : } // namespace chip

Generated by: LCOV version 1.14