Add existing command parsers to the main request parser
This commit is contained in:
parent
08104b3537
commit
3e512092bd
@ -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;
|
||||
|
@ -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;
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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<'_> {
|
||||
|
@ -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),
|
||||
};
|
||||
|
||||
|
@ -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),
|
||||
};
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
105
src/request.rs
105
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<Self, ()> {
|
||||
match volume {
|
||||
0..=100 => Ok(Self(volume)),
|
||||
@ -262,16 +262,16 @@ impl Volume {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<Volume> for u32 {
|
||||
fn from(val: Volume) -> Self {
|
||||
impl From<VolumeValue> 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<Self, Self::Err> {
|
||||
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!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user