LCOV - code coverage report
Current view: top level - app - RequiredPrivilege.h (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 8 8 100.0 %
Date: 2024-02-15 08:20:41 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  *    Copyright (c) 2022 Project CHIP Authors
       4             :  *    All rights reserved.
       5             :  *
       6             :  *    Licensed under the Apache License, Version 2.0 (the "License");
       7             :  *    you may not use this file except in compliance with the License.
       8             :  *    You may obtain a copy of the License at
       9             :  *
      10             :  *        http://www.apache.org/licenses/LICENSE-2.0
      11             :  *
      12             :  *    Unless required by applicable law or agreed to in writing, software
      13             :  *    distributed under the License is distributed on an "AS IS" BASIS,
      14             :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      15             :  *    See the License for the specific language governing permissions and
      16             :  *    limitations under the License.
      17             :  */
      18             : 
      19             : #pragma once
      20             : 
      21             : #include "ConcreteAttributePath.h"
      22             : #include "ConcreteCommandPath.h"
      23             : #include "ConcreteEventPath.h"
      24             : 
      25             : #include <app/util/privilege-storage.h>
      26             : 
      27             : #include <access/Privilege.h>
      28             : 
      29             : #include <lib/core/CHIPCore.h>
      30             : #include <lib/core/DataModelTypes.h>
      31             : 
      32             : namespace chip {
      33             : namespace app {
      34             : 
      35             : class RequiredPrivilege
      36             : {
      37             :     using Privilege = Access::Privilege;
      38             : 
      39             :     static constexpr Privilege kPrivilegeMapper[] = { Privilege::kView, Privilege::kOperate, Privilege::kManage,
      40             :                                                       Privilege::kAdminister };
      41             : 
      42             :     static_assert(ArraySize(kPrivilegeMapper) > kMatterAccessPrivilegeView &&
      43             :                       kPrivilegeMapper[kMatterAccessPrivilegeView] == Privilege::kView,
      44             :                   "Must map privilege correctly");
      45             :     static_assert(ArraySize(kPrivilegeMapper) > kMatterAccessPrivilegeOperate &&
      46             :                       kPrivilegeMapper[kMatterAccessPrivilegeOperate] == Privilege::kOperate,
      47             :                   "Must map privilege correctly");
      48             :     static_assert(ArraySize(kPrivilegeMapper) > kMatterAccessPrivilegeManage &&
      49             :                       kPrivilegeMapper[kMatterAccessPrivilegeManage] == Privilege::kManage,
      50             :                   "Must map privilege correctly");
      51             :     static_assert(ArraySize(kPrivilegeMapper) > kMatterAccessPrivilegeAdminister &&
      52             :                       kPrivilegeMapper[kMatterAccessPrivilegeAdminister] == Privilege::kAdminister,
      53             :                   "Must map privilege correctly");
      54             :     static_assert(ArraySize(kPrivilegeMapper) > kMatterAccessPrivilegeMaxValue, "Must map all privileges");
      55             : 
      56             : public:
      57        2761 :     static Privilege ForReadAttribute(const ConcreteAttributePath & path)
      58             :     {
      59        2761 :         return kPrivilegeMapper[MatterGetAccessPrivilegeForReadAttribute(path.mClusterId, path.mAttributeId)];
      60             :     }
      61             : 
      62        2434 :     static Privilege ForWriteAttribute(const ConcreteAttributePath & path)
      63             :     {
      64        2434 :         return kPrivilegeMapper[MatterGetAccessPrivilegeForWriteAttribute(path.mClusterId, path.mAttributeId)];
      65             :     }
      66             : 
      67          27 :     static Privilege ForInvokeCommand(const ConcreteCommandPath & path)
      68             :     {
      69          27 :         return kPrivilegeMapper[MatterGetAccessPrivilegeForInvokeCommand(path.mClusterId, path.mCommandId)];
      70             :     }
      71             : 
      72        2237 :     static Privilege ForReadEvent(const ConcreteEventPath & path)
      73             :     {
      74        2237 :         return kPrivilegeMapper[MatterGetAccessPrivilegeForReadEvent(path.mClusterId, path.mEventId)];
      75             :     }
      76             : };
      77             : 
      78             : } // namespace app
      79             : } // namespace chip

Generated by: LCOV version 1.14