Add a channel for replies to Player across thread
This commit is contained in:
parent
ba45cbf8fe
commit
b2169abc94
4 changed files with 45 additions and 8 deletions
|
@ -8,7 +8,7 @@ use std::{
|
||||||
|
|
||||||
use std::sync::mpsc::Receiver;
|
use std::sync::mpsc::Receiver;
|
||||||
|
|
||||||
use crate::{config::Settings, utils::Error};
|
use crate::{config::Settings, player::PlayerEvent, utils::Error};
|
||||||
|
|
||||||
pub enum AudioEvent {}
|
pub enum AudioEvent {}
|
||||||
|
|
||||||
|
@ -16,11 +16,13 @@ pub struct SoundManager {
|
||||||
settings: Arc<Settings>,
|
settings: Arc<Settings>,
|
||||||
error_chan: Sender<Error>,
|
error_chan: Sender<Error>,
|
||||||
audio_controls: Receiver<AudioEvent>,
|
audio_controls: Receiver<AudioEvent>,
|
||||||
|
player_chan: Sender<PlayerEvent>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
settings: Arc<Settings>,
|
settings: Arc<Settings>,
|
||||||
error_chan: Sender<Error>,
|
error_chan: Sender<Error>,
|
||||||
|
player_chan: Sender<PlayerEvent>,
|
||||||
) -> Result<Sender<AudioEvent>, Error> {
|
) -> Result<Sender<AudioEvent>, Error> {
|
||||||
let (audio_control_in, audio_control_out) = channel();
|
let (audio_control_in, audio_control_out) = channel();
|
||||||
thread::spawn(|| {
|
thread::spawn(|| {
|
||||||
|
@ -28,6 +30,7 @@ pub fn init(
|
||||||
settings,
|
settings,
|
||||||
error_chan,
|
error_chan,
|
||||||
audio_controls: audio_control_out,
|
audio_controls: audio_control_out,
|
||||||
|
player_chan,
|
||||||
};
|
};
|
||||||
loop {}
|
loop {}
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,13 +11,17 @@ mod utils;
|
||||||
fn init() -> Result<Receiver<utils::Error>, utils::Error> {
|
fn init() -> Result<Receiver<utils::Error>, utils::Error> {
|
||||||
let settings = config::init()?;
|
let settings = config::init()?;
|
||||||
let (error_in, error_out) = channel();
|
let (error_in, error_out) = channel();
|
||||||
let audio_event_chan = audio::init(settings.clone(), error_in.clone())?;
|
let (player_events_in, player_events_out) = channel();
|
||||||
let api_event_chan = ssonic::init(settings.clone(), error_in.clone())?;
|
let audio_event_chan =
|
||||||
|
audio::init(settings.clone(), error_in.clone(), player_events_in.clone())?;
|
||||||
|
let api_event_chan =
|
||||||
|
ssonic::init(settings.clone(), error_in.clone(), player_events_in.clone())?;
|
||||||
let mut player = player::init(
|
let mut player = player::init(
|
||||||
settings.clone(),
|
settings.clone(),
|
||||||
audio_event_chan,
|
audio_event_chan,
|
||||||
api_event_chan,
|
api_event_chan,
|
||||||
error_in.clone(),
|
error_in.clone(),
|
||||||
|
player_events_out,
|
||||||
)?;
|
)?;
|
||||||
player.begin()?;
|
player.begin()?;
|
||||||
Ok(error_out)
|
Ok(error_out)
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
use std::sync::{mpsc::Sender, Arc};
|
use std::sync::{
|
||||||
|
mpsc::{Receiver, Sender},
|
||||||
|
Arc,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{audio::AudioEvent, config::Settings, ssonic::APIEvent, utils::Error};
|
use crate::{audio::AudioEvent, config::Settings, ssonic::APIEvent, utils::Error};
|
||||||
|
|
||||||
|
pub struct PlayerEvent {}
|
||||||
|
|
||||||
pub struct Player {}
|
pub struct Player {}
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
|
@ -9,6 +14,7 @@ pub fn init(
|
||||||
audio_chan: Sender<AudioEvent>,
|
audio_chan: Sender<AudioEvent>,
|
||||||
api_chan: Sender<APIEvent>,
|
api_chan: Sender<APIEvent>,
|
||||||
error_chan: Sender<Error>,
|
error_chan: Sender<Error>,
|
||||||
|
player_chan: Receiver<PlayerEvent>,
|
||||||
) -> Result<Player, Error> {
|
) -> Result<Player, Error> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,33 @@
|
||||||
use std::sync::{mpsc::Sender, Arc};
|
use std::{
|
||||||
|
sync::{
|
||||||
|
mpsc::{channel, Receiver, Sender},
|
||||||
|
Arc,
|
||||||
|
},
|
||||||
|
thread,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{config::Settings, utils::Error};
|
use crate::{config::Settings, player::PlayerEvent, utils::Error};
|
||||||
|
|
||||||
pub enum APIEvent {}
|
pub enum APIEvent {}
|
||||||
|
|
||||||
pub fn init(settings: Arc<Settings>, error_chan: Sender<Error>) -> Result<Sender<APIEvent>, Error> {
|
pub struct APIClient {
|
||||||
unimplemented!()
|
settings: Arc<Settings>,
|
||||||
|
error_chan: Sender<Error>,
|
||||||
|
api_requests: Receiver<APIEvent>,
|
||||||
|
player_chan: Sender<PlayerEvent>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init(
|
||||||
|
settings: Arc<Settings>,
|
||||||
|
error_chan: Sender<Error>,
|
||||||
|
player_chan: Sender<PlayerEvent>,
|
||||||
|
) -> Result<Sender<APIEvent>, Error> {
|
||||||
|
let (api_requests_in, api_requests_out) = channel();
|
||||||
|
thread::spawn(|| APIClient {
|
||||||
|
settings,
|
||||||
|
error_chan,
|
||||||
|
api_requests: api_requests_out,
|
||||||
|
player_chan,
|
||||||
|
});
|
||||||
|
Ok(api_requests_in)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue