From 3e512092bde8f555115fc0ee5abeed3240c97cc1 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sun, 1 Dec 2024 19:16:44 +0100 Subject: [PATCH] Add existing command parsers to the main request parser --- src/commands.rs | 9 +- src/commands/audio_output_devices.rs | 6 ++ src/commands/client_to_client.rs | 6 ++ src/commands/controlling_playback.rs | 10 +++ src/commands/playback_options.rs | 13 +++ src/commands/playback_options/getvol.rs | 4 +- src/commands/playback_options/setvol.rs | 7 +- src/commands/playback_options/volume.rs | 8 +- src/commands/querying_mpd_status.rs | 6 ++ src/commands/queue.rs | 23 ++++++ src/request.rs | 105 +++++++++++++++++++++--- 11 files changed, 172 insertions(+), 25 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index ef650b3..beb6d44 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -9,9 +9,12 @@ mod playback_options; mod querying_mpd_status; mod queue; -pub use querying_mpd_status::clearerror::ClearError; -pub use querying_mpd_status::idle::Idle; -pub use querying_mpd_status::status::Status; +pub use audio_output_devices::*; +pub use client_to_client::*; +pub use controlling_playback::*; +pub use playback_options::*; +pub use querying_mpd_status::*; +pub use queue::*; pub trait Command { type Response; diff --git a/src/commands/audio_output_devices.rs b/src/commands/audio_output_devices.rs index 872fbb2..87c4bf0 100644 --- a/src/commands/audio_output_devices.rs +++ b/src/commands/audio_output_devices.rs @@ -3,3 +3,9 @@ pub mod enableoutput; pub mod outputs; pub mod outputset; pub mod toggleoutput; + +pub use disableoutput::DisableOutput; +pub use enableoutput::EnableOutput; +pub use outputs::Outputs; +pub use outputset::OutputSet; +pub use toggleoutput::ToggleOutput; \ No newline at end of file diff --git a/src/commands/client_to_client.rs b/src/commands/client_to_client.rs index daf105c..d8adc90 100644 --- a/src/commands/client_to_client.rs +++ b/src/commands/client_to_client.rs @@ -3,3 +3,9 @@ pub mod readmessages; pub mod sendmessage; pub mod subscribe; pub mod unsubscribe; + +pub use channels::Channels; +pub use readmessages::ReadMessages; +pub use sendmessage::SendMessage; +pub use subscribe::Subscribe; +pub use unsubscribe::Unsubscribe; diff --git a/src/commands/controlling_playback.rs b/src/commands/controlling_playback.rs index 1437847..6b6b7c3 100644 --- a/src/commands/controlling_playback.rs +++ b/src/commands/controlling_playback.rs @@ -7,3 +7,13 @@ pub mod seek; pub mod seekcur; pub mod seekid; pub mod stop; + +pub use next::Next; +pub use pause::Pause; +pub use play::Play; +pub use playid::PlayId; +pub use previous::Previous; +pub use seek::Seek; +pub use seekcur::SeekCur; +pub use seekid::SeekId; +pub use stop::Stop; diff --git a/src/commands/playback_options.rs b/src/commands/playback_options.rs index 408c2e1..2b60ed6 100644 --- a/src/commands/playback_options.rs +++ b/src/commands/playback_options.rs @@ -10,3 +10,16 @@ pub mod replay_gain_status; pub mod setvol; pub mod single; pub mod volume; + +pub use consume::Consume; +pub use crossfade::Crossfade; +pub use getvol::GetVol; +pub use mixrampdb::MixRampDb; +pub use mixrampdelay::MixRampDelay; +pub use random::Random; +pub use repeat::Repeat; +pub use replay_gain_mode::ReplayGainMode; +pub use replay_gain_status::ReplayGainStatus; +pub use setvol::SetVol; +pub use single::Single; +pub use volume::Volume; diff --git a/src/commands/playback_options/getvol.rs b/src/commands/playback_options/getvol.rs index cf6271b..bd83ded 100644 --- a/src/commands/playback_options/getvol.rs +++ b/src/commands/playback_options/getvol.rs @@ -1,12 +1,12 @@ use crate::{ commands::{Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError}, - request::Volume, + request::VolumeValue, }; pub struct GetVol; impl Command for GetVol { - type Response = Volume; + type Response = VolumeValue; const COMMAND: &'static str = "getvol"; fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> { diff --git a/src/commands/playback_options/setvol.rs b/src/commands/playback_options/setvol.rs index 860969b..dc1f8f2 100644 --- a/src/commands/playback_options/setvol.rs +++ b/src/commands/playback_options/setvol.rs @@ -5,7 +5,7 @@ use crate::{ Command, Request, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError, }, - request::Volume, + request::VolumeValue, }; pub struct SetVol; @@ -16,9 +16,8 @@ impl Command for SetVol { fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> { let volume = match parts.next() { - Some(s) => { - Volume::from_str(s).map_err(|_| RequestParserError::SyntaxError(0, s.to_owned()))? - } + Some(s) => VolumeValue::from_str(s) + .map_err(|_| RequestParserError::SyntaxError(0, s.to_owned()))?, None => return Err(RequestParserError::UnexpectedEOF), }; diff --git a/src/commands/playback_options/volume.rs b/src/commands/playback_options/volume.rs index a00a30e..f6baba9 100644 --- a/src/commands/playback_options/volume.rs +++ b/src/commands/playback_options/volume.rs @@ -1,11 +1,11 @@ use std::str::FromStr; -use crate::commands::{ +use crate::{commands::{ Command, Request, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError, -}; +}, request::VolumeValue}; -struct Volume; +pub struct Volume; impl Command for Volume { type Response = (); @@ -13,7 +13,7 @@ impl Command for Volume { fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> { let change = match parts.next() { - Some(s) => crate::request::Volume::from_str(s) + Some(s) => VolumeValue::from_str(s) .map_err(|_| RequestParserError::SyntaxError(0, s.to_owned()))?, None => return Err(RequestParserError::UnexpectedEOF), }; diff --git a/src/commands/querying_mpd_status.rs b/src/commands/querying_mpd_status.rs index f369cdb..ab60e62 100644 --- a/src/commands/querying_mpd_status.rs +++ b/src/commands/querying_mpd_status.rs @@ -3,3 +3,9 @@ pub mod currentsong; pub mod idle; pub mod stats; pub mod status; + +pub use clearerror::ClearError; +pub use currentsong::CurrentSong; +pub use idle::Idle; +pub use stats::Stats; +pub use status::Status; diff --git a/src/commands/queue.rs b/src/commands/queue.rs index 4e151ab..b7806fe 100644 --- a/src/commands/queue.rs +++ b/src/commands/queue.rs @@ -20,3 +20,26 @@ pub mod rangeid; pub mod shuffle; pub mod swap; pub mod swapid; + +pub use add::Add; +pub use addid::AddId; +pub use addtagid::AddTagId; +pub use clear::Clear; +pub use cleartagid::ClearTagId; +pub use delete::Delete; +pub use deleteid::DeleteId; +pub use move_::Move; +pub use moveid::MoveId; +pub use playlist::Playlist; +pub use playlistfind::PlaylistFind; +pub use playlistid::PlaylistId; +pub use playlistinfo::PlaylistInfo; +pub use playlistsearch::PlaylistSearch; +pub use plchanges::PlChanges; +pub use plchangesposid::PlChangesPosId; +pub use prio::Prio; +pub use prioid::PrioId; +pub use rangeid::RangeId; +pub use shuffle::Shuffle; +pub use swap::Swap; +pub use swapid::SwapId; diff --git a/src/request.rs b/src/request.rs index 8cc8adf..e69a082 100644 --- a/src/request.rs +++ b/src/request.rs @@ -26,12 +26,12 @@ pub enum Request { MixRampDelay(Seconds), Random(bool), Repeat(bool), - SetVol(Volume), + SetVol(VolumeValue), GetVol, Single(BoolOrOneshot), ReplayGainMode(ReplayGainModeMode), ReplayGainStatus, - Volume(Volume), + Volume(VolumeValue), // -- Playback Control Commands -- // Next, @@ -253,8 +253,8 @@ impl FromStr for ReplayGainModeMode { } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct Volume(u32); -impl Volume { +pub struct VolumeValue(u32); +impl VolumeValue { pub fn new(volume: u32) -> Result { match volume { 0..=100 => Ok(Self(volume)), @@ -262,16 +262,16 @@ impl Volume { } } } -impl From for u32 { - fn from(val: Volume) -> Self { +impl From for u32 { + fn from(val: VolumeValue) -> Self { val.0 } } -impl FromStr for Volume { +impl FromStr for VolumeValue { type Err = (); fn from_str(s: &str) -> Result { let volume = s.parse().map_err(|_| ())?; - Volume::new(volume) + VolumeValue::new(volume) } } @@ -353,10 +353,91 @@ impl Request { } "command_list_end" => Err(RequestParserError::UnexpectedCommandListEnd(0)), - Idle::COMMAND => Idle::parse_request(parts).map(|(req, _)| (req, rest)), - Status::COMMAND => Status::parse_request(parts).map(|(req, _)| (req, rest)), - ClearError::COMMAND => ClearError::parse_request(parts).map(|(req, _)| (req, rest)), - _ => todo!(), + /* querying mpd status */ + ClearError::COMMAND => ClearError::parse_request(parts), + CurrentSong::COMMAND => CurrentSong::parse_request(parts), + Idle::COMMAND => Idle::parse_request(parts), + Status::COMMAND => Status::parse_request(parts), + Stats::COMMAND => Stats::parse_request(parts), + + /* playback options */ + Consume::COMMAND => Consume::parse_request(parts), + Crossfade::COMMAND => Crossfade::parse_request(parts), + MixRampDb::COMMAND => MixRampDb::parse_request(parts), + MixRampDelay::COMMAND => MixRampDelay::parse_request(parts), + Random::COMMAND => Random::parse_request(parts), + Repeat::COMMAND => Repeat::parse_request(parts), + SetVol::COMMAND => SetVol::parse_request(parts), + GetVol::COMMAND => GetVol::parse_request(parts), + Single::COMMAND => Single::parse_request(parts), + ReplayGainMode::COMMAND => ReplayGainMode::parse_request(parts), + ReplayGainStatus::COMMAND => ReplayGainStatus::parse_request(parts), + Volume::COMMAND => Volume::parse_request(parts), + + /* playback control */ + Next::COMMAND => Next::parse_request(parts), + Pause::COMMAND => Pause::parse_request(parts), + Play::COMMAND => Play::parse_request(parts), + PlayId::COMMAND => PlayId::parse_request(parts), + Previous::COMMAND => Previous::parse_request(parts), + Seek::COMMAND => Seek::parse_request(parts), + SeekId::COMMAND => SeekId::parse_request(parts), + SeekCur::COMMAND => SeekCur::parse_request(parts), + Stop::COMMAND => Stop::parse_request(parts), + + /* queue */ + Add::COMMAND => Add::parse_request(parts), + AddId::COMMAND => AddId::parse_request(parts), + Clear::COMMAND => Clear::parse_request(parts), + Delete::COMMAND => Delete::parse_request(parts), + DeleteId::COMMAND => DeleteId::parse_request(parts), + Move::COMMAND => Move::parse_request(parts), + MoveId::COMMAND => MoveId::parse_request(parts), + Playlist::COMMAND => Playlist::parse_request(parts), + PlaylistFind::COMMAND => PlaylistFind::parse_request(parts), + PlaylistId::COMMAND => PlaylistId::parse_request(parts), + PlaylistInfo::COMMAND => PlaylistInfo::parse_request(parts), + PlaylistSearch::COMMAND => PlaylistSearch::parse_request(parts), + PlChanges::COMMAND => PlChanges::parse_request(parts), + PlChangesPosId::COMMAND => PlChangesPosId::parse_request(parts), + Prio::COMMAND => Prio::parse_request(parts), + PrioId::COMMAND => PrioId::parse_request(parts), + RangeId::COMMAND => RangeId::parse_request(parts), + Shuffle::COMMAND => Shuffle::parse_request(parts), + Swap::COMMAND => Swap::parse_request(parts), + SwapId::COMMAND => SwapId::parse_request(parts), + AddTagId::COMMAND => AddTagId::parse_request(parts), + ClearTagId::COMMAND => ClearTagId::parse_request(parts), + + /* stored playlists */ + + /* music database */ + + /* mounts and neighbors */ + + /* stickers */ + + /* connection settings */ + + /* partition commands */ + + /* audio output devices */ + DisableOutput::COMMAND => DisableOutput::parse_request(parts), + EnableOutput::COMMAND => EnableOutput::parse_request(parts), + ToggleOutput::COMMAND => ToggleOutput::parse_request(parts), + Outputs::COMMAND => Outputs::parse_request(parts), + OutputSet::COMMAND => OutputSet::parse_request(parts), + + /* reflection */ + + /* client to client */ + Subscribe::COMMAND => Subscribe::parse_request(parts), + Unsubscribe::COMMAND => Unsubscribe::parse_request(parts), + Channels::COMMAND => Channels::parse_request(parts), + ReadMessages::COMMAND => ReadMessages::parse_request(parts), + SendMessage::COMMAND => SendMessage::parse_request(parts), + + _ => unimplemented!(), } } }