Matter SDK Coverage Report
Current view: top level - app - ConcreteAttributePath.h (source / functions) Coverage Total Hit
Test: SHA:b879ecb8e99e175eea0a293a888bda853da2b19c Lines: 82.9 % 35 29
Test Date: 2025-01-17 19:00:11 Functions: 93.8 % 16 15

            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/ConcreteClusterPath.h>
      22              : #include <app/util/basic-types.h>
      23              : #include <lib/core/Optional.h>
      24              : 
      25              : namespace chip {
      26              : namespace app {
      27              : 
      28              : /**
      29              :  * A representation of a concrete attribute path. This does not convey any list index specifiers.
      30              :  *
      31              :  * The expanded flag can be set to indicate that a concrete path was expanded from a wildcard
      32              :  * or group path.
      33              :  */
      34              : struct ConcreteAttributePath : public ConcreteClusterPath
      35              : {
      36        23049 :     ConcreteAttributePath()
      37        23049 :     {
      38              :         // Note: mExpanded is in the superclass, so we can't use a field
      39              :         // initializer.
      40        23049 :         mExpanded = false;
      41        23049 :     }
      42              : 
      43         6494 :     ConcreteAttributePath(EndpointId aEndpointId, ClusterId aClusterId, AttributeId aAttributeId) :
      44         6494 :         ConcreteClusterPath(aEndpointId, aClusterId), mAttributeId(aAttributeId)
      45              :     {
      46              :         // Note: mExpanded is in the supercclass, so we can't use a field
      47              :         // initializer.
      48         6494 :         mExpanded = false;
      49         6494 :     }
      50              : 
      51         4355 :     bool IsValid() const { return ConcreteClusterPath::HasValidIds() && IsValidAttributeId(mAttributeId); }
      52              : 
      53        16885 :     bool operator==(const ConcreteAttributePath & aOther) const
      54              :     {
      55        16885 :         return ConcreteClusterPath::operator==(aOther) && (mAttributeId == aOther.mAttributeId);
      56              :     }
      57              : 
      58          733 :     bool operator!=(const ConcreteAttributePath & aOther) const { return !(*this == aOther); }
      59              : 
      60          364 :     bool operator<(const ConcreteAttributePath & path) const
      61              :     {
      62          702 :         return (mEndpointId < path.mEndpointId) || ((mEndpointId == path.mEndpointId) && (mClusterId < path.mClusterId)) ||
      63          702 :             ((mEndpointId == path.mEndpointId) && (mClusterId == path.mClusterId) && (mAttributeId < path.mAttributeId));
      64              :     }
      65              : 
      66              :     AttributeId mAttributeId = 0;
      67              : };
      68              : 
      69              : /**
      70              :  * A representation of a concrete path as it appears in a Read or Subscribe
      71              :  * request after path expansion. This contains support for expressing an
      72              :  * optional list index.
      73              :  */
      74              : struct ConcreteReadAttributePath : public ConcreteAttributePath
      75              : {
      76         2083 :     ConcreteReadAttributePath() {}
      77              : 
      78        11452 :     ConcreteReadAttributePath(const ConcreteAttributePath & path) : ConcreteAttributePath(path) {}
      79              : 
      80         1277 :     ConcreteReadAttributePath(EndpointId aEndpointId, ClusterId aClusterId, AttributeId aAttributeId) :
      81         1277 :         ConcreteAttributePath(aEndpointId, aClusterId, aAttributeId)
      82         1277 :     {}
      83              : 
      84              :     ConcreteReadAttributePath(EndpointId aEndpointId, ClusterId aClusterId, AttributeId aAttributeId, uint16_t aListIndex) :
      85              :         ConcreteAttributePath(aEndpointId, aClusterId, aAttributeId)
      86              :     {
      87              :         mListIndex.SetValue(aListIndex);
      88              :     }
      89              : 
      90              :     bool operator==(const ConcreteReadAttributePath & aOther) const = delete;
      91              :     bool operator!=(const ConcreteReadAttributePath & aOther) const = delete;
      92              :     bool operator<(const ConcreteReadAttributePath & aOther) const  = delete;
      93              : 
      94              :     Optional<uint16_t> mListIndex;
      95              : };
      96              : 
      97              : /**
      98              :  * A representation of a concrete path as it appears in a Report or Write
      99              :  * request after path expansion. This contains support for expressing list and list item-specific operations
     100              :  * like replace, update, delete and append.
     101              :  */
     102              : struct ConcreteDataAttributePath : public ConcreteAttributePath
     103              : {
     104              :     enum class ListOperation : uint8_t
     105              :     {
     106              :         NotList,     // Path points to an attribute that isn't a list.
     107              :         ReplaceAll,  // Path points to an attribute that is a list, indicating that the contents of the list should be replaced in
     108              :                      // its entirety.
     109              :         ReplaceItem, // Path points to a specific item in a list, indicating that that item should be replaced in its entirety.
     110              :         DeleteItem,  // Path points to a specific item in a list, indicating that that item should be deleted from the list.
     111              :         AppendItem   // Path points to an attribute that is a list, indicating that an item should be appended into the list.
     112              :     };
     113              : 
     114         7393 :     ConcreteDataAttributePath() {}
     115              : 
     116            7 :     ConcreteDataAttributePath(const ConcreteAttributePath & path) : ConcreteAttributePath(path) {}
     117              : 
     118         2471 :     ConcreteDataAttributePath(EndpointId aEndpointId, ClusterId aClusterId, AttributeId aAttributeId) :
     119         2471 :         ConcreteAttributePath(aEndpointId, aClusterId, aAttributeId)
     120         2471 :     {}
     121              : 
     122              :     ConcreteDataAttributePath(EndpointId aEndpointId, ClusterId aClusterId, AttributeId aAttributeId,
     123              :                               const Optional<DataVersion> & aDataVersion) :
     124              :         ConcreteAttributePath(aEndpointId, aClusterId, aAttributeId),
     125              :         mDataVersion(aDataVersion)
     126              :     {}
     127              : 
     128            0 :     ConcreteDataAttributePath(EndpointId aEndpointId, ClusterId aClusterId, AttributeId aAttributeId, ListOperation aListOp,
     129            0 :                               uint16_t aListIndex) :
     130            0 :         ConcreteAttributePath(aEndpointId, aClusterId, aAttributeId)
     131              :     {
     132            0 :         mListOp    = aListOp;
     133            0 :         mListIndex = aListIndex;
     134            0 :     }
     135              : 
     136        19626 :     bool IsListOperation() const { return mListOp != ListOperation::NotList; }
     137          144 :     bool IsListItemOperation() const { return ((mListOp != ListOperation::NotList) && (mListOp != ListOperation::ReplaceAll)); }
     138              : 
     139              :     void LogPath() const
     140              :     {
     141              :         ChipLogProgress(DataManagement, "Concrete Attribute Path: (%d, " ChipLogFormatMEI ", " ChipLogFormatMEI ") ", mEndpointId,
     142              :                         ChipLogValueMEI(mClusterId), ChipLogValueMEI(mAttributeId));
     143              :     }
     144              : 
     145         4096 :     bool MatchesConcreteAttributePath(const ConcreteAttributePath & aOther) const
     146              :     {
     147         4096 :         return ConcreteAttributePath::operator==(aOther);
     148              :     }
     149              : 
     150              :     bool operator==(const ConcreteDataAttributePath & aOther) const
     151              :     {
     152              :         return ConcreteAttributePath::operator==(aOther) && (mListIndex == aOther.mListIndex) && (mListOp == aOther.mListOp) &&
     153              :             (mDataVersion == aOther.mDataVersion);
     154              :     }
     155              : 
     156              :     bool operator!=(const ConcreteDataAttributePath & aOther) const { return !(*this == aOther); }
     157              : 
     158              :     bool operator<(const ConcreteDataAttributePath & aOther) const = delete;
     159              : 
     160              :     //
     161              :     // This index is only valid if `mListOp` is set to a list item operation, i.e
     162              :     // ReplaceItem, DeleteItem or AppendItem. Otherwise, it is to be ignored.
     163              :     //
     164              :     uint16_t mListIndex                = 0;
     165              :     ListOperation mListOp              = ListOperation::NotList;
     166              :     Optional<DataVersion> mDataVersion = NullOptional;
     167              : };
     168              : 
     169              : } // namespace app
     170              : } // namespace chip
        

Generated by: LCOV version 2.0-1