Matter SDK Coverage Report
Current view: top level - app/MessageDef - CommandPathIB.cpp (source / functions) Coverage Total Hit
Test: SHA:860799f81127706a2ea9ce42dc8cca99748a4fde Lines: 94.6 % 74 70
Test Date: 2025-07-06 07:09:48 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           91 : CHIP_ERROR CommandPathIB::Parser::PrettyPrint() const
      38              : {
      39           91 :     CHIP_ERROR err = CHIP_NO_ERROR;
      40           91 :     TLV::TLVReader reader;
      41           91 :     PRETTY_PRINT("CommandPathIB =");
      42           91 :     PRETTY_PRINT("{");
      43              : 
      44              :     // make a copy of the Path reader
      45           91 :     reader.Init(mReader);
      46              : 
      47          364 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      48              :     {
      49          273 :         if (!TLV::IsContextTag(reader.GetTag()))
      50              :         {
      51            0 :             continue;
      52              :         }
      53          273 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      54          273 :         switch (tagNum)
      55              :         {
      56           91 :         case to_underlying(Tag::kEndpointId):
      57           91 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      58              : 
      59              : #if CHIP_DETAIL_LOGGING
      60              :             {
      61              :                 uint16_t endpointId;
      62           91 :                 ReturnErrorOnFailure(reader.Get(endpointId));
      63           91 :                 PRETTY_PRINT("\tEndpointId = 0x%x,", endpointId);
      64              :             }
      65              : #endif // CHIP_DETAIL_LOGGING
      66           91 :             break;
      67           91 :         case to_underlying(Tag::kClusterId):
      68           91 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      69              : #if CHIP_DETAIL_LOGGING
      70              :             {
      71              :                 chip::ClusterId clusterId;
      72           91 :                 ReturnErrorOnFailure(reader.Get(clusterId));
      73           91 :                 PRETTY_PRINT("\tClusterId = 0x%" PRIx32 ",", clusterId);
      74              :             }
      75              : #endif // CHIP_DETAIL_LOGGING
      76           91 :             break;
      77           91 :         case to_underlying(Tag::kCommandId):
      78           91 :             VerifyOrReturnError(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      79              : #if CHIP_DETAIL_LOGGING
      80              :             {
      81              :                 chip::CommandId commandId;
      82           91 :                 ReturnErrorOnFailure(reader.Get(commandId));
      83           91 :                 PRETTY_PRINT("\tCommandId = 0x%" PRIx32 ",", commandId);
      84              :             }
      85              : #endif // CHIP_DETAIL_LOGGING
      86           91 :             break;
      87            0 :         default:
      88            0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
      89            0 :             break;
      90              :         }
      91              :     }
      92           91 :     PRETTY_PRINT("},");
      93           91 :     PRETTY_PRINT_BLANK_LINE();
      94              :     // if we have exhausted this container
      95           91 :     if (CHIP_END_OF_TLV == err)
      96              :     {
      97           91 :         err = CHIP_NO_ERROR;
      98              :     }
      99           91 :     ReturnErrorOnFailure(err);
     100           91 :     return reader.ExitContainer(mOuterContainerType);
     101              : }
     102              : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
     103              : 
     104          112 : CHIP_ERROR CommandPathIB::Parser::GetEndpointId(chip::EndpointId * const apEndpointID) const
     105              : {
     106          112 :     return GetUnsignedInteger(to_underlying(Tag::kEndpointId), apEndpointID);
     107              : }
     108              : 
     109          113 : CHIP_ERROR CommandPathIB::Parser::GetClusterId(chip::ClusterId * const apClusterId) const
     110              : {
     111          113 :     return GetUnsignedInteger(to_underlying(Tag::kClusterId), apClusterId);
     112              : }
     113              : 
     114          112 : CHIP_ERROR CommandPathIB::Parser::GetCommandId(chip::CommandId * const apCommandId) const
     115              : {
     116          112 :     return GetUnsignedInteger(to_underlying(Tag::kCommandId), apCommandId);
     117              : }
     118              : 
     119           76 : CHIP_ERROR CommandPathIB::Parser::GetConcreteCommandPath(ConcreteCommandPath & aCommandPath) const
     120              : {
     121           76 :     ReturnErrorOnFailure(GetGroupCommandPath(&aCommandPath.mClusterId, &aCommandPath.mCommandId));
     122              : 
     123           75 :     return GetEndpointId(&aCommandPath.mEndpointId);
     124              : }
     125              : 
     126           76 : CHIP_ERROR CommandPathIB::Parser::GetGroupCommandPath(ClusterId * apClusterId, CommandId * apCommandId) const
     127              : {
     128           76 :     ReturnErrorOnFailure(GetClusterId(apClusterId));
     129           76 :     VerifyOrReturnError(IsValidClusterId(*apClusterId), CHIP_IM_GLOBAL_STATUS(InvalidAction));
     130              : 
     131           75 :     ReturnErrorOnFailure(GetCommandId(apCommandId));
     132           75 :     VerifyOrReturnError(IsValidCommandId(*apCommandId), CHIP_IM_GLOBAL_STATUS(InvalidAction));
     133              : 
     134           75 :     return CHIP_NO_ERROR;
     135              : }
     136              : 
     137          124 : CommandPathIB::Builder & CommandPathIB::Builder::EndpointId(const chip::EndpointId aEndpointId)
     138              : {
     139              :     // skip if error has already been set
     140          124 :     if (mError == CHIP_NO_ERROR)
     141              :     {
     142          124 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kEndpointId), aEndpointId);
     143              :     }
     144          124 :     return *this;
     145              : }
     146              : 
     147          124 : CommandPathIB::Builder & CommandPathIB::Builder::ClusterId(const chip::ClusterId aClusterId)
     148              : {
     149              :     // skip if error has already been set
     150          124 :     if (mError == CHIP_NO_ERROR)
     151              :     {
     152          124 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kClusterId), aClusterId);
     153              :     }
     154          124 :     return *this;
     155              : }
     156              : 
     157          124 : CommandPathIB::Builder & CommandPathIB::Builder::CommandId(const chip::CommandId aCommandId)
     158              : {
     159              :     // skip if error has already been set
     160          124 :     if (mError == CHIP_NO_ERROR)
     161              :     {
     162          124 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kCommandId), aCommandId);
     163              :     }
     164          124 :     return *this;
     165              : }
     166              : 
     167          124 : CHIP_ERROR CommandPathIB::Builder::EndOfCommandPathIB()
     168              : {
     169          124 :     EndOfContainer();
     170          124 :     return GetError();
     171              : }
     172              : 
     173           46 : CHIP_ERROR CommandPathIB::Builder::Encode(const CommandPathParams & aCommandPathParams)
     174              : {
     175           46 :     if (aCommandPathParams.mFlags.Has(CommandPathFlags::kEndpointIdValid))
     176              :     {
     177           46 :         EndpointId(aCommandPathParams.mEndpointId);
     178              :     }
     179              : 
     180           46 :     return ClusterId(aCommandPathParams.mClusterId).CommandId(aCommandPathParams.mCommandId).EndOfCommandPathIB();
     181              : }
     182              : 
     183           60 : CHIP_ERROR CommandPathIB::Builder::Encode(const ConcreteCommandPath & aConcreteCommandPath)
     184              : {
     185           60 :     return EndpointId(aConcreteCommandPath.mEndpointId)
     186           60 :         .ClusterId(aConcreteCommandPath.mClusterId)
     187           60 :         .CommandId(aConcreteCommandPath.mCommandId)
     188           60 :         .EndOfCommandPathIB();
     189              : }
     190              : 
     191              : }; // namespace app
     192              : }; // namespace chip
        

Generated by: LCOV version 2.0-1