empidee/src/server.rs

247 lines
8.3 KiB
Rust
Raw Normal View History

2024-11-30 01:57:45 +01:00
use crate::{common::SubSystem, Request, Response};
pub trait MPDServer {
type Error;
fn route_request(&mut self, request: Request) -> Result<Response, Self::Error> {
match request {
Request::ClearError => self.handle_clear_error().map(|_| Response::Ok),
Request::CurrentSong => self.handle_current_song().map(|_| Response::Ok),
Request::Idle(subsystems) => self.handle_idle(subsystems).map(|_| Response::Ok),
Request::Status => self.handle_status().map(|_| Response::Ok),
Request::Stats => self.handle_stats().map(|_| Response::Ok),
_ => unimplemented!(),
}
}
fn handle_unimplemented(&mut self) -> Result<(), Self::Error> {
// fn handle_unimplemented(&mut self, name: &str) -> Result<(), Self::Error> {
// return Err("a".into());
unimplemented!()
}
// -- Query Commands -- //
fn handle_clear_error(&mut self) -> Result<(), Self::Error> {
self.handle_unimplemented()
}
fn handle_current_song(&mut self) -> Result<(), Self::Error> {
self.handle_unimplemented()
}
fn handle_idle(&mut self, _: Option<Vec<SubSystem>>) -> Result<(), Self::Error> {
self.handle_unimplemented()
}
fn handle_status(&mut self) -> Result<(), Self::Error> {
self.handle_unimplemented()
}
fn handle_stats(&mut self) -> Result<(), Self::Error> {
self.handle_unimplemented()
}
// -- Playback Commands -- //
// handle_consume(ConsumeState),
// handle_crossfade(Seconds),
// handle_mix_ramp_db(f32),
// handle_mix_ramp_delay(Seconds),
// handle_random(bool),
// handle_repeat(bool),
// handle_set_vol(Volume),
// handle_get_vol,
// handle_single(SingleState),
// handle_replay_gain_mode(ReplayGainMode),
// handle_replay_gain_status,
// handle_volume(Volume),
// // -- Playback Control Commands -- //
// next,
// pause(Option<bool>),
// play(SongPosition),
// play_id(SongId),
// previous,
// seek(SongPosition, TimeWithFractions),
// seek_id(SongId, TimeWithFractions),
// seek_cur(SeekMode, TimeWithFractions),
// stop,
// // -- Queue Commands -- //
// handle_add(String, Option<SongPosition>),
// handle_add_id(String, Option<SongPosition>),
// handle_clear,
// handle_delete(OneOrRange),
// handle_delete_id(SongId),
// handle_move(OneOrRange, SongPosition),
// handle_move_id(SongId, SongPosition),
// handle_playlist,
// handle_playlist_find(Filter, Option<Sort>, Option<WindowRange>),
// handle_playlist_id(SongId),
// handle_playlist_info(OneOrRange),
// handle_playlist_search(Filter, Option<Sort>, Option<WindowRange>),
// handle_pl_changes(Version, Option<WindowRange>),
// handle_pl_changes_pos_id(Version, Option<WindowRange>),
// handle_prio(Priority, WindowRange),
// handle_prio_id(Priority, Vec<SongId>),
// handle_range_id(SongId, WindowRange),
// handle_shuffle(Option<OneOrRange>),
// handle_swap(SongPosition, SongPosition),
// handle_swap_id(SongId, SongId),
// handle_add_tag_id(SongId, TagName, TagValue),
// handle_clear_tag_id(SongId, TagName),
// // -- Stored Playlist Commands -- //
// ListPlaylist(PlaylistName, Option<WindowRange>),
// ListPlaylistInfo(PlaylistName, Option<WindowRange>),
// SearchPlaylist(PlaylistName, Filter, Option<WindowRange>),
// ListPlaylists,
// Load(PlaylistName, Option<WindowRange>, SongPosition),
// PlaylistAdd(PlaylistName, Uri, SongPosition),
// PlaylistClear(PlaylistName),
// PlaylistDelete(PlaylistName, OneOrRange),
// PlaylistLength(PlaylistName),
// // TODO: which type of range?
// PlaylistMove(PlaylistName, OneOrRange, SongPosition),
// Rename(PlaylistName, PlaylistName),
// Rm(PlaylistName),
// Save(PlaylistName, Option<SaveMode>),
// // -- Music Database Commands -- //
// AlbumArt(Uri, Offset),
// Count(Filter, Option<GroupType>),
// GetFingerprint(Uri),
// Find(Filter, Option<Sort>, Option<WindowRange>),
// FindAdd(Filter, Option<Sort>, Option<WindowRange>, Option<SongPosition>),
// List(Tag, Filter, Option<GroupType>),
// #[deprecated]
// ListAll(Option<Uri>),
// #[deprecated]
// ListAllInfo(Option<Uri>),
// ListFiles(Uri),
// LsInfo(Option<Uri>),
// ReadComments(Uri),
// ReadPicture(Uri, Offset),
// Search(Filter, Option<Sort>, Option<WindowRange>),
// SearchAdd(Filter, Option<Sort>, Option<WindowRange>, Option<SongPosition>),
// SearchAddPl(Filter, Option<Sort>, Option<WindowRange>, Option<SongPosition>),
// SearchCount(Filter, Option<GroupType>),
// Update(Option<Uri>),
// Rescan(Option<Uri>),
// // -- Mount and Neighbor Commands -- //
// Mount(Option<Path>, Option<Uri>),
// Unmount(Path),
// ListMounts,
// ListNeighbors,
// // -- Sticker Commands -- //
// StickerGet(StickerType, Uri, String),
// StickerSet(StickerType, Uri, String, String),
// StickerDelete(StickerType, Uri, String),
// StickerList(StickerType, Uri),
// StickerFind(StickerType, Uri, String, Option<Sort>, Option<WindowRange>),
// StickerFindValue(StickerType, Uri, String, String, Option<Sort>, Option<WindowRange>),
// StickerNames,
// StickerTypes,
// StickerNamesTypes(Option<StickerType>),
// // -- Connection Commands -- //
// Close,
// Kill,
// Password(String),
// Ping,
// BinaryLimit(u64),
// TagTypes,
// TagTypesDisable(Vec<Tag>),
// TagTypesEnable(Vec<Tag>),
// TagTypesClear,
// TagTypesAll,
// TagTypesAvailable,
// TagTypesReset(Vec<Tag>),
// Protocol,
// ProtocolDisable(Vec<Feature>),
// ProtocolEnable(Vec<Feature>),
// ProtocolClear,
// ProtocolAll,
// ProtocolAvailable,
// // -- Partition Commands -- //
// Partition(PartitionName),
// ListPartitions,
// NewPartition(PartitionName),
// DelPartition(PartitionName),
// MoveOutput(String),
// // -- Audio Output Commands -- //
// DisableOutput(AudioOutputId),
// EnableOutput(AudioOutputId),
// ToggleOutput(AudioOutputId),
// Outputs,
// OutputSet(AudioOutputId, String, String),
// // -- Reflection Commands -- //
// Config,
// Commands,
// NotCommands,
// UrlHandlers,
// Decoders,
// // -- Client to Client Commands -- //
// Subscribe(ChannelName),
// Unsubscribe(ChannelName),
// Channels,
// ReadMessages,
// SendMessage(ChannelName, String),
}
// impl Into<Vec<u8>> for Request {
// fn into(self) -> Vec<u8> {
// todo!()
// }
// }
// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
// pub enum SaveMode {
// Create,
// Append,
// Replace,
// }
// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
// pub enum SeekMode {
// Relative,
// RelativeReverse,
// Absolute,
// }
// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
// pub enum SubSystem {
// /// The song database has been modified after update.
// Database,
// /// A database update has started or finished. If the database was modified during the update, the database event is also emitted.
// Update,
// /// A stored playlist has been modified, renamed, created or deleted
// StoredPlaylist,
// /// The queue (i.e. the current playlist) has been modified
// Playlist,
// /// The player has been started, stopped or seeked or tags of the currently playing song have changed (e.g. received from stream)
// Player,
// /// The volume has been changed
// Mixer,
// /// An audio output has been added, removed or modified (e.g. renamed, enabled or disabled)
// Output,
// /// Options like repeat, random, crossfade, replay gain
// Options,
// /// A partition was added, removed or changed
// Partition,
// /// The sticker database has been modified.
// Sticker,
// /// A client has subscribed or unsubscribed to a channel
// Subscription,
// /// A message was received on a channel this client is subscribed to; this event is only emitted when the clients message queue is empty
// Message,
// /// A neighbor was found or lost
// Neighbor,
// /// The mount list has changed
// Mount,
// /// Other subsystems not covered by the above
// Other(String),
// }