Matter SDK Coverage Report
Current view: top level - app/data-model-provider - MetadataLookup.cpp (source / functions) Coverage Total Hit
Test: SHA:4d2388ac7eed75b2fe5e05e20de377999c632502 Lines: 100.0 % 27 27
Test Date: 2025-07-27 07:17:09 Functions: 100.0 % 3 3

            Line data    Source code
       1              : /*
       2              :  *    Copyright (c) 2024 Project CHIP Authors
       3              :  *
       4              :  *    Licensed under the Apache License, Version 2.0 (the "License");
       5              :  *    you may not use this file except in compliance with the License.
       6              :  *    You may obtain a copy of the License at
       7              :  *
       8              :  *        http://www.apache.org/licenses/LICENSE-2.0
       9              :  *
      10              :  *    Unless required by applicable law or agreed to in writing, software
      11              :  *    distributed under the License is distributed on an "AS IS" BASIS,
      12              :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13              :  *    See the License for the specific language governing permissions and
      14              :  *    limitations under the License.
      15              :  */
      16              : #include <app/data-model-provider/MetadataLookup.h>
      17              : 
      18              : #include <lib/support/ReadOnlyBuffer.h>
      19              : 
      20              : namespace chip {
      21              : namespace app {
      22              : namespace DataModel {
      23              : 
      24              : using Protocols::InteractionModel::Status;
      25              : 
      26         5114 : std::optional<ServerClusterEntry> ServerClusterFinder::Find(const ConcreteClusterPath & path)
      27              : {
      28         5114 :     VerifyOrReturnValue(mProvider != nullptr, std::nullopt);
      29              : 
      30         5114 :     if (mEndpointId != path.mEndpointId)
      31              :     {
      32         5114 :         mEndpointId     = path.mEndpointId;
      33         5114 :         mClusterEntries = mProvider->ServerClustersIgnoreError(path.mEndpointId);
      34              :     }
      35              : 
      36         6523 :     for (auto & clusterEntry : mClusterEntries)
      37              :     {
      38         6515 :         if (clusterEntry.clusterId == path.mClusterId)
      39              :         {
      40         5106 :             return clusterEntry;
      41              :         }
      42              :     }
      43              : 
      44            8 :     return std::nullopt;
      45              : }
      46              : 
      47        14466 : std::optional<AttributeEntry> AttributeFinder::Find(const ConcreteAttributePath & path)
      48              : {
      49        14466 :     VerifyOrReturnValue(mProvider != nullptr, std::nullopt);
      50              : 
      51        14466 :     if (mClusterPath != path)
      52              :     {
      53        14460 :         mClusterPath = path;
      54        14460 :         mAttributes  = mProvider->AttributesIgnoreError(path);
      55              :     }
      56              : 
      57        38933 :     for (auto & attributeEntry : mAttributes)
      58              :     {
      59        38875 :         if (attributeEntry.attributeId == path.mAttributeId)
      60              :         {
      61        14408 :             return attributeEntry;
      62              :         }
      63              :     }
      64              : 
      65           58 :     return std::nullopt;
      66              : }
      67              : 
      68           68 : Protocols::InteractionModel::Status ValidateClusterPath(ProviderMetadataTree * provider, const ConcreteClusterPath & path,
      69              :                                                         Protocols::InteractionModel::Status successStatus)
      70              : {
      71           68 :     if (ServerClusterFinder(provider).Find(path).has_value())
      72              :     {
      73           62 :         return successStatus;
      74              :     }
      75              : 
      76              :     // If we get here, the cluster identified by the path does not exist.
      77            6 :     auto endpoints = provider->EndpointsIgnoreError();
      78           10 :     for (auto & endpointEntry : endpoints)
      79              :     {
      80            7 :         if (endpointEntry.id == path.mEndpointId)
      81              :         {
      82              :             // endpoint is valid
      83            3 :             return Protocols::InteractionModel::Status::UnsupportedCluster;
      84              :         }
      85              :     }
      86              : 
      87            3 :     return Protocols::InteractionModel::Status::UnsupportedEndpoint;
      88            6 : }
      89              : 
      90              : } // namespace DataModel
      91              : } // namespace app
      92              : } // namespace chip
        

Generated by: LCOV version 2.0-1