Matter SDK Coverage Report
Current view: top level - app/util - privilege-storage.cpp (source / functions) Coverage Total Hit
Test: SHA:b879ecb8e99e175eea0a293a888bda853da2b19c Lines: 100.0 % 8 8
Test Date: 2025-01-17 19:00:11 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /**
       2              :  *
       3              :  *    Copyright (c) 2022 Project CHIP Authors
       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 <lib/core/CHIPConfig.h>
      19              : 
      20              : #include "privilege-storage.h"
      21              : 
      22              : #if !CHIP_CONFIG_SKIP_APP_SPECIFIC_GENERATED_HEADER_INCLUDES
      23              : #include <zap-generated/access.h>
      24              : #endif // !CHIP_CONFIG_SKIP_APP_SPECIFIC_GENERATED_HEADER_INCLUDES
      25              : 
      26              : #include <lib/support/CodeUtils.h>
      27              : 
      28              : using chip::AttributeId;
      29              : using chip::ClusterId;
      30              : using chip::CommandId;
      31              : using chip::EventId;
      32              : 
      33              : namespace {
      34              : 
      35              : #ifdef GENERATED_ACCESS_READ_ATTRIBUTE__CLUSTER
      36              : namespace GeneratedAccessReadAttribute {
      37              : constexpr ClusterId kCluster[]                 = GENERATED_ACCESS_READ_ATTRIBUTE__CLUSTER;
      38              : constexpr AttributeId kAttribute[]             = GENERATED_ACCESS_READ_ATTRIBUTE__ATTRIBUTE;
      39              : constexpr chip::Access::Privilege kPrivilege[] = GENERATED_ACCESS_READ_ATTRIBUTE__PRIVILEGE;
      40              : static_assert(ArraySize(kCluster) == ArraySize(kAttribute) && ArraySize(kAttribute) == ArraySize(kPrivilege),
      41              :               "Generated parallel arrays must be same size");
      42              : } // namespace GeneratedAccessReadAttribute
      43              : #endif
      44              : 
      45              : #ifdef GENERATED_ACCESS_WRITE_ATTRIBUTE__CLUSTER
      46              : namespace GeneratedAccessWriteAttribute {
      47              : constexpr ClusterId kCluster[]                 = GENERATED_ACCESS_WRITE_ATTRIBUTE__CLUSTER;
      48              : constexpr AttributeId kAttribute[]             = GENERATED_ACCESS_WRITE_ATTRIBUTE__ATTRIBUTE;
      49              : constexpr chip::Access::Privilege kPrivilege[] = GENERATED_ACCESS_WRITE_ATTRIBUTE__PRIVILEGE;
      50              : static_assert(ArraySize(kCluster) == ArraySize(kAttribute) && ArraySize(kAttribute) == ArraySize(kPrivilege),
      51              :               "Generated parallel arrays must be same size");
      52              : } // namespace GeneratedAccessWriteAttribute
      53              : #endif
      54              : 
      55              : #ifdef GENERATED_ACCESS_INVOKE_COMMAND__CLUSTER
      56              : namespace GeneratedAccessInvokeCommand {
      57              : constexpr ClusterId kCluster[]                 = GENERATED_ACCESS_INVOKE_COMMAND__CLUSTER;
      58              : constexpr CommandId kCommand[]                 = GENERATED_ACCESS_INVOKE_COMMAND__COMMAND;
      59              : constexpr chip::Access::Privilege kPrivilege[] = GENERATED_ACCESS_INVOKE_COMMAND__PRIVILEGE;
      60              : static_assert(ArraySize(kCluster) == ArraySize(kCommand) && ArraySize(kCommand) == ArraySize(kPrivilege),
      61              :               "Generated parallel arrays must be same size");
      62              : } // namespace GeneratedAccessInvokeCommand
      63              : #endif
      64              : 
      65              : #ifdef GENERATED_ACCESS_READ_EVENT__CLUSTER
      66              : namespace GeneratedAccessReadEvent {
      67              : constexpr ClusterId kCluster[]                 = GENERATED_ACCESS_READ_EVENT__CLUSTER;
      68              : constexpr EventId kEvent[]                     = GENERATED_ACCESS_READ_EVENT__EVENT;
      69              : constexpr chip::Access::Privilege kPrivilege[] = GENERATED_ACCESS_READ_EVENT__PRIVILEGE;
      70              : static_assert(ArraySize(kCluster) == ArraySize(kEvent) && ArraySize(kEvent) == ArraySize(kPrivilege),
      71              :               "Generated parallel arrays must be same size");
      72              : } // namespace GeneratedAccessReadEvent
      73              : #endif
      74              : 
      75              : } // anonymous namespace
      76              : 
      77         4092 : chip::Access::Privilege MatterGetAccessPrivilegeForReadAttribute(ClusterId cluster, AttributeId attribute)
      78              : {
      79              : #ifdef GENERATED_ACCESS_READ_ATTRIBUTE__CLUSTER
      80              :     using namespace GeneratedAccessReadAttribute;
      81              :     for (size_t i = 0; i < ArraySize(kCluster); ++i)
      82              :     {
      83              :         if (kCluster[i] == cluster && kAttribute[i] == attribute)
      84              :         {
      85              :             return kPrivilege[i];
      86              :         }
      87              :     }
      88              : #endif
      89         4092 :     return chip::Access::Privilege::kView;
      90              : }
      91              : 
      92         2127 : chip::Access::Privilege MatterGetAccessPrivilegeForWriteAttribute(ClusterId cluster, AttributeId attribute)
      93              : {
      94              : #ifdef GENERATED_ACCESS_WRITE_ATTRIBUTE__CLUSTER
      95              :     using namespace GeneratedAccessWriteAttribute;
      96              :     for (size_t i = 0; i < ArraySize(kCluster); ++i)
      97              :     {
      98              :         if (kCluster[i] == cluster && kAttribute[i] == attribute)
      99              :         {
     100              :             return kPrivilege[i];
     101              :         }
     102              :     }
     103              : #endif
     104         2127 :     return chip::Access::Privilege::kOperate;
     105              : }
     106              : 
     107            9 : chip::Access::Privilege MatterGetAccessPrivilegeForInvokeCommand(ClusterId cluster, CommandId command)
     108              : {
     109              : #ifdef GENERATED_ACCESS_INVOKE_COMMAND__CLUSTER
     110              :     using namespace GeneratedAccessInvokeCommand;
     111              :     for (size_t i = 0; i < ArraySize(kCluster); ++i)
     112              :     {
     113              :         if (kCluster[i] == cluster && kCommand[i] == command)
     114              :         {
     115              :             return kPrivilege[i];
     116              :         }
     117              :     }
     118              : #endif
     119            9 :     return chip::Access::Privilege::kOperate;
     120              : }
     121              : 
     122         2047 : chip::Access::Privilege MatterGetAccessPrivilegeForReadEvent(ClusterId cluster, EventId event)
     123              : {
     124              : #ifdef GENERATED_ACCESS_READ_EVENT__CLUSTER
     125              :     using namespace GeneratedAccessReadEvent;
     126              :     for (size_t i = 0; i < ArraySize(kCluster); ++i)
     127              :     {
     128              :         if (kCluster[i] == cluster && kEvent[i] == event)
     129              :         {
     130              :             return kPrivilege[i];
     131              :         }
     132              :     }
     133              : #endif
     134         2047 :     return chip::Access::Privilege::kView;
     135              : }
        

Generated by: LCOV version 2.0-1