@@ -21,6 +21,7 @@ use syn::{
21
21
parse:: { Parse , ParseStream } ,
22
22
punctuated:: Punctuated ,
23
23
spanned:: Spanned ,
24
+ token,
24
25
token:: Bracket ,
25
26
AttrStyle , Error , Field , FieldsNamed , GenericParam , Ident , ItemStruct , LitInt , Path ,
26
27
PathSegment , Result , Token , Type , Visibility ,
@@ -34,6 +35,7 @@ mod kw {
34
35
syn:: custom_keyword!( consumes) ;
35
36
syn:: custom_keyword!( sends) ;
36
37
syn:: custom_keyword!( message_capacity) ;
38
+ syn:: custom_keyword!( signal_capacity) ;
37
39
}
38
40
39
41
#[ derive( Clone , Debug ) ]
@@ -49,7 +51,9 @@ pub(crate) enum SubSysAttrItem {
49
51
/// Message to be consumed by this subsystem.
50
52
Consumes ( Consumes ) ,
51
53
/// Custom message channels capacity for this subsystem
52
- MessageChannelCapacity ( MessageCapacity ) ,
54
+ MessageChannelCapacity ( ChannelCapacity < kw:: message_capacity > ) ,
55
+ /// Custom signal channels capacity for this subsystem
56
+ SignalChannelCapacity ( ChannelCapacity < kw:: signal_capacity > ) ,
53
57
}
54
58
55
59
impl Parse for SubSysAttrItem {
@@ -62,7 +66,9 @@ impl Parse for SubSysAttrItem {
62
66
} else if lookahead. peek ( kw:: sends) {
63
67
Self :: Sends ( input. parse :: < Sends > ( ) ?)
64
68
} else if lookahead. peek ( kw:: message_capacity) {
65
- Self :: MessageChannelCapacity ( input. parse :: < MessageCapacity > ( ) ?)
69
+ Self :: MessageChannelCapacity ( input. parse :: < ChannelCapacity < kw:: message_capacity > > ( ) ?)
70
+ } else if lookahead. peek ( kw:: signal_capacity) {
71
+ Self :: SignalChannelCapacity ( input. parse :: < ChannelCapacity < kw:: signal_capacity > > ( ) ?)
66
72
} else {
67
73
Self :: Consumes ( input. parse :: < Consumes > ( ) ?)
68
74
} )
@@ -87,6 +93,9 @@ impl ToTokens for SubSysAttrItem {
87
93
Self :: MessageChannelCapacity ( _) => {
88
94
quote ! { }
89
95
} ,
96
+ Self :: SignalChannelCapacity ( _) => {
97
+ quote ! { }
98
+ } ,
90
99
} ;
91
100
tokens. extend ( ts. into_iter ( ) ) ;
92
101
}
@@ -113,8 +122,10 @@ pub(crate) struct SubSysField {
113
122
/// Avoids dispatching `Wrapper` type messages, but generates the variants.
114
123
/// Does not require the subsystem to be instantiated with the builder pattern.
115
124
pub ( crate ) wip : bool ,
116
- /// Custom message capacity
125
+ /// Custom message channel capacity
117
126
pub ( crate ) message_capacity : Option < usize > ,
127
+ /// Custom signal channel capacity
128
+ pub ( crate ) signal_capacity : Option < usize > ,
118
129
}
119
130
120
131
impl SubSysField {
@@ -300,18 +311,18 @@ impl Parse for Consumes {
300
311
}
301
312
302
313
#[ derive( Debug , Clone ) ]
303
- pub ( crate ) struct MessageCapacity {
314
+ pub ( crate ) struct ChannelCapacity < T : Parse > {
304
315
#[ allow( dead_code) ]
305
- tag : kw :: message_capacity ,
316
+ tag : T ,
306
317
#[ allow( dead_code) ]
307
- colon_token : Token ! [ : ] ,
318
+ colon_token : token :: Colon ,
308
319
value : usize ,
309
320
}
310
321
311
- impl Parse for MessageCapacity {
322
+ impl < T : Parse > Parse for ChannelCapacity < T > {
312
323
fn parse ( input : syn:: parse:: ParseStream ) -> Result < Self > {
313
324
Ok ( Self {
314
- tag : input. parse :: < kw :: message_capacity > ( ) ?,
325
+ tag : input. parse :: < T > ( ) ?,
315
326
colon_token : input. parse ( ) ?,
316
327
value : input. parse :: < LitInt > ( ) ?. base10_parse :: < usize > ( ) ?,
317
328
} )
@@ -331,8 +342,10 @@ pub(crate) struct SubSystemAttrItems {
331
342
/// The message type being consumed by the subsystem.
332
343
pub ( crate ) consumes : Option < Consumes > ,
333
344
pub ( crate ) sends : Option < Sends > ,
334
- /// Custom channel capacity
335
- pub ( crate ) message_capacity : Option < MessageCapacity > ,
345
+ /// Custom message channel capacity
346
+ pub ( crate ) message_capacity : Option < ChannelCapacity < kw:: message_capacity > > ,
347
+ /// Custom signal channel capacity
348
+ pub ( crate ) signal_capacity : Option < ChannelCapacity < kw:: signal_capacity > > ,
336
349
}
337
350
338
351
impl Parse for SubSystemAttrItems {
@@ -373,8 +386,9 @@ impl Parse for SubSystemAttrItems {
373
386
let blocking = extract_variant ! ( unique, Blocking ; default = false ) ;
374
387
let wip = extract_variant ! ( unique, Wip ; default = false ) ;
375
388
let message_capacity = extract_variant ! ( unique, MessageChannelCapacity take ) ;
389
+ let signal_capacity = extract_variant ! ( unique, SignalChannelCapacity take ) ;
376
390
377
- Ok ( Self { blocking, wip, sends, consumes, message_capacity } )
391
+ Ok ( Self { blocking, wip, sends, consumes, message_capacity, signal_capacity } )
378
392
}
379
393
}
380
394
@@ -507,7 +521,10 @@ impl OrchestraInfo {
507
521
. collect :: < Vec < _ > > ( )
508
522
}
509
523
510
- pub ( crate ) fn channel_capacities_without_wip ( & self , default_capacity : usize ) -> Vec < LitInt > {
524
+ pub ( crate ) fn message_channel_capacities_without_wip (
525
+ & self ,
526
+ default_capacity : usize ,
527
+ ) -> Vec < LitInt > {
511
528
self . subsystems
512
529
. iter ( )
513
530
. filter ( |ssf| !ssf. wip )
@@ -520,6 +537,22 @@ impl OrchestraInfo {
520
537
. collect :: < Vec < _ > > ( )
521
538
}
522
539
540
+ pub ( crate ) fn signal_channel_capacities_without_wip (
541
+ & self ,
542
+ default_capacity : usize ,
543
+ ) -> Vec < LitInt > {
544
+ self . subsystems
545
+ . iter ( )
546
+ . filter ( |ssf| !ssf. wip )
547
+ . map ( |ssf| {
548
+ LitInt :: new (
549
+ & ( ssf. signal_capacity . unwrap_or ( default_capacity) . to_string ( ) ) ,
550
+ ssf. signal_capacity . span ( ) ,
551
+ )
552
+ } )
553
+ . collect :: < Vec < _ > > ( )
554
+ }
555
+
523
556
pub ( crate ) fn consumes_without_wip ( & self ) -> Vec < Path > {
524
557
self . subsystems
525
558
. iter ( )
@@ -601,8 +634,15 @@ impl OrchestraGuts {
601
634
}
602
635
unique_subsystem_idents. insert ( generic. clone ( ) ) ;
603
636
604
- let SubSystemAttrItems { wip, blocking, consumes, sends, message_capacity, .. } =
605
- subsystem_attrs;
637
+ let SubSystemAttrItems {
638
+ wip,
639
+ blocking,
640
+ consumes,
641
+ sends,
642
+ message_capacity,
643
+ signal_capacity,
644
+ ..
645
+ } = subsystem_attrs;
606
646
607
647
// messages to be sent
608
648
let sends = if let Some ( sends) = sends {
@@ -612,6 +652,7 @@ impl OrchestraGuts {
612
652
} ;
613
653
let consumes = consumes. map ( |consumes| consumes. consumes ) ;
614
654
let message_capacity = message_capacity. map ( |capacity| capacity. value ) ;
655
+ let signal_capacity = signal_capacity. map ( |capacity| capacity. value ) ;
615
656
616
657
subsystems. push ( SubSysField {
617
658
name : ident,
@@ -621,6 +662,7 @@ impl OrchestraGuts {
621
662
wip,
622
663
blocking,
623
664
message_capacity,
665
+ signal_capacity,
624
666
} ) ;
625
667
} else {
626
668
// collect the "baggage"
0 commit comments