@@ -21,7 +21,7 @@ use anyhow::Result;
21
21
use async_std:: stream:: StreamExt ;
22
22
use async_std:: sync:: Arc ;
23
23
use futures_util:: FutureExt ;
24
- use log:: { info, warn} ;
24
+ use log:: { error , info, warn} ;
25
25
use serde:: { Deserialize , Serialize } ;
26
26
27
27
use super :: systemd:: { Service , ServiceAction } ;
@@ -41,21 +41,37 @@ mod demo_mode;
41
41
#[ cfg( not( feature = "demo_mode" ) ) ]
42
42
mod installer;
43
43
44
+ #[ cfg( not( feature = "demo_mode" ) ) ]
45
+ use installer:: InstallerProxy ;
46
+
44
47
#[ cfg( not( feature = "demo_mode" ) ) ]
45
48
mod poller;
46
49
47
50
#[ cfg( not( feature = "demo_mode" ) ) ]
48
- use installer :: InstallerProxy ;
51
+ use poller :: PollerProxy ;
49
52
50
53
#[ cfg( feature = "demo_mode" ) ]
51
54
mod imports {
52
55
pub ( super ) const CHANNELS_DIR : & str = "demo_files/usr/share/tacd/update_channels" ;
56
+
57
+ pub ( super ) struct PollerProxy < ' a > {
58
+ _dummy : & ' a ( ) ,
59
+ }
60
+
61
+ impl PollerProxy < ' _ > {
62
+ pub async fn new < C > ( _conn : C ) -> Option < Self > {
63
+ Some ( Self { _dummy : & ( ) } )
64
+ }
65
+
66
+ pub async fn poll ( & self ) -> zbus:: Result < ( ) > {
67
+ Ok ( ( ) )
68
+ }
69
+ }
53
70
}
54
71
55
72
#[ cfg( not( feature = "demo_mode" ) ) ]
56
73
mod imports {
57
74
pub ( super ) use anyhow:: bail;
58
- pub ( super ) use log:: error;
59
75
60
76
pub ( super ) const CHANNELS_DIR : & str = "/usr/share/tacd/update_channels" ;
61
77
}
@@ -186,11 +202,14 @@ fn would_reboot_into_other_slot(slot_status: &SlotStatus, primary: Option<String
186
202
}
187
203
188
204
async fn channel_list_update_task (
205
+ conn : Arc < Connection > ,
189
206
reload : Arc < Topic < bool > > ,
190
207
enable_polling : Arc < Topic < bool > > ,
191
208
channels : Arc < Topic < Channels > > ,
192
209
rauc_service : Service ,
193
210
) -> Result < ( ) > {
211
+ let poller = PollerProxy :: new ( & conn) . await . unwrap ( ) ;
212
+
194
213
let ( reload_stream, _) = reload. subscribe_unbounded ( ) ;
195
214
let ( mut enable_polling_stream, _) = enable_polling. subscribe_unbounded ( ) ;
196
215
@@ -252,6 +271,14 @@ async fn channel_list_update_task(
252
271
}
253
272
254
273
status_subscription. unsubscribe ( ) ;
274
+
275
+ if enable_polling {
276
+ info ! ( "Trigger a poll" ) ;
277
+
278
+ if let Err ( err) = poller. poll ( ) . await {
279
+ error ! ( "Failed to poll for updates: {err}" ) ;
280
+ }
281
+ }
255
282
}
256
283
}
257
284
@@ -295,6 +322,7 @@ impl Rauc {
295
322
wtb. spawn_task (
296
323
"rauc-channel-list-update" ,
297
324
channel_list_update_task (
325
+ Arc :: new ( Connection ) ,
298
326
inst. reload . clone ( ) ,
299
327
inst. enable_polling . clone ( ) ,
300
328
inst. channels . clone ( ) ,
@@ -448,6 +476,56 @@ impl Rauc {
448
476
Ok ( ( ) )
449
477
} ) ?;
450
478
479
+ let conn_task = conn. clone ( ) ;
480
+ let channels = inst. channels . clone ( ) ;
481
+
482
+ // Forward the "Poller::status" property to the broker framework
483
+ wtb. spawn_task ( "rauc-forward-poller-status" , async move {
484
+ let proxy = PollerProxy :: new ( & conn_task) . await . unwrap ( ) ;
485
+
486
+ let mut stream = proxy. receive_status_changed ( ) . await ;
487
+
488
+ if let Ok ( status) = proxy. status ( ) . await {
489
+ channels. modify ( |chs| {
490
+ let mut chs = chs?;
491
+
492
+ match chs. update_from_poll_status ( status. into ( ) ) {
493
+ Ok ( true ) => Some ( chs) ,
494
+ Ok ( false ) => None ,
495
+ Err ( e) => {
496
+ warn ! ( "Could not update channel list from poll status: {e}" ) ;
497
+ None
498
+ }
499
+ }
500
+ } ) ;
501
+ }
502
+
503
+ while let Some ( status) = stream. next ( ) . await {
504
+ let status = match status. get ( ) . await {
505
+ Ok ( status) => status,
506
+ Err ( e) => {
507
+ warn ! ( "Could not get poll status: {e}" ) ;
508
+ continue ;
509
+ }
510
+ } ;
511
+
512
+ channels. modify ( |chs| {
513
+ let mut chs = chs?;
514
+
515
+ match chs. update_from_poll_status ( status. into ( ) ) {
516
+ Ok ( true ) => Some ( chs) ,
517
+ Ok ( false ) => None ,
518
+ Err ( e) => {
519
+ warn ! ( "Could not update channel list from poll status: {e}" ) ;
520
+ None
521
+ }
522
+ }
523
+ } ) ;
524
+ }
525
+
526
+ Ok ( ( ) )
527
+ } ) ?;
528
+
451
529
let conn_task = conn. clone ( ) ;
452
530
let channels = inst. channels . clone ( ) ;
453
531
let ( mut install_stream, _) = inst. install . clone ( ) . subscribe_unbounded ( ) ;
@@ -503,6 +581,7 @@ impl Rauc {
503
581
wtb. spawn_task (
504
582
"rauc-channel-list-update" ,
505
583
channel_list_update_task (
584
+ conn. clone ( ) ,
506
585
inst. reload . clone ( ) ,
507
586
inst. enable_polling . clone ( ) ,
508
587
inst. channels . clone ( ) ,
0 commit comments