LCOV - code coverage report
Current view: top level - protocols - Protocols.cpp (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 39 50 78.0 %
Date: 2024-02-15 08:20:41 Functions: 3 3 100.0 %

          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       19015 : static const char * LookupMessageTypeName(const MessageTypeNameLookup * lookupTable, size_t tableSize, uint8_t msgType)
      30             : {
      31       83335 :     for (auto ptr = lookupTable; ptr != (lookupTable + tableSize); ptr++)
      32             :     {
      33       83335 :         if (ptr->mId == msgType)
      34             :         {
      35       19015 :             return ptr->mName;
      36             :         }
      37             :     }
      38             : 
      39           0 :     return sUnknownTypeName;
      40             : }
      41             : 
      42       19058 : const char * GetProtocolName(Id protocolId)
      43             : {
      44       19058 :     if (protocolId.GetVendorId() != VendorId::Common)
      45             :     {
      46          43 :         return sUnknownTypeName;
      47             :     }
      48             : 
      49       19015 :     switch (protocolId.GetProtocolId())
      50             :     {
      51       15609 :     case InteractionModel::Id.GetProtocolId():
      52       15609 :         return InteractionModel::kProtocolName;
      53             :         break;
      54             : 
      55        3208 :     case SecureChannel::Id.GetProtocolId():
      56        3208 :         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       19058 : const char * GetMessageTypeName(Id protocolId, uint8_t msgType)
      77             : {
      78       19058 :     if (protocolId.GetVendorId() != VendorId::Common)
      79             :     {
      80          43 :         return sUnknownTypeName;
      81             :     }
      82             : 
      83       19015 :     const MessageTypeNameLookup * lookupTable = nullptr;
      84       19015 :     size_t lookupTableSize                    = 0;
      85             : 
      86       19015 :     switch (protocolId.GetProtocolId())
      87             :     {
      88       15609 :     case InteractionModel::Id.GetProtocolId():
      89       15609 :         lookupTable     = MessageTypeTraits<InteractionModel::MsgType>::GetTypeToNameTable()->begin();
      90       15609 :         lookupTableSize = MessageTypeTraits<InteractionModel::MsgType>::GetTypeToNameTable()->size();
      91       15609 :         break;
      92             : 
      93        3208 :     case SecureChannel::Id.GetProtocolId():
      94        3208 :         lookupTable     = MessageTypeTraits<SecureChannel::MsgType>::GetTypeToNameTable()->begin();
      95        3208 :         lookupTableSize = MessageTypeTraits<SecureChannel::MsgType>::GetTypeToNameTable()->size();
      96        3208 :         break;
      97             : 
      98           8 :     case BDX::Id.GetProtocolId():
      99           8 :         lookupTable     = MessageTypeTraits<bdx::MessageType>::GetTypeToNameTable()->begin();
     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()->begin();
     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()->begin();
     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       19015 :     return LookupMessageTypeName(lookupTable, lookupTableSize, msgType);
     122             : }
     123             : 
     124             : } // namespace Protocols
     125             : } // namespace chip

Generated by: LCOV version 1.14