libmpd-0.10.0.1: An MPD client library.

Copyright | (c) Ben Sinclair 2005-2009 Joachim Fasting 2010
License | MIT (see LICENSE)
Maintainer | Joachim Fasting <joachifm@fastmail.fm>
Stability | alpha
Safe Haskell | None
Language | Haskell2010

Network.MPD.Core

Contents

- Classes
- Data types
- Running
- Interacting

Description

The core datatypes and operations are defined here, including the primary instance of the `MonadMPD` class, `MPD`.

Synopsis

- class (Monad m, MonadError MPDError m) => MonadMPD (m :: Type -> Type) where
  - open :: m ()
  - close :: m ()
  - send :: String -> m [ByteString]
  - getPassword :: m Password
  - setPassword :: Password -> m ()
  - getVersion :: m (Int, Int, Int)
- data MPD a
- data MPDError
  - = NoMPD
  - | ConnectionError IOException
  - | Unexpected String
  - | Custom String
  - | ACK ACKType String
- data ACKType
  - = InvalidArgument
  - | InvalidPassword
  - | Auth
  - | UnknownCommand
  - | FileNotFound
  - | PlaylistMax
  - | System
  - | PlaylistLoad
  - | Busy
  - | NotPlaying
  - | FileExists
  - | UnknownACK
- type Response = Either MPDError
- type Host = String
- type Port = Integer
- type Password = String
- withMPDEx :: Host -> Port -> Password -> MPD a -> IO (Response a)
- getResponse :: MonadMPD m => String -> m [ByteString]
- kill :: MonadMPD m => m ()

# Classes

class (Monad m, MonadError MPDError m) => MonadMPD (m :: Type -> Type) where Source #

A typeclass to allow for multiple implementations of a connection to an MPD server.

Methods

open :: m () Source #

Open (or re-open) a connection to the MPD server.

close :: m () Source #

Close the connection.

send :: String -> m [ByteString] Source #

Send a string to the server and return its response.

getPassword :: m Password Source #

Produce a password to send to the server should it ask for one.

setPassword :: Password -> m () Source #

Alters password to be sent to the server.

getVersion :: m (Int, Int, Int) Source #

Get MPD protocol version

#### Instances

Instances details

MonadMPD MPD Source # |
Instance details Defined in Network.MPD.Core Methods open :: MPD () Source # close :: MPD () Source # send :: String -> MPD [ByteString] Source # getPassword :: MPD Password Source # setPassword :: Password -> MPD () Source # getVersion :: MPD (Int, Int, Int) Source #

# Data types

data MPD a Source #

The main implementation of an MPD client. It actually connects to a server and interacts with it.

To use the error throwing/catching capabilities:

    import Control.Monad.Except (throwError, catchError)

To run IO actions within the MPD monad:

    import Control.Monad.Trans (liftIO)

#### Instances

Instances details

MonadIO MPD Source # |
Instance details Defined in Network.MPD.Core Methods liftIO :: IO a -> MPD a Source #
Applicative MPD Source # |
Instance details Defined in Network.MPD.Core Methods pure :: a -> MPD a Source # (<*>) :: MPD (a -> b) -> MPD a -> MPD b Source # liftA2 :: (a -> b -> c) -> MPD a -> MPD b -> MPD c Source # (*>) :: MPD a -> MPD b -> MPD b Source # (<*) :: MPD a -> MPD b -> MPD a Source #
Functor MPD Source # |
Instance details Defined in Network.MPD.Core Methods fmap :: (a -> b) -> MPD a -> MPD b Source # (<$) :: a -> MPD b -> MPD a Source #
Monad MPD Source # |
Instance details Defined in Network.MPD.Core Methods (>>=) :: MPD a -> (a -> MPD b) -> MPD b Source # (>>) :: MPD a -> MPD b -> MPD b Source # return :: a -> MPD a Source #
MonadMPD MPD Source # |
Instance details Defined in Network.MPD.Core Methods open :: MPD () Source # close :: MPD () Source # send :: String -> MPD [ByteString] Source # getPassword :: MPD Password Source # setPassword :: Password -> MPD () Source # getVersion :: MPD (Int, Int, Int) Source #
MonadError MPDError MPD Source # |
Instance details Defined in Network.MPD.Core Methods throwError :: MPDError -> MPD a Source # catchError :: MPD a -> (MPDError -> MPD a) -> MPD a Source #

data MPDError Source #

The MPDError type is used to signal errors, both from the MPD and otherwise.

Constructors

NoMPD | MPD not responding
ConnectionError IOException | An error occurred while talking to MPD.
Unexpected String | MPD returned an unexpected response. This is a bug, either in the library or in MPD itself.
Custom String | Used for misc. errors
ACK ACKType String | ACK type and a message from the server

#### Instances

Instances details

Exception MPDError Source # |
Instance details Defined in Network.MPD.Core.Error Methods toException :: MPDError -> SomeException Source # fromException :: SomeException -> Maybe MPDError Source # displayException :: MPDError -> String Source # backtraceDesired :: MPDError -> Bool Source #
Show MPDError Source # |
Instance details Defined in Network.MPD.Core.Error Methods showsPrec :: Int -> MPDError -> ShowS Source # show :: MPDError -> String Source # showList :: [MPDError] -> ShowS Source #
Eq MPDError Source # |
Instance details Defined in Network.MPD.Core.Error Methods (==) :: MPDError -> MPDError -> Bool Source # (/=) :: MPDError -> MPDError -> Bool Source #
MonadError MPDError MPD Source # |
Instance details Defined in Network.MPD.Core Methods throwError :: MPDError -> MPD a Source # catchError :: MPD a -> (MPDError -> MPD a) -> MPD a Source #

data ACKType Source #

Represents various MPD errors (aka. ACKs).

Constructors

InvalidArgument | Invalid argument passed (ACK 2)
InvalidPassword | Invalid password supplied (ACK 3)
Auth | Authentication required (ACK 4)
UnknownCommand | Unknown command (ACK 5)
FileNotFound | File or directory not found ACK 50)
PlaylistMax | Playlist at maximum size (ACK 51)
System | A system error (ACK 52)
PlaylistLoad | Playlist loading failed (ACK 53)
Busy | Update already running (ACK 54)
NotPlaying | An operation requiring playback got interrupted (ACK 55)
FileExists | File already exists (ACK 56)
UnknownACK | An unknown ACK (aka. bug)

#### Instances

Instances details

Eq ACKType Source # |
Instance details Defined in Network.MPD.Core.Error Methods (==) :: ACKType -> ACKType -> Bool Source # (/=) :: ACKType -> ACKType -> Bool Source #

type Response = Either MPDError Source #

A response is either an `MPDError` or some result.

type Host = String Source #

type Port = Integer Source #

type Password = String Source #

# Running

withMPDEx :: Host -> Port -> Password -> MPD a -> IO (Response a) Source #

The most configurable API for running an MPD action.

# Interacting

getResponse :: MonadMPD m => String -> m [ByteString] Source #

Send a command to the MPD server and return the result.

kill :: MonadMPD m => m () Source #

Kill the server. Obviously, the connection is then invalid.