LCOV - code coverage report
Current view: top level - app/MessageDef - DataVersionFilterIB.cpp (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 43 47 91.5 %
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             :  *    @file
      18             :  *      This file defines DataVersionFilter parser and builder in CHIP interaction model
      19             :  *
      20             :  */
      21             : 
      22             : #include "DataVersionFilterIB.h"
      23             : 
      24             : #include "MessageDefHelper.h"
      25             : 
      26             : #include <inttypes.h>
      27             : #include <stdarg.h>
      28             : #include <stdio.h>
      29             : 
      30             : #include <app/AppConfig.h>
      31             : 
      32             : namespace chip {
      33             : namespace app {
      34             : #if CHIP_CONFIG_IM_PRETTY_PRINT
      35          82 : CHIP_ERROR DataVersionFilterIB::Parser::PrettyPrint() const
      36             : {
      37          82 :     CHIP_ERROR err = CHIP_NO_ERROR;
      38             :     TLV::TLVReader reader;
      39             : 
      40          82 :     PRETTY_PRINT("DataVersionFilterIB =");
      41          82 :     PRETTY_PRINT("{");
      42             : 
      43             :     // make a copy of the Path reader
      44          82 :     reader.Init(mReader);
      45             : 
      46         246 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      47             :     {
      48         164 :         if (!TLV::IsContextTag(reader.GetTag()))
      49             :         {
      50           0 :             continue;
      51             :         }
      52         164 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      53         164 :         switch (tagNum)
      54             :         {
      55          82 :         case to_underlying(Tag::kPath): {
      56          82 :             ClusterPathIB::Parser path;
      57          82 :             ReturnErrorOnFailure(path.Init(reader));
      58             : 
      59          82 :             PRETTY_PRINT_INCDEPTH();
      60          82 :             ReturnErrorOnFailure(path.PrettyPrint());
      61          82 :             PRETTY_PRINT_DECDEPTH();
      62             :         }
      63          82 :         break;
      64          82 :         case to_underlying(Tag::kDataVersion):
      65          82 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      66             : 
      67             : #if CHIP_DETAIL_LOGGING
      68             :             {
      69             :                 chip::DataVersion version;
      70          82 :                 ReturnErrorOnFailure(reader.Get(version));
      71          82 :                 PRETTY_PRINT("\tDataVersion = 0x%" PRIx32 ",", version);
      72             :             }
      73             : #endif // CHIP_DETAIL_LOGGING
      74          82 :             break;
      75           0 :         default:
      76           0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
      77           0 :             break;
      78             :         }
      79             :     }
      80          82 :     PRETTY_PRINT("},");
      81          82 :     PRETTY_PRINT_BLANK_LINE();
      82             : 
      83             :     // if we have exhausted this container
      84          82 :     if (CHIP_END_OF_TLV == err)
      85             :     {
      86          82 :         err = CHIP_NO_ERROR;
      87             :     }
      88          82 :     ReturnErrorOnFailure(err);
      89          82 :     return reader.ExitContainer(mOuterContainerType);
      90             : }
      91             : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
      92             : 
      93          79 : CHIP_ERROR DataVersionFilterIB::Parser::GetPath(ClusterPathIB::Parser * const apPath) const
      94             : {
      95             :     TLV::TLVReader reader;
      96          79 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kPath), reader));
      97          79 :     return apPath->Init(reader);
      98             : }
      99             : 
     100          79 : CHIP_ERROR DataVersionFilterIB::Parser::GetDataVersion(chip::DataVersion * const apVersion) const
     101             : {
     102          79 :     return GetUnsignedInteger(to_underlying(Tag::kDataVersion), apVersion);
     103             : }
     104             : 
     105         605 : ClusterPathIB::Builder & DataVersionFilterIB::Builder::CreatePath()
     106             : {
     107         605 :     if (mError == CHIP_NO_ERROR)
     108             :     {
     109         605 :         mError = mPath.Init(mpWriter, to_underlying(Tag::kPath));
     110             :     }
     111         605 :     return mPath;
     112             : }
     113             : 
     114         495 : DataVersionFilterIB::Builder & DataVersionFilterIB::Builder::DataVersion(const chip::DataVersion aDataVersion)
     115             : {
     116             :     // skip if error has already been set
     117         495 :     if (mError == CHIP_NO_ERROR)
     118             :     {
     119         495 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kDataVersion), aDataVersion);
     120             :     }
     121         495 :     return *this;
     122             : }
     123             : 
     124         495 : CHIP_ERROR DataVersionFilterIB::Builder::EndOfDataVersionFilterIB()
     125             : {
     126         495 :     EndOfContainer();
     127         495 :     return GetError();
     128             : }
     129             : } // namespace app
     130             : } // namespace chip

Generated by: LCOV version 1.14