LCOV - code coverage report
Current view: top level - app/MessageDef - InvokeResponseIB.cpp (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 46 50 92.0 %
Date: 2024-02-15 08:20:41 Functions: 6 6 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 <inttypes.h>
      18             : #include <stdarg.h>
      19             : #include <stdio.h>
      20             : 
      21             : #include "InvokeResponseIB.h"
      22             : #include "MessageDefHelper.h"
      23             : 
      24             : #include <app/AppConfig.h>
      25             : 
      26             : namespace chip {
      27             : namespace app {
      28             : #if CHIP_CONFIG_IM_PRETTY_PRINT
      29          35 : CHIP_ERROR InvokeResponseIB::Parser::PrettyPrint() const
      30             : {
      31          35 :     CHIP_ERROR err = CHIP_NO_ERROR;
      32             :     TLV::TLVReader reader;
      33             : 
      34          35 :     PRETTY_PRINT("InvokeResponseIB =");
      35          35 :     PRETTY_PRINT("{");
      36             : 
      37             :     // make a copy of the reader
      38          35 :     reader.Init(mReader);
      39             : 
      40          70 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      41             :     {
      42          35 :         if (!TLV::IsContextTag(reader.GetTag()))
      43             :         {
      44           0 :             continue;
      45             :         }
      46          35 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      47          35 :         switch (tagNum)
      48             :         {
      49          10 :         case to_underlying(Tag::kCommand): {
      50          10 :             CommandDataIB::Parser command;
      51          10 :             ReturnErrorOnFailure(command.Init(reader));
      52             : 
      53          10 :             PRETTY_PRINT_INCDEPTH();
      54          10 :             ReturnErrorOnFailure(command.PrettyPrint());
      55          10 :             PRETTY_PRINT_DECDEPTH();
      56             :         }
      57          10 :         break;
      58          25 :         case to_underlying(Tag::kStatus): {
      59          25 :             CommandStatusIB::Parser status;
      60          25 :             ReturnErrorOnFailure(status.Init(reader));
      61             : 
      62          25 :             PRETTY_PRINT_INCDEPTH();
      63          25 :             ReturnErrorOnFailure(status.PrettyPrint());
      64          25 :             PRETTY_PRINT_DECDEPTH();
      65             :         }
      66          25 :         break;
      67           0 :         default:
      68           0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
      69           0 :             break;
      70             :         }
      71             :     }
      72             : 
      73          35 :     PRETTY_PRINT("},");
      74          35 :     PRETTY_PRINT_BLANK_LINE();
      75             : 
      76             :     // if we have exhausted this container
      77          35 :     if (CHIP_END_OF_TLV == err)
      78             :     {
      79          35 :         err = CHIP_NO_ERROR;
      80             :     }
      81          35 :     ReturnErrorOnFailure(err);
      82          35 :     return reader.ExitContainer(mOuterContainerType);
      83             : }
      84             : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
      85             : 
      86           8 : CHIP_ERROR InvokeResponseIB::Parser::GetCommand(CommandDataIB::Parser * const apCommand) const
      87             : {
      88             :     TLV::TLVReader reader;
      89           8 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kCommand), reader));
      90           8 :     return apCommand->Init(reader);
      91             : }
      92             : 
      93          32 : CHIP_ERROR InvokeResponseIB::Parser::GetStatus(CommandStatusIB::Parser * const apStatus) const
      94             : {
      95             :     TLV::TLVReader reader;
      96          32 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kStatus), reader));
      97          25 :     return apStatus->Init(reader);
      98             : }
      99             : 
     100          24 : CommandDataIB::Builder & InvokeResponseIB::Builder::CreateCommand()
     101             : {
     102          24 :     if (mError == CHIP_NO_ERROR)
     103             :     {
     104          24 :         mError = mCommand.Init(mpWriter, to_underlying(Tag::kCommand));
     105             :     }
     106          24 :     return mCommand;
     107             : }
     108             : 
     109          38 : CommandStatusIB::Builder & InvokeResponseIB::Builder::CreateStatus()
     110             : {
     111          38 :     if (mError == CHIP_NO_ERROR)
     112             :     {
     113          38 :         mError = mStatus.Init(mpWriter, to_underlying(Tag::kStatus));
     114             :     }
     115          38 :     return mStatus;
     116             : }
     117             : 
     118          58 : CHIP_ERROR InvokeResponseIB::Builder::EndOfInvokeResponseIB()
     119             : {
     120          58 :     EndOfContainer();
     121          58 :     return GetError();
     122             : }
     123             : } // namespace app
     124             : } // namespace chip

Generated by: LCOV version 1.14