diff --git a/src/music_controller/controller.rs b/src/music_controller/controller.rs index 6a67653..950d7d5 100644 --- a/src/music_controller/controller.rs +++ b/src/music_controller/controller.rs @@ -81,18 +81,24 @@ pub enum PlayerResponse { pub enum LibraryCommand { Song(Uuid), + AllSongs, + GetLibrary, } pub enum LibraryResponse { - Songs(Song), + Song(Song), + AllSongs(Vec), + Library(MusicLibrary), } enum InnerLibraryCommand { Song(Uuid), + AllSongs, } enum InnerLibraryResponse<'a> { Song(&'a Song), + AllSongs(&'a Vec), } pub enum QueueCommand { @@ -120,12 +126,12 @@ pub struct ControllerInput { } pub struct ControllerHandle { - lib_mail: MailMan, - player_mail: MailMan, + pub lib_mail: MailMan, + pub player_mail: MailMan, } impl ControllerHandle { - fn new(library: MusicLibrary, config: Arc>) -> (Self, ControllerInput) { + pub fn new(library: MusicLibrary, config: Arc>) -> (Self, ControllerInput) { let lib_mail = MailMan::double(); let player_mail = MailMan::double(); @@ -195,29 +201,24 @@ impl<'c, P: Player + Send + Sync> Controller<'c, P> { ) .await .unwrap(); - }) - .await; + }); scope .spawn(async move { Controller::

::player_event_loop(player, player_mail.0) .await .unwrap(); - }) - .await; + }); scope .spawn(async { - Controller::

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

::inner_library_loop(inner_lib_mail.1, &mut library).await .unwrap() - }) - .await; + }); scope .spawn(async { Controller::

::outer_library_loop(lib_mail, inner_lib_mail.0) .await .unwrap(); - }) - .await + }); }) .await; }) @@ -315,15 +316,33 @@ impl<'c, P: Player + Send + Sync> Controller<'c, P> { lib_mail: MailMan, inner_lib_mail: MailMan>, ) -> Result<(), ()> { + println!("outer lib loop"); while true { match lib_mail.recv().await.unwrap() { LibraryCommand::Song(uuid) => { + println!("got song commandf"); inner_lib_mail .send(InnerLibraryCommand::Song(uuid)) .await .unwrap(); let x = inner_lib_mail.recv().await.unwrap(); } + LibraryCommand::AllSongs => { + println!("got command"); + inner_lib_mail + .send(InnerLibraryCommand::AllSongs) + .await + .unwrap(); + println!("sent"); + let x = inner_lib_mail.recv().await.unwrap(); + println!("recieved"); + if let InnerLibraryResponse::AllSongs(songs) = x { + lib_mail.send(LibraryResponse::AllSongs(songs.clone())).await.unwrap(); + } else { + unreachable!() + } + }, + _ => { todo!() } } } Ok(()) @@ -342,6 +361,12 @@ impl<'c, P: Player + Send + Sync> Controller<'c, P> { .await .unwrap(); } + InnerLibraryCommand::AllSongs => { + let songs: &'c Vec = &library.library; + lib_mail.send(InnerLibraryResponse::AllSongs(songs)) + .await + .unwrap(); + } } } Ok(())