packages feed

alsa-core (empty) → 0.5

raw patch · 4 files changed

+159/−0 lines, 4 filesdep +basedep +extensible-exceptionssetup-changed

Dependencies added: base, extensible-exceptions

Files

+ LICENSE view
@@ -0,0 +1,9 @@+Copyright (c) 2009-2010 Henning Thielemann+Copyright (c) 2006 Bjorn Bringert+Copyright (c) 2006 Iavor S. Diatchki++Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.lhs view
@@ -0,0 +1,8 @@+#!/usr/bin/env runghc++> module Main where++> import Distribution.Simple++> main :: IO ()+> main = defaultMain
+ alsa-core.cabal view
@@ -0,0 +1,40 @@+Name: alsa-core+Version: 0.5+Copyright: Bjorn Bringert, Iavor S. Diatchki, Henning Thielemann+Maintainer: Henning Thielemann <alsa@henning-thielemann.de>+Author: Bjorn Bringert <bjorn@bringert.net>, Iavor S. Diatchki <iavor.diatchki@gmail.com>+Category: Sound, Music+License: BSD3+License-file: LICENSE+Homepage: http://www.haskell.org/haskellwiki/ALSA+Stability: Experimental+Build-Type: Simple+Cabal-Version: >= 1.8++Synopsis: Binding to the ALSA Library API (Exceptions).+Description:+  This package provides access to ALSA infrastructure,+  that is needed by both alsa-seq and alsa-pcm.++Source-Repository head+  type:     darcs+  location: http://code.haskell.org/~thielema/alsa-core/++Source-Repository this+  type:     darcs+  location: http://code.haskell.org/~thielema/alsa-core/+  tag:      0.5++Library+  Build-depends:+    extensible-exceptions >=0.1.1 && <0.2,+    base >= 3 && <5++  Hs-Source-Dirs: src++  Exposed-Modules:+    Sound.ALSA.Exception++  GHC-Options: -Wall+  Includes: alsa/asoundlib.h+  Extra-libraries: asound
+ src/Sound/ALSA/Exception.hs view
@@ -0,0 +1,102 @@+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE DeriveDataTypeable #-}+{- |+ALSA does not distinguish between programming errors and runtime exceptions,+which is sad, but we have to cope with it.+-}+module Sound.ALSA.Exception where++import qualified Control.Exception.Extensible as Exc+import Control.Exception.Extensible (Exception, )++import Data.Typeable (Typeable, )+import Foreign.C.Error (Errno(Errno), ePIPE, errnoToIOError, )+import Foreign.C.String (CString, peekCString, )+import Foreign.C.Types (CInt, )++import Prelude hiding (catch, show, )+import qualified Prelude as P++data T = Cons {+   location    :: String,+   description :: String,+   code        :: Errno+   } deriving (Typeable)++instance Show T where+   showsPrec p (Cons l d (Errno c)) =+      showParen (p>10)+         (showString "AlsaException.Cons " .+          shows l . showString " " .+          shows d . showString " " .+          showParen True (showString "Errno " . shows c))++instance Exception T where++checkResult :: Integral a => String -> a -> IO a+checkResult f r =+   if r < 0+     then throw f (Errno (negate (fromIntegral r)))+     else return r++checkResult_ :: Integral a => String -> a -> IO ()+checkResult_ f r = checkResult f r >> return ()++checkResultMaybe :: String -> (CInt -> a) -> (CInt -> Maybe a) -> CInt -> IO a+checkResultMaybe f ok err x =+   if x >= 0+     then return (ok x)+     else case err x of+             Just a -> return a+             _ -> throw f (Errno x)+++throw :: String -> Errno -> IO a+throw fun err = do+   d <- strerror err+   Exc.throw Cons+     { location = fun+     , description = d+     , code = err+     }++catch :: IO a -> (T -> IO a) -> IO a+catch = Exc.catch++catchErrno ::+      Errno+   -> IO a -- ^ Action+   -> IO a -- ^ Handler+   -> IO a+catchErrno e x h =+   catch x (\ex -> if code ex == e then h else Exc.throw ex)++catchXRun ::+      IO a -- ^ Action+   -> IO a -- ^ Handler+   -> IO a+catchXRun = catchErrno ePIPE++showErrno :: Errno -> String+showErrno (Errno n) = P.show n++show :: T -> String+show e =+   location e ++ ": " +++   description e ++ " (" ++ showErrno (code e) ++ ")"++-- | Converts any 'AlsaException.T' into an 'IOError'.+-- This produces better a error message than letting an uncaught+-- 'AlsaException.T' propagate to the top.+rethrow :: IO a -> IO a+rethrow x =+    catch x $ \e ->+       ioError (errnoToIOError (location e)+                               (code e) Nothing Nothing)++-- | Returns the message for an error code.+strerror :: Errno -> IO String+strerror x = peekCString =<< snd_strerror x++foreign import ccall "alsa/asoundlib.h snd_strerror"+  snd_strerror :: Errno -> IO CString