-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathClusterInfo.h
99 lines (88 loc) · 3.93 KB
/
ClusterInfo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
*
* Copyright (c) 2021 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <app/AttributePathParams.h>
#include <app/util/basic-types.h>
#include <assert.h>
#include <lib/core/Optional.h>
namespace chip {
namespace app {
struct ClusterInfo
{
enum class Flags : uint8_t
{
kFieldIdValid = 0x01,
kListIndexValid = 0x02,
kEventIdValid = 0x03,
kEndpointIdValid = 0x04,
kClusterIdValid = 0x05,
};
bool IsAttributePathSupersetOf(const ClusterInfo & other) const
{
Optional<EndpointId> myEndpointId =
mFlags.Has(Flags::kEndpointIdValid) ? Optional<EndpointId>(mEndpointId) : Optional<EndpointId>::Missing();
Optional<EndpointId> otherEndpointId =
other.mFlags.Has(Flags::kEndpointIdValid) ? Optional<EndpointId>(other.mEndpointId) : Optional<EndpointId>::Missing();
Optional<ClusterId> myClusterId =
mFlags.Has(Flags::kClusterIdValid) ? Optional<ClusterId>(mClusterId) : Optional<ClusterId>::Missing();
Optional<ClusterId> otherClusterId =
other.mFlags.Has(Flags::kClusterIdValid) ? Optional<ClusterId>(other.mClusterId) : Optional<ClusterId>::Missing();
Optional<AttributeId> myFieldId =
mFlags.Has(Flags::kFieldIdValid) ? Optional<AttributeId>::Value(mFieldId) : Optional<AttributeId>::Missing();
Optional<AttributeId> otherFieldId = other.mFlags.Has(Flags::kFieldIdValid) ? Optional<AttributeId>::Value(other.mFieldId)
: Optional<AttributeId>::Missing();
Optional<AttributeId> myListIndex =
mFlags.Has(Flags::kListIndexValid) ? Optional<AttributeId>::Value(mListIndex) : Optional<AttributeId>::Missing();
Optional<AttributeId> otherListIndex = other.mFlags.Has(Flags::kListIndexValid)
? Optional<AttributeId>::Value(other.mListIndex)
: Optional<AttributeId>::Missing();
VerifyOrReturnError(!myEndpointId.HasValue() || myEndpointId == otherEndpointId, false);
VerifyOrReturnError(!myClusterId.HasValue() || myClusterId == otherClusterId, false);
VerifyOrReturnError(!myFieldId.HasValue() || myFieldId == otherFieldId, false);
VerifyOrReturnError(!myListIndex.HasValue() || myListIndex == otherListIndex, false);
// TODO: We did not make uses of list index in ClusterInfo now.
return true;
}
bool HasWildcard() const { return !mFlags.HasAll(Flags::kEndpointIdValid, Flags::kClusterIdValid, Flags::kFieldIdValid); }
ClusterInfo() {}
NodeId mNodeId = 0;
ClusterId mClusterId = 0;
ListIndex mListIndex = 0;
AttributeId mFieldId = 0;
EndpointId mEndpointId = 0;
BitFlags<Flags> mFlags;
ClusterInfo * mpNext = nullptr;
EventId mEventId = 0;
/* For better structure alignment
* Above ordering is by bit-size to ensure least amount of memory alignment padding.
* Changing order to something more natural (e.g. clusterid before nodeid) will result
* in extra memory alignment padding.
* uint64 mNodeId
* uint16_t mClusterId
* uint16_t mListIndex
* uint8_t FieldId
* uint8_t EndpointId
* uint8_t mDirty
* uint8_t mType
* uint32_t mpNext
* uint16_t EventId
* padding 2 bytes
*/
};
} // namespace app
} // namespace chip