@@ -53,13 +53,63 @@ pub const CLUSTER: Cluster<'static> = Cluster {
53
53
commands : & [ ] ,
54
54
} ;
55
55
56
- pub struct DescriptorCluster {
56
+ struct StandardPartsMatcher ;
57
+
58
+ impl PartsMatcher for StandardPartsMatcher {
59
+ fn describe ( & self , our_endpoint : EndptId , endpoint : EndptId ) -> bool {
60
+ our_endpoint == 0 && endpoint != our_endpoint
61
+ }
62
+ }
63
+
64
+ struct AggregatorPartsMatcher ;
65
+
66
+ impl PartsMatcher for AggregatorPartsMatcher {
67
+ fn describe ( & self , our_endpoint : EndptId , endpoint : EndptId ) -> bool {
68
+ endpoint != our_endpoint && endpoint != 0
69
+ }
70
+ }
71
+
72
+ pub trait PartsMatcher {
73
+ fn describe ( & self , our_endpoint : EndptId , endpoint : EndptId ) -> bool ;
74
+ }
75
+
76
+ impl < T > PartsMatcher for & T
77
+ where
78
+ T : PartsMatcher ,
79
+ {
80
+ fn describe ( & self , our_endpoint : EndptId , endpoint : EndptId ) -> bool {
81
+ ( * * self ) . describe ( our_endpoint, endpoint)
82
+ }
83
+ }
84
+
85
+ impl < T > PartsMatcher for & mut T
86
+ where
87
+ T : PartsMatcher ,
88
+ {
89
+ fn describe ( & self , our_endpoint : EndptId , endpoint : EndptId ) -> bool {
90
+ ( * * self ) . describe ( our_endpoint, endpoint)
91
+ }
92
+ }
93
+
94
+ pub struct DescriptorCluster < ' a > {
95
+ matcher : & ' a dyn PartsMatcher ,
57
96
data_ver : Dataver ,
58
97
}
59
98
60
- impl DescriptorCluster {
99
+ impl DescriptorCluster < ' static > {
61
100
pub fn new ( rand : Rand ) -> Self {
101
+ Self :: new_matching ( & StandardPartsMatcher , rand)
102
+ }
103
+
104
+ pub fn new_aggregator ( rand : Rand ) -> Self {
105
+ Self :: new_matching ( & AggregatorPartsMatcher , rand)
106
+ }
107
+ }
108
+
109
+ impl < ' a > DescriptorCluster < ' a > {
110
+ pub fn new_matching ( matcher : & ' a dyn PartsMatcher , rand : Rand ) -> DescriptorCluster < ' a > {
62
111
Self {
112
+ matcher,
63
113
data_ver : Dataver :: new ( rand) ,
64
114
}
65
115
}
@@ -159,12 +209,9 @@ impl DescriptorCluster {
159
209
) -> Result < ( ) , Error > {
160
210
tw. start_array ( tag) ?;
161
211
162
- if endpoint_id == 0 {
163
- // TODO: If endpoint is another than 0, need to figure out what to do
164
- for endpoint in node. endpoints {
165
- if endpoint. id != 0 {
166
- tw. u16 ( TagType :: Anonymous , endpoint. id ) ?;
167
- }
212
+ for endpoint in node. endpoints {
213
+ if self . matcher . describe ( endpoint_id, endpoint. id ) {
214
+ tw. u16 ( TagType :: Anonymous , endpoint. id ) ?;
168
215
}
169
216
}
170
217
@@ -184,15 +231,15 @@ impl DescriptorCluster {
184
231
}
185
232
}
186
233
187
- impl Handler for DescriptorCluster {
234
+ impl < ' a > Handler for DescriptorCluster < ' a > {
188
235
fn read ( & self , attr : & AttrDetails , encoder : AttrDataEncoder ) -> Result < ( ) , Error > {
189
236
DescriptorCluster :: read ( self , attr, encoder)
190
237
}
191
238
}
192
239
193
- impl NonBlockingHandler for DescriptorCluster { }
240
+ impl < ' a > NonBlockingHandler for DescriptorCluster < ' a > { }
194
241
195
- impl ChangeNotifier < ( ) > for DescriptorCluster {
242
+ impl < ' a > ChangeNotifier < ( ) > for DescriptorCluster < ' a > {
196
243
fn consume_change ( & mut self ) -> Option < ( ) > {
197
244
self . data_ver . consume_change ( ( ) )
198
245
}
0 commit comments