Daemonize the musicbrainz thread #217
@ -10,7 +10,7 @@ use crate::tui::{
|
|||||||
machine::{match_state::MatchState, App, AppInner, AppMachine},
|
machine::{match_state::MatchState, App, AppInner, AppMachine},
|
||||||
AppPublicState, AppState, IAppEventFetch, IAppInteractFetch,
|
AppPublicState, AppState, IAppEventFetch, IAppInteractFetch,
|
||||||
},
|
},
|
||||||
lib::external::musicbrainz::daemon::{
|
lib::interface::musicbrainz::daemon::{
|
||||||
Error as DaemonError, IMbJobSender, MbApiResult, MbParams, ResultSender,
|
Error as DaemonError, IMbJobSender, MbApiResult, MbParams, ResultSender,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -13,7 +13,7 @@ use crate::tui::{
|
|||||||
selection::Selection, AppMode, AppPublic, AppPublicInner, AppPublicState, AppState, IApp,
|
selection::Selection, AppMode, AppPublic, AppPublicInner, AppPublicState, AppState, IApp,
|
||||||
IAppAccess, IAppBase, IAppState,
|
IAppAccess, IAppBase, IAppState,
|
||||||
},
|
},
|
||||||
lib::{external::musicbrainz::daemon::IMbJobSender, IMusicHoard},
|
lib::{interface::musicbrainz::daemon::IMbJobSender, IMusicHoard},
|
||||||
};
|
};
|
||||||
|
|
||||||
use browse_state::BrowseState;
|
use browse_state::BrowseState;
|
||||||
|
68
src/tui/lib/external/musicbrainz/daemon/mod.rs
vendored
68
src/tui/lib/external/musicbrainz/daemon/mod.rs
vendored
@ -1,25 +1,17 @@
|
|||||||
use std::{collections::VecDeque, fmt, sync::mpsc, thread, time};
|
use std::{collections::VecDeque, sync::mpsc, thread, time};
|
||||||
|
|
||||||
use musichoard::collection::{album::AlbumMeta, artist::ArtistMeta, musicbrainz::Mbid};
|
|
||||||
|
|
||||||
use crate::tui::{
|
use crate::tui::{
|
||||||
app::MatchStateInfo,
|
app::MatchStateInfo,
|
||||||
event::IFetchCompleteEventSender,
|
event::IFetchCompleteEventSender,
|
||||||
lib::interface::musicbrainz::api::{Error as ApiError, IMusicBrainz},
|
lib::interface::musicbrainz::{
|
||||||
|
api::{Error as ApiError, IMusicBrainz},
|
||||||
|
daemon::{Error, IMbJobSender, MbParams, ResultSender, SearchParams},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub enum Error {
|
enum JobError {
|
||||||
|
JobQueueEmpty,
|
||||||
EventChannelDisconnected,
|
EventChannelDisconnected,
|
||||||
JobChannelDisconnected,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
Error::EventChannelDisconnected => write!(f, "the event channel is disconnected"),
|
|
||||||
Error::JobChannelDisconnected => write!(f, "the job channel is disconnected"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MusicBrainzDaemon {
|
pub struct MusicBrainzDaemon {
|
||||||
@ -29,11 +21,6 @@ pub struct MusicBrainzDaemon {
|
|||||||
event_sender: Box<dyn IFetchCompleteEventSender>,
|
event_sender: Box<dyn IFetchCompleteEventSender>,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum JobError {
|
|
||||||
JobQueueEmpty,
|
|
||||||
EventChannelDisconnected,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct JobQueue {
|
struct JobQueue {
|
||||||
foreground_queue: VecDeque<JobInstance>,
|
foreground_queue: VecDeque<JobInstance>,
|
||||||
background_queue: VecDeque<JobInstance>,
|
background_queue: VecDeque<JobInstance>,
|
||||||
@ -55,8 +42,6 @@ enum JobPriority {
|
|||||||
Background,
|
Background,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type MbApiResult = Result<MatchStateInfo, ApiError>;
|
|
||||||
pub type ResultSender = mpsc::Sender<MbApiResult>;
|
|
||||||
struct JobInstance {
|
struct JobInstance {
|
||||||
result_sender: ResultSender,
|
result_sender: ResultSender,
|
||||||
requests: VecDeque<MbParams>,
|
requests: VecDeque<MbParams>,
|
||||||
@ -81,37 +66,6 @@ impl JobInstance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum MbParams {
|
|
||||||
Search(SearchParams),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MbParams {
|
|
||||||
pub fn search_artist(artist: ArtistMeta) -> Self {
|
|
||||||
MbParams::Search(SearchParams::Artist(SearchArtistParams { artist }))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn search_release_group(arid: Mbid, album: AlbumMeta) -> Self {
|
|
||||||
MbParams::Search(SearchParams::ReleaseGroup(SearchReleaseGroupParams {
|
|
||||||
arid,
|
|
||||||
album,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum SearchParams {
|
|
||||||
Artist(SearchArtistParams),
|
|
||||||
ReleaseGroup(SearchReleaseGroupParams),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct SearchArtistParams {
|
|
||||||
artist: ArtistMeta,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct SearchReleaseGroupParams {
|
|
||||||
arid: Mbid,
|
|
||||||
album: AlbumMeta,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct JobChannel {
|
pub struct JobChannel {
|
||||||
sender: mpsc::Sender<Job>,
|
sender: mpsc::Sender<Job>,
|
||||||
receiver: mpsc::Receiver<Job>,
|
receiver: mpsc::Receiver<Job>,
|
||||||
@ -144,14 +98,6 @@ impl JobChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait IMbJobSender {
|
|
||||||
fn submit_background_job(
|
|
||||||
&self,
|
|
||||||
result_sender: ResultSender,
|
|
||||||
requests: VecDeque<MbParams>,
|
|
||||||
) -> Result<(), Error>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IMbJobSender for JobSender {
|
impl IMbJobSender for JobSender {
|
||||||
fn submit_background_job(
|
fn submit_background_job(
|
||||||
&self,
|
&self,
|
||||||
|
61
src/tui/lib/interface/musicbrainz/daemon/mod.rs
Normal file
61
src/tui/lib/interface/musicbrainz/daemon/mod.rs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
use std::{collections::VecDeque, fmt, sync::mpsc};
|
||||||
|
|
||||||
|
use musichoard::collection::{album::AlbumMeta, artist::ArtistMeta, musicbrainz::Mbid};
|
||||||
|
|
||||||
|
use crate::tui::{app::MatchStateInfo, lib::interface::musicbrainz::api::Error as MbApiError};
|
||||||
|
|
||||||
|
pub enum Error {
|
||||||
|
EventChannelDisconnected,
|
||||||
|
JobChannelDisconnected,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Error {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Error::EventChannelDisconnected => write!(f, "the event channel is disconnected"),
|
||||||
|
Error::JobChannelDisconnected => write!(f, "the job channel is disconnected"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type MbApiResult = Result<MatchStateInfo, MbApiError>;
|
||||||
|
pub type ResultSender = mpsc::Sender<MbApiResult>;
|
||||||
|
|
||||||
|
pub trait IMbJobSender {
|
||||||
|
fn submit_background_job(
|
||||||
|
&self,
|
||||||
|
result_sender: ResultSender,
|
||||||
|
requests: VecDeque<MbParams>,
|
||||||
|
) -> Result<(), Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum MbParams {
|
||||||
|
Search(SearchParams),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum SearchParams {
|
||||||
|
Artist(SearchArtistParams),
|
||||||
|
ReleaseGroup(SearchReleaseGroupParams),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct SearchArtistParams {
|
||||||
|
pub artist: ArtistMeta,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct SearchReleaseGroupParams {
|
||||||
|
pub arid: Mbid,
|
||||||
|
pub album: AlbumMeta,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MbParams {
|
||||||
|
pub fn search_artist(artist: ArtistMeta) -> Self {
|
||||||
|
MbParams::Search(SearchParams::Artist(SearchArtistParams { artist }))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn search_release_group(arid: Mbid, album: AlbumMeta) -> Self {
|
||||||
|
MbParams::Search(SearchParams::ReleaseGroup(SearchReleaseGroupParams {
|
||||||
|
arid,
|
||||||
|
album,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
@ -1 +1,2 @@
|
|||||||
pub mod api;
|
pub mod api;
|
||||||
|
pub mod daemon;
|
||||||
|
Loading…
Reference in New Issue
Block a user