LCOV - code coverage report
Current view: top level - app - AttributePathParams.h (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 36 48 75.0 %
Date: 2024-02-15 08:20:41 Functions: 14 18 77.8 %

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

Generated by: LCOV version 1.14