LCOV - code coverage report
Current view: top level - app/MessageDef - ClusterPathIB.cpp (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 51 55 92.7 %
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 "ClusterPathIB.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          83 : CHIP_ERROR ClusterPathIB::Parser::PrettyPrint() const
      30             : {
      31          83 :     CHIP_ERROR err = CHIP_NO_ERROR;
      32             :     TLV::TLVReader reader;
      33             : 
      34          83 :     PRETTY_PRINT("ClusterPathIB =");
      35          83 :     PRETTY_PRINT("{");
      36             : 
      37             :     // make a copy of the Path reader
      38          83 :     reader.Init(mReader);
      39             : 
      40         254 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      41             :     {
      42         171 :         if (!TLV::IsContextTag(reader.GetTag()))
      43             :         {
      44           0 :             continue;
      45             :         }
      46         171 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      47         171 :         switch (tagNum)
      48             :         {
      49           5 :         case to_underlying(Tag::kNode):
      50           5 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE);
      51             : 
      52             : #if CHIP_DETAIL_LOGGING
      53             :             {
      54             :                 NodeId node;
      55           5 :                 reader.Get(node);
      56           5 :                 PRETTY_PRINT("\tNode = 0x" ChipLogFormatX64 ",", ChipLogValueX64(node));
      57             :             }
      58             : #endif // CHIP_DETAIL_LOGGING
      59           5 :             break;
      60          83 :         case to_underlying(Tag::kEndpoint):
      61          83 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      62             : #if CHIP_DETAIL_LOGGING
      63             :             {
      64             :                 EndpointId endpoint;
      65          83 :                 reader.Get(endpoint);
      66          83 :                 PRETTY_PRINT("\tEndpoint = 0x%x,", endpoint);
      67             :             }
      68             : #endif // CHIP_DETAIL_LOGGING
      69          83 :             break;
      70          83 :         case to_underlying(Tag::kCluster):
      71          83 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE);
      72             : 
      73             : #if CHIP_DETAIL_LOGGING
      74             :             {
      75             :                 ClusterId cluster;
      76          83 :                 ReturnErrorOnFailure(reader.Get(cluster));
      77          83 :                 PRETTY_PRINT("\tCluster = 0x%" PRIx32 ",", cluster);
      78             :             }
      79             : #endif // CHIP_DETAIL_LOGGING
      80          83 :             break;
      81           0 :         default:
      82           0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
      83           0 :             break;
      84             :         }
      85             :     }
      86             : 
      87          83 :     PRETTY_PRINT("}");
      88          83 :     PRETTY_PRINT("\t");
      89             :     // if we have exhausted this container
      90          83 :     if (CHIP_END_OF_TLV == err)
      91             :     {
      92          83 :         err = CHIP_NO_ERROR;
      93             :     }
      94             : 
      95          83 :     ReturnErrorOnFailure(err);
      96          83 :     return reader.ExitContainer(mOuterContainerType);
      97             : }
      98             : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
      99             : 
     100           1 : CHIP_ERROR ClusterPathIB::Parser::GetNode(NodeId * const apNode) const
     101             : {
     102           1 :     return GetUnsignedInteger(to_underlying(Tag::kNode), apNode);
     103             : }
     104             : 
     105          79 : CHIP_ERROR ClusterPathIB::Parser::GetEndpoint(EndpointId * const apEndpoint) const
     106             : {
     107          79 :     return GetUnsignedInteger(to_underlying(Tag::kEndpoint), apEndpoint);
     108             : }
     109             : 
     110          79 : CHIP_ERROR ClusterPathIB::Parser::GetCluster(ClusterId * const apCluster) const
     111             : {
     112          79 :     return GetUnsignedInteger(to_underlying(Tag::kCluster), apCluster);
     113             : }
     114             : 
     115           5 : ClusterPathIB::Builder & ClusterPathIB::Builder::Node(const NodeId aNode)
     116             : {
     117             :     // skip if error has already been set
     118           5 :     if (mError == CHIP_NO_ERROR)
     119             :     {
     120           5 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kNode), aNode);
     121             :     }
     122           5 :     return *this;
     123             : }
     124             : 
     125         579 : ClusterPathIB::Builder & ClusterPathIB::Builder::Endpoint(const EndpointId aEndpoint)
     126             : {
     127             :     // skip if error has already been set
     128         579 :     if (mError == CHIP_NO_ERROR)
     129             :     {
     130         579 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kEndpoint), aEndpoint);
     131             :     }
     132         579 :     return *this;
     133             : }
     134             : 
     135         579 : ClusterPathIB::Builder & ClusterPathIB::Builder::Cluster(const ClusterId aCluster)
     136             : {
     137             :     // skip if error has already been set
     138         579 :     if (mError == CHIP_NO_ERROR)
     139             :     {
     140         552 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kCluster), aCluster);
     141             :     }
     142         579 :     return *this;
     143             : }
     144             : 
     145         579 : CHIP_ERROR ClusterPathIB::Builder::EndOfClusterPathIB()
     146             : {
     147         579 :     EndOfContainer();
     148         579 :     return GetError();
     149             : }
     150             : } // namespace app
     151             : } // namespace chip

Generated by: LCOV version 1.14