Matter SDK Coverage Report
Current view: top level - protocols - Protocols.cpp (source / functions) Coverage Total Hit
Test: SHA:f84fe08d06f240e801b5d923f8a938a9938ca110 Lines: 80.0 % 50 40
Test Date: 2025-02-22 08:08:07 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        20169 : static const char * LookupMessageTypeName(const MessageTypeNameLookup * lookupTable, size_t tableSize, uint8_t msgType)
      30              : {
      31        87287 :     for (auto ptr = lookupTable; ptr != (lookupTable + tableSize); ptr++)
      32              :     {
      33        87275 :         if (ptr->mId == msgType)
      34              :         {
      35        20157 :             return ptr->mName;
      36              :         }
      37              :     }
      38              : 
      39           12 :     return sUnknownTypeName;
      40              : }
      41              : 
      42        20212 : const char * GetProtocolName(Id protocolId)
      43              : {
      44        20212 :     if (protocolId.GetVendorId() != VendorId::Common)
      45              :     {
      46           43 :         return sUnknownTypeName;
      47              :     }
      48              : 
      49        20169 :     switch (protocolId.GetProtocolId())
      50              :     {
      51        16456 :     case InteractionModel::Id.GetProtocolId():
      52        16456 :         return InteractionModel::kProtocolName;
      53              :         break;
      54              : 
      55         3508 :     case SecureChannel::Id.GetProtocolId():
      56         3508 :         return SecureChannel::kProtocolName;
      57              :         break;
      58              : 
      59            8 :     case BDX::Id.GetProtocolId():
      60            8 :         return bdx::kProtocolName;
      61              :         break;
      62              : 
      63          197 :     case Echo::Id.GetProtocolId():
      64          197 :         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        20212 : const char * GetMessageTypeName(Id protocolId, uint8_t msgType)
      77              : {
      78        20212 :     if (protocolId.GetVendorId() != VendorId::Common)
      79              :     {
      80           43 :         return sUnknownTypeName;
      81              :     }
      82              : 
      83        20169 :     const MessageTypeNameLookup * lookupTable = nullptr;
      84        20169 :     size_t lookupTableSize                    = 0;
      85              : 
      86        20169 :     switch (protocolId.GetProtocolId())
      87              :     {
      88        16456 :     case InteractionModel::Id.GetProtocolId():
      89        16456 :         lookupTable     = MessageTypeTraits<InteractionModel::MsgType>::GetTypeToNameTable()->data();
      90        16456 :         lookupTableSize = MessageTypeTraits<InteractionModel::MsgType>::GetTypeToNameTable()->size();
      91        16456 :         break;
      92              : 
      93         3508 :     case SecureChannel::Id.GetProtocolId():
      94         3508 :         lookupTable     = MessageTypeTraits<SecureChannel::MsgType>::GetTypeToNameTable()->data();
      95         3508 :         lookupTableSize = MessageTypeTraits<SecureChannel::MsgType>::GetTypeToNameTable()->size();
      96         3508 :         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          197 :     case Echo::Id.GetProtocolId():
     104          197 :         lookupTable     = MessageTypeTraits<Echo::MsgType>::GetTypeToNameTable()->data();
     105          197 :         lookupTableSize = MessageTypeTraits<Echo::MsgType>::GetTypeToNameTable()->size();
     106          197 :         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        20169 :     return LookupMessageTypeName(lookupTable, lookupTableSize, msgType);
     122              : }
     123              : 
     124              : } // namespace Protocols
     125              : } // namespace chip
        

Generated by: LCOV version 2.0-1