Matter SDK Coverage Report
Current view: top level - app/MessageDef - CommandPathIB.cpp (source / functions) Coverage Total Hit
Test: SHA:e98a48c2e59f85a25417956e1d105721433aa5d1 Lines: 94.6 % 74 70
Test Date: 2026-01-09 16:53:50 Functions: 100.0 % 12 12

            Line data    Source code
       1              : /**
       2              :  *
       3              :  *    Copyright (c) 2020 Project CHIP Authors
       4              :  *    Copyright (c) 2018 Google LLC.
       5              :  *    Copyright (c) 2016-2017 Nest Labs, Inc.
       6              :  *    Licensed under the Apache License, Version 2.0 (the "License");
       7              :  *    you may not use this file except in compliance with the License.
       8              :  *    You may obtain a copy of the License at
       9              :  *
      10              :  *        http://www.apache.org/licenses/LICENSE-2.0
      11              :  *
      12              :  *    Unless required by applicable law or agreed to in writing, software
      13              :  *    distributed under the License is distributed on an "AS IS" BASIS,
      14              :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      15              :  *    See the License for the specific language governing permissions and
      16              :  *    limitations under the License.
      17              :  */
      18              : 
      19              : #include "CommandPathIB.h"
      20              : 
      21              : #include "MessageDefHelper.h"
      22              : 
      23              : #include <inttypes.h>
      24              : #include <stdarg.h>
      25              : #include <stdio.h>
      26              : 
      27              : #include <app/AppConfig.h>
      28              : 
      29              : #include <protocols/interaction_model/Constants.h>
      30              : 
      31              : using namespace chip;
      32              : using namespace chip::TLV;
      33              : 
      34              : namespace chip {
      35              : namespace app {
      36              : #if CHIP_CONFIG_IM_PRETTY_PRINT
      37          134 : CHIP_ERROR CommandPathIB::Parser::PrettyPrint() const
      38              : {
      39          134 :     CHIP_ERROR err = CHIP_NO_ERROR;
      40          134 :     TLV::TLVReader reader;
      41          134 :     PRETTY_PRINT("CommandPathIB =");
      42          134 :     PRETTY_PRINT("{");
      43              : 
      44              :     // make a copy of the Path reader
      45          134 :     reader.Init(mReader);
      46              : 
      47         1072 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      48              :     {
      49          402 :         if (!TLV::IsContextTag(reader.GetTag()))
      50              :         {
      51            0 :             continue;
      52              :         }
      53          402 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      54          402 :         switch (tagNum)
      55              :         {
      56          134 :         case to_underlying(Tag::kEndpointId):
      57          134 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      58              : 
      59              : #if CHIP_DETAIL_LOGGING
      60              :             {
      61              :                 uint16_t endpointId;
      62          134 :                 ReturnErrorOnFailure(reader.Get(endpointId));
      63          134 :                 PRETTY_PRINT("\tEndpointId = 0x%x,", endpointId);
      64              :             }
      65              : #endif // CHIP_DETAIL_LOGGING
      66          134 :             break;
      67          134 :         case to_underlying(Tag::kClusterId):
      68          134 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      69              : #if CHIP_DETAIL_LOGGING
      70              :             {
      71              :                 chip::ClusterId clusterId;
      72          134 :                 ReturnErrorOnFailure(reader.Get(clusterId));
      73          134 :                 PRETTY_PRINT("\tClusterId = 0x%" PRIx32 ",", clusterId);
      74              :             }
      75              : #endif // CHIP_DETAIL_LOGGING
      76          134 :             break;
      77          134 :         case to_underlying(Tag::kCommandId):
      78          134 :             VerifyOrReturnError(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      79              : #if CHIP_DETAIL_LOGGING
      80              :             {
      81              :                 chip::CommandId commandId;
      82          134 :                 ReturnErrorOnFailure(reader.Get(commandId));
      83          134 :                 PRETTY_PRINT("\tCommandId = 0x%" PRIx32 ",", commandId);
      84              :             }
      85              : #endif // CHIP_DETAIL_LOGGING
      86          134 :             break;
      87            0 :         default:
      88            0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
      89            0 :             break;
      90              :         }
      91              :     }
      92          134 :     PRETTY_PRINT("},");
      93          134 :     PRETTY_PRINT_BLANK_LINE();
      94              :     // if we have exhausted this container
      95          268 :     if (CHIP_END_OF_TLV == err)
      96              :     {
      97          134 :         err = CHIP_NO_ERROR;
      98              :     }
      99          134 :     ReturnErrorOnFailure(err);
     100          134 :     return reader.ExitContainer(mOuterContainerType);
     101              : }
     102              : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
     103              : 
     104          172 : CHIP_ERROR CommandPathIB::Parser::GetEndpointId(chip::EndpointId * const apEndpointID) const
     105              : {
     106          172 :     return GetUnsignedInteger(to_underlying(Tag::kEndpointId), apEndpointID);
     107              : }
     108              : 
     109          173 : CHIP_ERROR CommandPathIB::Parser::GetClusterId(chip::ClusterId * const apClusterId) const
     110              : {
     111          173 :     return GetUnsignedInteger(to_underlying(Tag::kClusterId), apClusterId);
     112              : }
     113              : 
     114          172 : CHIP_ERROR CommandPathIB::Parser::GetCommandId(chip::CommandId * const apCommandId) const
     115              : {
     116          172 :     return GetUnsignedInteger(to_underlying(Tag::kCommandId), apCommandId);
     117              : }
     118              : 
     119          110 : CHIP_ERROR CommandPathIB::Parser::GetConcreteCommandPath(ConcreteCommandPath & aCommandPath) const
     120              : {
     121          110 :     ReturnErrorOnFailure(GetGroupCommandPath(&aCommandPath.mClusterId, &aCommandPath.mCommandId));
     122              : 
     123          109 :     return GetEndpointId(&aCommandPath.mEndpointId);
     124              : }
     125              : 
     126          110 : CHIP_ERROR CommandPathIB::Parser::GetGroupCommandPath(ClusterId * apClusterId, CommandId * apCommandId) const
     127              : {
     128          110 :     ReturnErrorOnFailure(GetClusterId(apClusterId));
     129          110 :     VerifyOrReturnError(IsValidClusterId(*apClusterId), CHIP_IM_GLOBAL_STATUS(InvalidAction));
     130              : 
     131          109 :     ReturnErrorOnFailure(GetCommandId(apCommandId));
     132          109 :     VerifyOrReturnError(IsValidCommandId(*apCommandId), CHIP_IM_GLOBAL_STATUS(InvalidAction));
     133              : 
     134          109 :     return CHIP_NO_ERROR;
     135              : }
     136              : 
     137          168 : CommandPathIB::Builder & CommandPathIB::Builder::EndpointId(const chip::EndpointId aEndpointId)
     138              : {
     139              :     // skip if error has already been set
     140          336 :     if (mError == CHIP_NO_ERROR)
     141              :     {
     142          168 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kEndpointId), aEndpointId);
     143              :     }
     144          168 :     return *this;
     145              : }
     146              : 
     147          168 : CommandPathIB::Builder & CommandPathIB::Builder::ClusterId(const chip::ClusterId aClusterId)
     148              : {
     149              :     // skip if error has already been set
     150          336 :     if (mError == CHIP_NO_ERROR)
     151              :     {
     152          168 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kClusterId), aClusterId);
     153              :     }
     154          168 :     return *this;
     155              : }
     156              : 
     157          168 : CommandPathIB::Builder & CommandPathIB::Builder::CommandId(const chip::CommandId aCommandId)
     158              : {
     159              :     // skip if error has already been set
     160          336 :     if (mError == CHIP_NO_ERROR)
     161              :     {
     162          168 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kCommandId), aCommandId);
     163              :     }
     164          168 :     return *this;
     165              : }
     166              : 
     167          168 : CHIP_ERROR CommandPathIB::Builder::EndOfCommandPathIB()
     168              : {
     169          168 :     EndOfContainer();
     170          168 :     return GetError();
     171              : }
     172              : 
     173           64 : CHIP_ERROR CommandPathIB::Builder::Encode(const CommandPathParams & aCommandPathParams)
     174              : {
     175           64 :     if (aCommandPathParams.mFlags.Has(CommandPathFlags::kEndpointIdValid))
     176              :     {
     177           64 :         EndpointId(aCommandPathParams.mEndpointId);
     178              :     }
     179              : 
     180           64 :     return ClusterId(aCommandPathParams.mClusterId).CommandId(aCommandPathParams.mCommandId).EndOfCommandPathIB();
     181              : }
     182              : 
     183           86 : CHIP_ERROR CommandPathIB::Builder::Encode(const ConcreteCommandPath & aConcreteCommandPath)
     184              : {
     185           86 :     return EndpointId(aConcreteCommandPath.mEndpointId)
     186           86 :         .ClusterId(aConcreteCommandPath.mClusterId)
     187           86 :         .CommandId(aConcreteCommandPath.mCommandId)
     188           86 :         .EndOfCommandPathIB();
     189              : }
     190              : 
     191              : }; // namespace app
     192              : }; // namespace chip
        

Generated by: LCOV version 2.0-1