From ab5c65d64d02855807e62986868f71b60b499490 Mon Sep 17 00:00:00 2001 From: MrDulfin Date: Sun, 29 Sep 2024 23:19:03 -0400 Subject: [PATCH] added Controller Handle and Input structs --- src/music_controller/controller.rs | 43 +++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/music_controller/controller.rs b/src/music_controller/controller.rs index 12ce0fa..cf5ce9a 100644 --- a/src/music_controller/controller.rs +++ b/src/music_controller/controller.rs @@ -108,16 +108,31 @@ pub enum QueueResponse { Item(QueueItem), } + +pub struct ControllerInput<'a> { + player_mail: ( + MailMan, + MailMan, + ), + lib_mail: MailMan, + library: &'a mut MusicLibrary, + config: Arc>, +} + +pub struct ControllerHandle { + lib_mail: MailMan, + player_mail: MailMan, +} + #[allow(unused_variables)] impl<'c, P: Player + Send + Sync> Controller<'c, P> { pub async fn start( - player_mail: ( - MailMan, - MailMan, - ), - lib_mail: MailMan, - mut library: MusicLibrary, - config: Arc>, + ControllerInput { + player_mail, + lib_mail, + library, + config + }: ControllerInput<'c> ) -> Result<(), Box> where P: Player, @@ -171,7 +186,7 @@ impl<'c, P: Player + Send + Sync> Controller<'c, P> { .await; scope .spawn(async { - Controller::

::inner_library_loop(inner_lib_mail.1, &mut library) + Controller::

::inner_library_loop(inner_lib_mail.1, library) .await .unwrap() }) @@ -420,7 +435,7 @@ mod test_super { let a = spawn(move || { futures::executor::block_on(async { let config = Config::read_file(PathBuf::from(std::env!("CONFIG-PATH"))).unwrap(); - let library = { + let mut library = { MusicLibrary::init( config.libraries.get_default().unwrap().path.clone(), config.libraries.get_default().unwrap().uuid, @@ -429,10 +444,12 @@ mod test_super { }; Controller::::start( - player_mail, - lib_mail.1, - library, - Arc::new(RwLock::new(config)), + crate::music_controller::controller::ControllerInput { + player_mail, + lib_mail: lib_mail.1, + library: &mut library, + config: Arc::new(RwLock::new(config)), + } ) .await .unwrap();