Skip to content

Commit 2016d93

Browse files
committed
Simplify and re-export the IDL import macro; compat with latest rust nightly; restore the modules for generated clusters
1 parent 6178f15 commit 2016d93

33 files changed

Lines changed: 179 additions & 707 deletions

File tree

examples/onoff_light/src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ use embassy_time::{Duration, Timer};
2626
use log::info;
2727

2828
use rs_matter::core::{BasicCommData, Matter, MATTER_PORT};
29-
use rs_matter::data_model::cluster_basic_information::BasicInfoConfig;
30-
use rs_matter::data_model::cluster_on_off::{self, OnOffAdaptor};
29+
use rs_matter::data_model::basic_info::BasicInfoConfig;
3130
use rs_matter::data_model::core::IMBuffer;
3231
use rs_matter::data_model::device_types::DEV_TYPE_ON_OFF_LIGHT;
3332
use rs_matter::data_model::objects::*;
33+
use rs_matter::data_model::on_off;
3434
use rs_matter::data_model::root_endpoint;
3535
use rs_matter::data_model::subscriptions::Subscriptions;
3636
use rs_matter::data_model::system_model::descriptor;
@@ -136,7 +136,7 @@ fn run() -> Result<(), Error> {
136136

137137
info!("IM buffers initialized");
138138

139-
let on_off = cluster_on_off::OnOffCluster::new(Dataver::new_rand(matter.rand()));
139+
let on_off = on_off::OnOffHandler::new(Dataver::new_rand(matter.rand()));
140140

141141
let subscriptions = SUBSCRIPTIONS.uninit().init_with(Subscriptions::init());
142142

@@ -231,14 +231,14 @@ const NODE: Node<'static> = Node {
231231
Endpoint {
232232
id: 1,
233233
device_types: &[DEV_TYPE_ON_OFF_LIGHT],
234-
clusters: &[descriptor::CLUSTER, cluster_on_off::CLUSTER],
234+
clusters: &[descriptor::CLUSTER, on_off::CLUSTER],
235235
},
236236
],
237237
};
238238

239239
fn dm_handler<'a>(
240240
matter: &'a Matter<'a>,
241-
on_off: &'a cluster_on_off::OnOffCluster,
241+
on_off: &'a on_off::OnOffHandler,
242242
) -> impl Metadata + NonBlockingHandler + 'a {
243243
(
244244
NODE,
@@ -250,7 +250,7 @@ fn dm_handler<'a>(
250250
matter.rand(),
251251
))),
252252
)
253-
.chain(1, cluster_on_off::ID, Async(OnOffAdaptor(on_off))),
253+
.chain(1, on_off::ID, Async(on_off::HandlerAdaptor(on_off))),
254254
)
255255
}
256256

examples/onoff_light_bt/src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ use embassy_time::{Duration, Timer};
4343
use log::{info, warn};
4444

4545
use rs_matter::core::{BasicCommData, Matter};
46-
use rs_matter::data_model::cluster_basic_information::BasicInfoConfig;
47-
use rs_matter::data_model::cluster_on_off::{self, OnOffAdaptor};
46+
use rs_matter::data_model::basic_info::BasicInfoConfig;
4847
use rs_matter::data_model::core::IMBuffer;
4948
use rs_matter::data_model::device_types::DEV_TYPE_ON_OFF_LIGHT;
5049
use rs_matter::data_model::objects::*;
50+
use rs_matter::data_model::on_off;
5151
use rs_matter::data_model::root_endpoint;
5252
use rs_matter::data_model::sdm::wifi_nw_diagnostics::{
5353
self, WiFiSecurity, WiFiVersion, WifiNwDiagCluster, WifiNwDiagData,
@@ -144,7 +144,7 @@ fn run() -> Result<(), Error> {
144144

145145
let mut mdns = pin!(run_mdns(&matter));
146146

147-
let on_off = cluster_on_off::OnOffCluster::new(Dataver::new_rand(matter.rand()));
147+
let on_off = on_off::OnOffHandler::new(Dataver::new_rand(matter.rand()));
148148

149149
let subscriptions = Subscriptions::<3>::new();
150150

@@ -251,14 +251,14 @@ const NODE: Node<'static> = Node {
251251
Endpoint {
252252
id: 1,
253253
device_types: &[DEV_TYPE_ON_OFF_LIGHT],
254-
clusters: &[descriptor::CLUSTER, cluster_on_off::CLUSTER],
254+
clusters: &[descriptor::CLUSTER, on_off::CLUSTER],
255255
},
256256
],
257257
};
258258

259259
fn dm_handler<'a>(
260260
matter: &'a Matter<'a>,
261-
on_off: &'a cluster_on_off::OnOffCluster,
261+
on_off: &'a on_off::OnOffHandler,
262262
wifi_complete: &'a Notification<NoopRawMutex>,
263263
) -> impl Metadata + NonBlockingHandler + 'a {
264264
(
@@ -290,7 +290,7 @@ fn dm_handler<'a>(
290290
matter.rand(),
291291
))),
292292
)
293-
.chain(1, cluster_on_off::ID, Async(OnOffAdaptor(on_off))),
293+
.chain(1, on_off::ID, Async(on_off::HandlerAdaptor(on_off))),
294294
)
295295
}
296296

rs-matter-macros-impl/src/idl.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
use proc_macro2::{Ident, Literal, Span, TokenStream};
17+
use proc_macro2::{Ident, Span, TokenStream};
1818
use quote::quote;
1919

2020
use rs_matter_data_model::Cluster;
@@ -57,7 +57,10 @@ fn cluster_internal(
5757
with_async: bool,
5858
context: &IdlGenerateContext,
5959
) -> TokenStream {
60-
//let cluster_module_name = Ident::new(&cluster.id.to_case(Case::Snake), Span::call_site());
60+
let cluster_module_name = Ident::new(
61+
&id::idl_field_name_to_rs_name(&cluster.id),
62+
Span::call_site(),
63+
);
6164

6265
let bitmaps = bitmap::bitmaps(cluster, context);
6366
let enums = enumeration::enums(cluster, context);
@@ -74,11 +77,7 @@ fn cluster_internal(
7477
let handler_inherent_impl = handler::handler(false, true, cluster, context);
7578
let handler_adaptor = handler::handler_adaptor(false, cluster, context);
7679

77-
let cluster_code = Literal::u32_unsuffixed(cluster.code as u32);
78-
7980
let quote = quote!(
80-
pub const ID: u32 = #cluster_code;
81-
8281
#bitmaps
8382

8483
#enums
@@ -104,7 +103,7 @@ fn cluster_internal(
104103
#handler_adaptor
105104
);
106105

107-
if with_async {
106+
let quote = if with_async {
108107
let async_handler = handler::handler(true, false, cluster, context);
109108
let async_handler_inherent_impl = handler::handler(true, true, cluster, context);
110109
let async_handler_adaptor = handler::handler_adaptor(true, cluster, context);
@@ -120,7 +119,16 @@ fn cluster_internal(
120119
)
121120
} else {
122121
quote
123-
}
122+
};
123+
124+
quote!(
125+
#[allow(async_fn_in_trait)]
126+
#[allow(unknown_lints)]
127+
#[allow(clippy::uninlined_format_args)]
128+
pub mod #cluster_module_name {
129+
#quote
130+
}
131+
)
124132
}
125133

126134
#[cfg(test)]

rs-matter-macros-impl/src/idl/bitmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn bitmap(b: &Bitmap, context: &IdlGenerateContext) -> TokenStream {
4141
"bitmap16" => quote!(u16),
4242
"bitmap32" => quote!(u32),
4343
"bitmap64" => quote!(u64),
44-
other => panic!("Unknown bitmap base type {}", other),
44+
other => panic!("Unknown bitmap base type {other}"),
4545
};
4646
let name = Ident::new(&b.id, Span::call_site());
4747

rs-matter-macros-impl/src/idl/cluster.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,12 @@ pub fn cluster(cluster: &Cluster, context: &IdlGenerateContext) -> TokenStream {
495495
)
496496
});
497497

498+
let cluster_id = Literal::u32_unsuffixed(cluster.code as u32);
498499
let cluster_revision = Literal::u16_unsuffixed(cluster.revision as u16);
499500

500501
quote!(
501-
const CLUSTER_REVISION: u16 = #cluster_revision;
502+
pub const ID: u32 = #cluster_id;
503+
pub const REVISION: u16 = #cluster_revision;
502504

503505
// TODO: Think if to continue supporting this
504506
pub const CLUSTER: #krate::data_model::objects::Cluster<'static> = ClusterConf::Default.cluster();
@@ -532,7 +534,7 @@ pub fn cluster(cluster: &Cluster, context: &IdlGenerateContext) -> TokenStream {
532534
id: ID as _,
533535
attributes_access: ATTRIBUTES_ACCESS,
534536
revision: match self {
535-
ClusterConf::Default => CLUSTER_REVISION,
537+
ClusterConf::Default => REVISION,
536538
ClusterConf::Mandatory { revision, .. } => *revision,
537539
ClusterConf::All { revision, .. } => *revision,
538540
ClusterConf::Custom { revision, .. } => *revision,

rs-matter-macros-impl/src/idl/enumeration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn enumeration(e: &Enum, context: &IdlGenerateContext) -> TokenStream {
4040
let base_type = match e.base_type.as_ref() {
4141
"enum8" => quote!(u8),
4242
"enum16" => quote!(u16),
43-
other => panic!("Unknown enumeration base type {}", other),
43+
other => panic!("Unknown enumeration base type {other}"),
4444
};
4545
let name = Ident::new(&e.id, Span::call_site());
4646

rs-matter-macros-impl/src/idl/handler.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn handler(
5353
let krate = context.rs_matter_crate.clone();
5454

5555
let handler_name = Ident::new(
56-
&format!("{}{}Handler", if asynch { "Async" } else { "" }, cluster.id),
56+
&format!("Cluster{}Handler", if asynch { "Async" } else { "" }),
5757
Span::call_site(),
5858
);
5959

@@ -126,6 +126,21 @@ pub fn handler_adaptor(
126126
) -> TokenStream {
127127
let krate = context.rs_matter_crate.clone();
128128

129+
let handler_name = Ident::new(
130+
&format!("Cluster{}Handler", if asynch { "Async" } else { "" }),
131+
Span::call_site(),
132+
);
133+
134+
let handler_adaptor_name = Ident::new(
135+
&format!("Handler{}Adaptor", if asynch { "Async" } else { "" }),
136+
Span::call_site(),
137+
);
138+
139+
let generic_handler_name = Ident::new(
140+
&format!("{}Handler", if asynch { "Async" } else { "" }),
141+
Span::call_site(),
142+
);
143+
129144
let handler_adaptor_attribute_match = cluster
130145
.attributes
131146
.iter()
@@ -186,21 +201,6 @@ pub fn handler_adaptor(
186201
)
187202
};
188203

189-
let handler_name = Ident::new(
190-
&format!("{}{}Handler", if asynch { "Async" } else { "" }, cluster.id),
191-
Span::call_site(),
192-
);
193-
194-
let handler_adaptor_name = Ident::new(
195-
&format!("{}{}Adaptor", if asynch { "Async" } else { "" }, cluster.id),
196-
Span::call_site(),
197-
);
198-
199-
let generic_handler_name = Ident::new(
200-
&format!("{}Handler", if asynch { "Async" } else { "" }),
201-
Span::call_site(),
202-
);
203-
204204
let pasync = if asynch { quote!(async) } else { quote!() };
205205

206206
let stream = quote!(

rs-matter-macros-impl/src/idl/id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn idl_id_to_constant_name(s: &str) -> String {
3535
let str = s.strip_prefix('k').unwrap_or(s).to_case(Case::UpperSnake);
3636
let char = str.chars().next().unwrap();
3737
if !char.is_alphabetic() {
38-
format!("C{}", str)
38+
format!("C{str}")
3939
} else {
4040
str
4141
}
@@ -57,7 +57,7 @@ pub fn idl_id_to_enum_variant_name(s: &str) -> String {
5757
let str = s.strip_prefix('k').unwrap_or(s).to_string();
5858
let char = str.chars().next().unwrap();
5959
if !char.is_alphabetic() {
60-
format!("V{}", str)
60+
format!("V{str}")
6161
} else {
6262
str
6363
}

rs-matter-macros-impl/src/tlv.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,7 @@ fn get_unit_enum_func_and_tags(
124124
// "struct" is the default, so we make it equivalent to u8 for convenience
125125
"struct" | "u8" => {
126126
if tags.iter().any(|v| *v > 0xFF) {
127-
panic!(
128-
"Enum discriminator value larger that 0xFF for {:?}",
129-
enum_name
130-
)
127+
panic!("Enum discriminator value larger that 0xFF for {enum_name:?}")
131128
}
132129
(
133130
Ident::new("u8", Span::call_site()),
@@ -140,7 +137,7 @@ fn get_unit_enum_func_and_tags(
140137
Ident::new("u16", Span::call_site()),
141138
tags.into_iter().map(Literal::u16_suffixed).collect(),
142139
),
143-
_ => panic!("Invalid data type {:?} for enum {:?}", data_type, enum_name),
140+
_ => panic!("Invalid data type {data_type:?} for enum {enum_name:?}"),
144141
}
145142
}
146143

@@ -328,14 +325,11 @@ fn gen_totlv_for_enum(
328325
} else {
329326
// tags MUST be context-tags (up to u8 range)
330327
if tags.iter().any(|v| *v > u8::MAX as _) {
331-
panic!(
332-
"Enum discriminator value larger that 0xFF for {:?}",
333-
enum_name
334-
)
328+
panic!("Enum discriminator value larger that 0xFF for {enum_name:?}")
335329
}
336330

337331
if tags.len() > 6 {
338-
panic!("More than 6 enum variants for {:?}", enum_name)
332+
panic!("More than 6 enum variants for {enum_name:?}")
339333
}
340334

341335
let either_ident = if tags.len() != 2 {
@@ -702,10 +696,7 @@ fn gen_fromtlv_for_enum(
702696
} else {
703697
// tags MUST be context-tags (up to u8 range)
704698
if tags.iter().any(|v| *v > 0xFF) {
705-
panic!(
706-
"Enum discriminator value larger that 0xFF for {:?}",
707-
enum_name
708-
)
699+
panic!("Enum discriminator value larger that 0xFF for {enum_name:?}")
709700
}
710701
let tags = tags
711702
.into_iter()
@@ -770,7 +761,7 @@ fn gen_fromtlv_for_enum(
770761

771762
fn normalize_fromtlv_type(ty: &syn::Type) -> TokenStream {
772763
let Type::Path(type_path) = ty else {
773-
panic!("Don't know what to do {:?}", ty);
764+
panic!("Don't know what to do {ty:?}");
774765
};
775766

776767
// When paths are like `matter_rs::tlv::Nullable<u32>`

0 commit comments

Comments
 (0)