LCOV - code coverage report
Current view: top level - app/MessageDef - CommandStatusIB.cpp (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 55 64 85.9 %
Date: 2024-02-15 08:20:41 Functions: 8 8 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 "CommandStatusIB.h"
      18             : #include "MessageDefHelper.h"
      19             : #include "StructBuilder.h"
      20             : #include "StructParser.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          26 : CHIP_ERROR CommandStatusIB::Parser::PrettyPrint() const
      32             : {
      33          26 :     CHIP_ERROR err      = CHIP_NO_ERROR;
      34          26 :     int tagPresenceMask = 0;
      35             :     TLV::TLVReader reader;
      36             : 
      37          26 :     PRETTY_PRINT("CommandStatusIB =");
      38          26 :     PRETTY_PRINT("{");
      39             : 
      40             :     // make a copy of the reader
      41          26 :     reader.Init(mReader);
      42             : 
      43          78 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      44             :     {
      45          52 :         if (!TLV::IsContextTag(reader.GetTag()))
      46             :         {
      47           0 :             continue;
      48             :         }
      49          52 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      50          52 :         switch (tagNum)
      51             :         {
      52          26 :         case to_underlying(Tag::kPath):
      53             :             // check if this tag has appeared before
      54          26 :             VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kPath))), CHIP_ERROR_INVALID_TLV_TAG);
      55          26 :             tagPresenceMask |= (1 << to_underlying(Tag::kPath));
      56             :             {
      57          26 :                 CommandPathIB::Parser path;
      58          26 :                 ReturnErrorOnFailure(path.Init(reader));
      59             : 
      60          26 :                 PRETTY_PRINT_INCDEPTH();
      61          26 :                 ReturnErrorOnFailure(path.PrettyPrint());
      62          26 :                 PRETTY_PRINT_DECDEPTH();
      63             :             }
      64          26 :             break;
      65          26 :         case to_underlying(Tag::kErrorStatus):
      66             :             // check if this tag has appeared before
      67          26 :             VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kErrorStatus))), CHIP_ERROR_INVALID_TLV_TAG);
      68          26 :             tagPresenceMask |= (1 << to_underlying(Tag::kErrorStatus));
      69             :             {
      70          26 :                 StatusIB::Parser errorStatus;
      71          26 :                 ReturnErrorOnFailure(errorStatus.Init(reader));
      72             : 
      73          26 :                 PRETTY_PRINT_INCDEPTH();
      74          26 :                 ReturnErrorOnFailure(errorStatus.PrettyPrint());
      75          26 :                 PRETTY_PRINT_DECDEPTH();
      76             :             }
      77          26 :             break;
      78           0 :         case to_underlying(Tag::kRef):
      79           0 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      80             :             {
      81             :                 uint16_t reference;
      82           0 :                 ReturnErrorOnFailure(reader.Get(reference));
      83           0 :                 PRETTY_PRINT("\tRef = 0x%x,", reference);
      84             :             }
      85           0 :             break;
      86           0 :         default:
      87           0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
      88           0 :             break;
      89             :         }
      90             :     }
      91             : 
      92          26 :     PRETTY_PRINT("},");
      93          26 :     PRETTY_PRINT_BLANK_LINE();
      94             : 
      95          26 :     if (CHIP_END_OF_TLV == err)
      96             :     {
      97          26 :         err = CHIP_NO_ERROR;
      98             :     }
      99             : 
     100          26 :     ReturnErrorOnFailure(err);
     101          26 :     return reader.ExitContainer(mOuterContainerType);
     102             : }
     103             : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
     104             : 
     105          25 : CHIP_ERROR CommandStatusIB::Parser::GetPath(CommandPathIB::Parser * const apPath) const
     106             : {
     107             :     TLV::TLVReader reader;
     108          25 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kPath), reader));
     109          25 :     return apPath->Init(reader);
     110             : }
     111             : 
     112          25 : CHIP_ERROR CommandStatusIB::Parser::GetErrorStatus(StatusIB::Parser * const apErrorStatus) const
     113             : {
     114             :     TLV::TLVReader reader;
     115          25 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kErrorStatus), reader));
     116          25 :     return apErrorStatus->Init(reader);
     117             : }
     118             : 
     119          24 : CHIP_ERROR CommandStatusIB::Parser::GetRef(uint16_t * const apRef) const
     120             : {
     121          24 :     return GetUnsignedInteger(to_underlying(Tag::kRef), apRef);
     122             : }
     123             : 
     124          39 : CommandPathIB::Builder & CommandStatusIB::Builder::CreatePath()
     125             : {
     126          39 :     if (mError == CHIP_NO_ERROR)
     127             :     {
     128          39 :         mError = mPath.Init(mpWriter, to_underlying(Tag::kPath));
     129             :     }
     130          39 :     return mPath;
     131             : }
     132             : 
     133          39 : StatusIB::Builder & CommandStatusIB::Builder::CreateErrorStatus()
     134             : {
     135          39 :     if (mError == CHIP_NO_ERROR)
     136             :     {
     137          39 :         mError = mErrorStatus.Init(mpWriter, to_underlying(Tag::kErrorStatus));
     138             :     }
     139          39 :     return mErrorStatus;
     140             : }
     141             : 
     142           3 : CHIP_ERROR CommandStatusIB::Builder::Ref(const uint16_t aRef)
     143             : {
     144           3 :     return mpWriter->Put(TLV::ContextTag(Tag::kRef), aRef);
     145             : }
     146             : 
     147          39 : CHIP_ERROR CommandStatusIB::Builder::EndOfCommandStatusIB()
     148             : {
     149          39 :     EndOfContainer();
     150          39 :     return GetError();
     151             : }
     152             : } // namespace app
     153             : } // namespace chip

Generated by: LCOV version 1.14