Matter SDK Coverage Report
Current view: top level - app - AttributePathParams.h (source / functions) Coverage Total Hit
Test: SHA:b879ecb8e99e175eea0a293a888bda853da2b19c Lines: 88.5 % 52 46
Test Date: 2025-01-17 19:00:11 Functions: 89.5 % 19 17

            Line data    Source code
       1              : /*
       2              :  *
       3              :  *    Copyright (c) 2021 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 <app/AppConfig.h>
      22              : #include <app/ConcreteAttributePath.h>
      23              : #include <app/DataVersionFilter.h>
      24              : #include <app/util/basic-types.h>
      25              : 
      26              : namespace chip {
      27              : namespace app {
      28              : 
      29              : struct AttributePathParams
      30              : {
      31         1406 :     AttributePathParams() = default;
      32              : 
      33           24 :     explicit AttributePathParams(EndpointId aEndpointId) :
      34           24 :         AttributePathParams(aEndpointId, kInvalidClusterId, kInvalidAttributeId, kInvalidListIndex)
      35           24 :     {}
      36              : 
      37              :     //
      38              :     // TODO: (Issue #10596) Need to ensure that we do not encode the NodeId over the wire
      39              :     // if it is either not 'set', or is set to a value that matches accessing fabric
      40              :     // on which the interaction is undertaken.
      41            0 :     AttributePathParams(EndpointId aEndpointId, ClusterId aClusterId) :
      42            0 :         AttributePathParams(aEndpointId, aClusterId, kInvalidAttributeId, kInvalidListIndex)
      43            0 :     {}
      44              : 
      45         2508 :     AttributePathParams(EndpointId aEndpointId, ClusterId aClusterId, AttributeId aAttributeId) :
      46         2508 :         AttributePathParams(aEndpointId, aClusterId, aAttributeId, kInvalidListIndex)
      47         2508 :     {}
      48              : 
      49            0 :     AttributePathParams(ClusterId aClusterId, AttributeId aAttributeId) :
      50            0 :         AttributePathParams(kInvalidEndpointId, aClusterId, aAttributeId, kInvalidListIndex)
      51            0 :     {}
      52              : 
      53         2534 :     AttributePathParams(EndpointId aEndpointId, ClusterId aClusterId, AttributeId aAttributeId, ListIndex aListIndex) :
      54         2534 :         mClusterId(aClusterId), mAttributeId(aAttributeId), mEndpointId(aEndpointId), mListIndex(aListIndex)
      55         2534 :     {}
      56              : 
      57         9992 :     [[nodiscard]] bool IsWildcardPath() const
      58              :     {
      59         9992 :         return HasWildcardEndpointId() || HasWildcardClusterId() || HasWildcardAttributeId();
      60              :     }
      61              : 
      62              :     bool operator==(const AttributePathParams & aOther) const
      63              :     {
      64              :         return mEndpointId == aOther.mEndpointId && mClusterId == aOther.mClusterId && mAttributeId == aOther.mAttributeId &&
      65              :             mListIndex == aOther.mListIndex;
      66              :     }
      67              : 
      68              :     /**
      69              :      * SPEC 8.9.2.2
      70              :      * Check that the path meets some basic constraints of an attribute path: If list index is not wildcard, then field id must not
      71              :      * be wildcard. This does not verify that the attribute being targeted is actually of list type when the list index is not
      72              :      * wildcard.
      73              :      */
      74         1925 :     [[nodiscard]] bool IsValidAttributePath() const { return HasWildcardListIndex() || !HasWildcardAttributeId(); }
      75              : 
      76        20845 :     [[nodiscard]] inline bool HasWildcardEndpointId() const { return mEndpointId == kInvalidEndpointId; }
      77        19429 :     [[nodiscard]] inline bool HasWildcardClusterId() const { return mClusterId == kInvalidClusterId; }
      78        17965 :     [[nodiscard]] inline bool HasWildcardAttributeId() const { return mAttributeId == kInvalidAttributeId; }
      79         3987 :     [[nodiscard]] inline bool HasWildcardListIndex() const { return mListIndex == kInvalidListIndex; }
      80              :     inline void SetWildcardEndpointId() { mEndpointId = kInvalidEndpointId; }
      81           14 :     inline void SetWildcardClusterId() { mClusterId = kInvalidClusterId; }
      82           28 :     inline void SetWildcardAttributeId()
      83              :     {
      84           28 :         mAttributeId = kInvalidAttributeId;
      85           28 :         mListIndex   = kInvalidListIndex;
      86           28 :     }
      87              : 
      88          331 :     [[nodiscard]] bool IsAttributePathSupersetOf(const AttributePathParams & other) const
      89              :     {
      90          331 :         VerifyOrReturnError(HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false);
      91          264 :         VerifyOrReturnError(HasWildcardClusterId() || mClusterId == other.mClusterId, false);
      92          248 :         VerifyOrReturnError(HasWildcardAttributeId() || mAttributeId == other.mAttributeId, false);
      93          123 :         VerifyOrReturnError(HasWildcardListIndex() || mListIndex == other.mListIndex, false);
      94              : 
      95          123 :         return true;
      96              :     }
      97              : 
      98          815 :     [[nodiscard]] bool IsAttributePathSupersetOf(const ConcreteAttributePath & other) const
      99              :     {
     100          815 :         VerifyOrReturnError(HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false);
     101          459 :         VerifyOrReturnError(HasWildcardClusterId() || mClusterId == other.mClusterId, false);
     102          411 :         VerifyOrReturnError(HasWildcardAttributeId() || mAttributeId == other.mAttributeId, false);
     103              : 
     104          252 :         return true;
     105              :     }
     106              : 
     107          808 :     bool Intersects(const AttributePathParams & other) const
     108              :     {
     109          808 :         VerifyOrReturnError(HasWildcardEndpointId() || other.HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false);
     110          797 :         VerifyOrReturnError(HasWildcardClusterId() || other.HasWildcardClusterId() || mClusterId == other.mClusterId, false);
     111          725 :         VerifyOrReturnError(HasWildcardAttributeId() || other.HasWildcardAttributeId() || mAttributeId == other.mAttributeId,
     112              :                             false);
     113          346 :         return true;
     114              :     }
     115              : 
     116         3053 :     bool IncludesAttributesInCluster(const DataVersionFilter & other) const
     117              :     {
     118         3053 :         VerifyOrReturnError(HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false);
     119         3039 :         VerifyOrReturnError(HasWildcardClusterId() || mClusterId == other.mClusterId, false);
     120              : 
     121         3034 :         return true;
     122              :     }
     123              : 
     124              :     // check if input concrete cluster path is subset of current wildcard attribute
     125           79 :     bool IncludesAllAttributesInCluster(const ConcreteClusterPath & aOther) const
     126              :     {
     127           79 :         VerifyOrReturnError(HasWildcardEndpointId() || mEndpointId == aOther.mEndpointId, false);
     128           62 :         VerifyOrReturnError(HasWildcardClusterId() || mClusterId == aOther.mClusterId, false);
     129           57 :         return HasWildcardAttributeId();
     130              :     }
     131              : 
     132              :     ClusterId mClusterId     = kInvalidClusterId;   // uint32
     133              :     AttributeId mAttributeId = kInvalidAttributeId; // uint32
     134              :     EndpointId mEndpointId   = kInvalidEndpointId;  // uint16
     135              :     ListIndex mListIndex     = kInvalidListIndex;   // uint16
     136              : };
     137              : 
     138              : } // namespace app
     139              : } // namespace chip
        

Generated by: LCOV version 2.0-1