@@ -23,10 +23,10 @@ use crate::{
23
23
} ;
24
24
use std:: fmt;
25
25
26
- use super :: DeviceType ;
26
+ use super :: { ClusterId , DeviceType , EndptId } ;
27
27
28
28
pub trait ChangeConsumer {
29
- fn endpoint_added ( & self , id : u16 , endpoint : & mut Endpoint ) -> Result < ( ) , Error > ;
29
+ fn endpoint_added ( & self , id : EndptId , endpoint : & mut Endpoint ) -> Result < ( ) , Error > ;
30
30
}
31
31
32
32
pub const ENDPTS_PER_ACC : usize = 3 ;
@@ -61,21 +61,21 @@ impl Node {
61
61
self . changes_cb = Some ( consumer) ;
62
62
}
63
63
64
- pub fn add_endpoint ( & mut self , dev_type : DeviceType ) -> Result < u32 , Error > {
64
+ pub fn add_endpoint ( & mut self , dev_type : DeviceType ) -> Result < EndptId , Error > {
65
65
let index = self
66
66
. endpoints
67
67
. iter ( )
68
68
. position ( |x| x. is_none ( ) )
69
69
. ok_or ( Error :: NoSpace ) ?;
70
70
let mut endpoint = Endpoint :: new ( dev_type) ?;
71
71
if let Some ( cb) = & self . changes_cb {
72
- cb. endpoint_added ( index as u16 , & mut endpoint) ?;
72
+ cb. endpoint_added ( index as EndptId , & mut endpoint) ?;
73
73
}
74
74
self . endpoints [ index] = Some ( endpoint) ;
75
- Ok ( index as u32 )
75
+ Ok ( index as EndptId )
76
76
}
77
77
78
- pub fn get_endpoint ( & self , endpoint_id : u16 ) -> Result < & Endpoint , Error > {
78
+ pub fn get_endpoint ( & self , endpoint_id : EndptId ) -> Result < & Endpoint , Error > {
79
79
if ( endpoint_id as usize ) < ENDPTS_PER_ACC {
80
80
let endpoint = self . endpoints [ endpoint_id as usize ]
81
81
. as_ref ( )
@@ -86,7 +86,7 @@ impl Node {
86
86
}
87
87
}
88
88
89
- pub fn get_endpoint_mut ( & mut self , endpoint_id : u16 ) -> Result < & mut Endpoint , Error > {
89
+ pub fn get_endpoint_mut ( & mut self , endpoint_id : EndptId ) -> Result < & mut Endpoint , Error > {
90
90
if ( endpoint_id as usize ) < ENDPTS_PER_ACC {
91
91
let endpoint = self . endpoints [ endpoint_id as usize ]
92
92
. as_mut ( )
@@ -97,17 +97,21 @@ impl Node {
97
97
}
98
98
}
99
99
100
- pub fn get_cluster_mut ( & mut self , e : u16 , c : u32 ) -> Result < & mut dyn ClusterType , Error > {
100
+ pub fn get_cluster_mut (
101
+ & mut self ,
102
+ e : EndptId ,
103
+ c : ClusterId ,
104
+ ) -> Result < & mut dyn ClusterType , Error > {
101
105
self . get_endpoint_mut ( e) ?. get_cluster_mut ( c)
102
106
}
103
107
104
- pub fn get_cluster ( & self , e : u16 , c : u32 ) -> Result < & dyn ClusterType , Error > {
108
+ pub fn get_cluster ( & self , e : EndptId , c : ClusterId ) -> Result < & dyn ClusterType , Error > {
105
109
self . get_endpoint ( e) ?. get_cluster ( c)
106
110
}
107
111
108
112
pub fn add_cluster (
109
113
& mut self ,
110
- endpoint_id : u32 ,
114
+ endpoint_id : EndptId ,
111
115
cluster : Box < dyn ClusterType > ,
112
116
) -> Result < ( ) , Error > {
113
117
let endpoint_id = endpoint_id as usize ;
@@ -124,7 +128,7 @@ impl Node {
124
128
// Returns a slice of endpoints, with either a single endpoint or all (wildcard)
125
129
pub fn get_wildcard_endpoints (
126
130
& self ,
127
- endpoint : Option < u16 > ,
131
+ endpoint : Option < EndptId > ,
128
132
) -> Result < ( & BoxedEndpoints , usize , bool ) , IMStatusCode > {
129
133
if let Some ( e) = endpoint {
130
134
let e = e as usize ;
@@ -140,7 +144,7 @@ impl Node {
140
144
141
145
pub fn get_wildcard_endpoints_mut (
142
146
& mut self ,
143
- endpoint : Option < u16 > ,
147
+ endpoint : Option < EndptId > ,
144
148
) -> Result < ( & mut BoxedEndpoints , usize , bool ) , IMStatusCode > {
145
149
if let Some ( e) = endpoint {
146
150
let e = e as usize ;
@@ -171,7 +175,7 @@ impl Node {
171
175
let ( endpoints, mut endpoint_id, wildcard) = self . get_wildcard_endpoints ( path. endpoint ) ?;
172
176
for e in endpoints. iter ( ) {
173
177
if let Some ( e) = e {
174
- current_path. endpoint = Some ( endpoint_id as u16 ) ;
178
+ current_path. endpoint = Some ( endpoint_id as EndptId ) ;
175
179
f ( & current_path, e. as_ref ( ) )
176
180
. or_else ( |e| if !wildcard { Err ( e) } else { Ok ( ( ) ) } ) ?;
177
181
}
@@ -202,7 +206,7 @@ impl Node {
202
206
self . get_wildcard_endpoints_mut ( path. endpoint ) ?;
203
207
for e in endpoints. iter_mut ( ) {
204
208
if let Some ( e) = e {
205
- current_path. endpoint = Some ( endpoint_id as u16 ) ;
209
+ current_path. endpoint = Some ( endpoint_id as EndptId ) ;
206
210
f ( & current_path, e. as_mut ( ) )
207
211
. or_else ( |e| if !wildcard { Err ( e) } else { Ok ( ( ) ) } ) ?;
208
212
}
0 commit comments