/src/connectedhomeip/src/app/AttributePathParams.h
Line | Count | Source |
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 | 0 | AttributePathParams() = default; |
32 | | |
33 | | constexpr explicit AttributePathParams(EndpointId aEndpointId) : |
34 | 0 | AttributePathParams(aEndpointId, kInvalidClusterId, kInvalidAttributeId, kInvalidListIndex) |
35 | 0 | {} |
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 | | constexpr AttributePathParams(EndpointId aEndpointId, ClusterId aClusterId) : |
42 | | AttributePathParams(aEndpointId, aClusterId, kInvalidAttributeId, kInvalidListIndex) |
43 | 0 | {} |
44 | | |
45 | | constexpr AttributePathParams(EndpointId aEndpointId, ClusterId aClusterId, AttributeId aAttributeId) : |
46 | 0 | AttributePathParams(aEndpointId, aClusterId, aAttributeId, kInvalidListIndex) |
47 | 0 | {} |
48 | | |
49 | | constexpr AttributePathParams(ClusterId aClusterId, AttributeId aAttributeId) : |
50 | | AttributePathParams(kInvalidEndpointId, aClusterId, aAttributeId, kInvalidListIndex) |
51 | 0 | {} |
52 | | |
53 | | constexpr AttributePathParams(EndpointId aEndpointId, ClusterId aClusterId, AttributeId aAttributeId, ListIndex aListIndex) : |
54 | 0 | mClusterId(aClusterId), mAttributeId(aAttributeId), mEndpointId(aEndpointId), mListIndex(aListIndex) |
55 | 0 | {} |
56 | | |
57 | | [[nodiscard]] bool IsWildcardPath() const |
58 | 0 | { |
59 | 0 | return HasWildcardEndpointId() || HasWildcardClusterId() || HasWildcardAttributeId(); |
60 | 0 | } |
61 | | |
62 | | bool operator==(const AttributePathParams & aOther) const |
63 | 0 | { |
64 | 0 | return mEndpointId == aOther.mEndpointId && mClusterId == aOther.mClusterId && mAttributeId == aOther.mAttributeId && |
65 | 0 | mListIndex == aOther.mListIndex; |
66 | 0 | } |
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 | 0 | [[nodiscard]] bool IsValidAttributePath() const { return HasWildcardListIndex() || !HasWildcardAttributeId(); } |
75 | | |
76 | 0 | [[nodiscard]] inline bool HasWildcardEndpointId() const { return mEndpointId == kInvalidEndpointId; } |
77 | 0 | [[nodiscard]] inline bool HasWildcardClusterId() const { return mClusterId == kInvalidClusterId; } |
78 | 0 | [[nodiscard]] inline bool HasWildcardAttributeId() const { return mAttributeId == kInvalidAttributeId; } |
79 | 0 | [[nodiscard]] inline bool HasWildcardListIndex() const { return mListIndex == kInvalidListIndex; } |
80 | 0 | inline void SetWildcardEndpointId() { mEndpointId = kInvalidEndpointId; } |
81 | 0 | inline void SetWildcardClusterId() { mClusterId = kInvalidClusterId; } |
82 | | inline void SetWildcardAttributeId() |
83 | 0 | { |
84 | 0 | mAttributeId = kInvalidAttributeId; |
85 | 0 | mListIndex = kInvalidListIndex; |
86 | 0 | } |
87 | | |
88 | | [[nodiscard]] bool IsAttributePathSupersetOf(const AttributePathParams & other) const |
89 | 0 | { |
90 | 0 | VerifyOrReturnError(HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false); |
91 | 0 | VerifyOrReturnError(HasWildcardClusterId() || mClusterId == other.mClusterId, false); |
92 | 0 | VerifyOrReturnError(HasWildcardAttributeId() || mAttributeId == other.mAttributeId, false); |
93 | 0 | VerifyOrReturnError(HasWildcardListIndex() || mListIndex == other.mListIndex, false); |
94 | | |
95 | 0 | return true; |
96 | 0 | } |
97 | | |
98 | | [[nodiscard]] bool IsAttributePathSupersetOf(const ConcreteAttributePath & other) const |
99 | 0 | { |
100 | 0 | VerifyOrReturnError(HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false); |
101 | 0 | VerifyOrReturnError(HasWildcardClusterId() || mClusterId == other.mClusterId, false); |
102 | 0 | VerifyOrReturnError(HasWildcardAttributeId() || mAttributeId == other.mAttributeId, false); |
103 | | |
104 | 0 | return true; |
105 | 0 | } |
106 | | |
107 | | bool Intersects(const AttributePathParams & other) const |
108 | 0 | { |
109 | 0 | VerifyOrReturnError(HasWildcardEndpointId() || other.HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false); |
110 | 0 | VerifyOrReturnError(HasWildcardClusterId() || other.HasWildcardClusterId() || mClusterId == other.mClusterId, false); |
111 | 0 | VerifyOrReturnError(HasWildcardAttributeId() || other.HasWildcardAttributeId() || mAttributeId == other.mAttributeId, |
112 | 0 | false); |
113 | 0 | return true; |
114 | 0 | } |
115 | | |
116 | | bool IncludesAttributesInCluster(const DataVersionFilter & other) const |
117 | 0 | { |
118 | 0 | VerifyOrReturnError(HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false); |
119 | 0 | VerifyOrReturnError(HasWildcardClusterId() || mClusterId == other.mClusterId, false); |
120 | | |
121 | 0 | return true; |
122 | 0 | } |
123 | | |
124 | | // check if input concrete cluster path is subset of current wildcard attribute |
125 | | bool IncludesAllAttributesInCluster(const ConcreteClusterPath & aOther) const |
126 | 0 | { |
127 | 0 | VerifyOrReturnError(HasWildcardEndpointId() || mEndpointId == aOther.mEndpointId, false); |
128 | 0 | VerifyOrReturnError(HasWildcardClusterId() || mClusterId == aOther.mClusterId, false); |
129 | 0 | return HasWildcardAttributeId(); |
130 | 0 | } |
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 |