Matter SDK Coverage Report
Current view: top level - app/MessageDef - InvokeResponseIB.cpp (source / functions) Coverage Total Hit
Test: SHA:b879ecb8e99e175eea0a293a888bda853da2b19c Lines: 92.5 % 53 49
Test Date: 2025-01-17 19:00:11 Functions: 100.0 % 6 6

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

Generated by: LCOV version 2.0-1