Matter SDK Coverage Report
Current view: top level - protocols - Protocols.cpp (source / functions) Coverage Total Hit
Test: SHA:b879ecb8e99e175eea0a293a888bda853da2b19c Lines: 80.0 % 50 40
Test Date: 2025-01-17 19:00:11 Functions: 100.0 % 3 3

            Line data    Source code
       1              : /*
       2              :  *    Copyright (c) 2022 Project CHIP Authors
       3              :  *    All rights reserved.
       4              :  *
       5              :  *    Licensed under the Apache License, Version 2.0 (the "License");
       6              :  *    you may not use this file except in compliance with the License.
       7              :  *    You may obtain a copy of the License at
       8              :  *
       9              :  *        http://www.apache.org/licenses/LICENSE-2.0
      10              :  *
      11              :  *    Unless required by applicable law or agreed to in writing, software
      12              :  *    distributed under the License is distributed on an "AS IS" BASIS,
      13              :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14              :  *    See the License for the specific language governing permissions and
      15              :  *    limitations under the License.
      16              :  */
      17              : 
      18              : #include <protocols/bdx/BdxMessages.h>
      19              : #include <protocols/echo/Echo.h>
      20              : #include <protocols/interaction_model/Constants.h>
      21              : #include <protocols/secure_channel/Constants.h>
      22              : #include <protocols/user_directed_commissioning/UserDirectedCommissioning.h>
      23              : 
      24              : namespace chip {
      25              : namespace Protocols {
      26              : 
      27              : static const char sUnknownTypeName[] = "----";
      28              : 
      29        19492 : static const char * LookupMessageTypeName(const MessageTypeNameLookup * lookupTable, size_t tableSize, uint8_t msgType)
      30              : {
      31        85138 :     for (auto ptr = lookupTable; ptr != (lookupTable + tableSize); ptr++)
      32              :     {
      33        85126 :         if (ptr->mId == msgType)
      34              :         {
      35        19480 :             return ptr->mName;
      36              :         }
      37              :     }
      38              : 
      39           12 :     return sUnknownTypeName;
      40              : }
      41              : 
      42        19535 : const char * GetProtocolName(Id protocolId)
      43              : {
      44        19535 :     if (protocolId.GetVendorId() != VendorId::Common)
      45              :     {
      46           43 :         return sUnknownTypeName;
      47              :     }
      48              : 
      49        19492 :     switch (protocolId.GetProtocolId())
      50              :     {
      51        15924 :     case InteractionModel::Id.GetProtocolId():
      52        15924 :         return InteractionModel::kProtocolName;
      53              :         break;
      54              : 
      55         3370 :     case SecureChannel::Id.GetProtocolId():
      56         3370 :         return SecureChannel::kProtocolName;
      57              :         break;
      58              : 
      59            8 :     case BDX::Id.GetProtocolId():
      60            8 :         return bdx::kProtocolName;
      61              :         break;
      62              : 
      63          190 :     case Echo::Id.GetProtocolId():
      64          190 :         return Echo::kProtocolName;
      65              :         break;
      66              : 
      67            0 :     case UserDirectedCommissioning::Id.GetProtocolId():
      68            0 :         return UserDirectedCommissioning::kProtocolName;
      69              :         break;
      70              : 
      71            0 :     default:
      72            0 :         return sUnknownTypeName;
      73              :     }
      74              : }
      75              : 
      76        19535 : const char * GetMessageTypeName(Id protocolId, uint8_t msgType)
      77              : {
      78        19535 :     if (protocolId.GetVendorId() != VendorId::Common)
      79              :     {
      80           43 :         return sUnknownTypeName;
      81              :     }
      82              : 
      83        19492 :     const MessageTypeNameLookup * lookupTable = nullptr;
      84        19492 :     size_t lookupTableSize                    = 0;
      85              : 
      86        19492 :     switch (protocolId.GetProtocolId())
      87              :     {
      88        15924 :     case InteractionModel::Id.GetProtocolId():
      89        15924 :         lookupTable     = MessageTypeTraits<InteractionModel::MsgType>::GetTypeToNameTable()->data();
      90        15924 :         lookupTableSize = MessageTypeTraits<InteractionModel::MsgType>::GetTypeToNameTable()->size();
      91        15924 :         break;
      92              : 
      93         3370 :     case SecureChannel::Id.GetProtocolId():
      94         3370 :         lookupTable     = MessageTypeTraits<SecureChannel::MsgType>::GetTypeToNameTable()->data();
      95         3370 :         lookupTableSize = MessageTypeTraits<SecureChannel::MsgType>::GetTypeToNameTable()->size();
      96         3370 :         break;
      97              : 
      98            8 :     case BDX::Id.GetProtocolId():
      99            8 :         lookupTable     = MessageTypeTraits<bdx::MessageType>::GetTypeToNameTable()->data();
     100            8 :         lookupTableSize = MessageTypeTraits<bdx::MessageType>::GetTypeToNameTable()->size();
     101            8 :         break;
     102              : 
     103          190 :     case Echo::Id.GetProtocolId():
     104          190 :         lookupTable     = MessageTypeTraits<Echo::MsgType>::GetTypeToNameTable()->data();
     105          190 :         lookupTableSize = MessageTypeTraits<Echo::MsgType>::GetTypeToNameTable()->size();
     106          190 :         break;
     107              : 
     108            0 :     case UserDirectedCommissioning::Id.GetProtocolId():
     109            0 :         lookupTable     = MessageTypeTraits<UserDirectedCommissioning::MsgType>::GetTypeToNameTable()->data();
     110            0 :         lookupTableSize = MessageTypeTraits<UserDirectedCommissioning::MsgType>::GetTypeToNameTable()->size();
     111            0 :         break;
     112              : 
     113            0 :     default:
     114              :         //
     115              :         // TODO: Add support at some point to let applications to route to custom protocols defined outside of the standard
     116              :         // namespace in the SDK.
     117              :         //
     118            0 :         return sUnknownTypeName;
     119              :     }
     120              : 
     121        19492 :     return LookupMessageTypeName(lookupTable, lookupTableSize, msgType);
     122              : }
     123              : 
     124              : } // namespace Protocols
     125              : } // namespace chip
        

Generated by: LCOV version 2.0-1