Skip to content

Commit

Permalink
Use MonadPeelIO instead of MonadCatchIO & Support iteratee-0.5
Browse files Browse the repository at this point in the history
Ignore-this: 53be82f58c1fca4d63afdb44c0cda5f8

darcs-hash:20101106122026-ae560-0e0fcc0daecf0a21044d5a0721f1a51682c07ae6.gz
  • Loading branch information
basvandijk committed Nov 6, 2010
1 parent 3352144 commit f33a5da
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
42 changes: 22 additions & 20 deletions System/USB/Safe.hs
Expand Up @@ -208,8 +208,10 @@ import Data.ByteString ( ByteString )
-- from transformers:
import Control.Monad.IO.Class ( MonadIO, liftIO )

-- from MonadCatchIO-transformers:
import Control.Monad.CatchIO ( MonadCatchIO, bracket_, throw, block )
-- from monad-peel:
import Control.Monad.IO.Peel ( MonadPeelIO )
import Control.Exception.Peel ( bracket_, block )
import qualified Control.Exception.Peel as P ( throwIO )

-- from regions:
import Control.Monad.Trans.Region.OnExit ( FinalizerHandle, onExit )
Expand Down Expand Up @@ -310,7 +312,7 @@ Exceptions:
* Another 'USB.USBException'.
-}
openDevice MonadCatchIO pr
openDevice MonadPeelIO pr
USB.Device RegionT s pr (RegionalDeviceHandle (RegionT s pr))
openDevice dev = block $ do
h liftIO $ USB.openDevice dev
Expand All @@ -321,7 +323,7 @@ openDevice dev = block $ do
{-| Convenience function which opens the device, applies the given continuation
function to the resulting regional device handle and runs the resulting region.
-}
withDevice MonadCatchIO pr
withDevice MonadPeelIO pr
USB.Device
( s. RegionalDeviceHandle (RegionT s pr) RegionT s pr α)
pr α
Expand All @@ -344,7 +346,7 @@ Exceptions:
* Another 'USB.USBException'.
-}
withDeviceWhich pr α
. MonadCatchIO pr
. MonadPeelIO pr
USB.Ctx
(USB.DeviceDesc Bool) -- ^ Predicate on the device descriptor.
( s. RegionalDeviceHandle (RegionT s pr) RegionT s pr α)
Expand All @@ -365,7 +367,7 @@ useWhich ∷ ∀ k desc e (m ∷ * → *) α
k -- ^ Continuation function
m α
useWhich ds w p f = case find (p getDesc) ds of
Nothing throw USB.NotFoundException
Nothing P.throwIO USB.NotFoundException
Just d w d f

-- | Internally used function for getting the actual USB device handle from a
Expand Down Expand Up @@ -527,7 +529,7 @@ Exceptions:
* Another 'USB.USBException'.
-}
setConfig pr cr α
. (pr `AncestorRegion` cr, MonadCatchIO cr)
. (pr `AncestorRegion` cr, MonadPeelIO cr)
Config pr -- ^ The configuration you wish to set.
( sCfg. ConfigHandle sCfg cr α) -- ^ Continuation function.
cr α
Expand All @@ -540,7 +542,7 @@ setConfig (Config (RegionalDeviceHandle internalDevHndl mv _) configDesc) f =
-- the given @MVar@ was set. If the given @MVar@ wasn't set it will be set
-- before the given computation is performed. When the computation terminates,
-- wheter normally or by raising an exception, the @MVar@ will be unset again.
withUnsettedMVar MonadCatchIO m MVar Bool m α m α
withUnsettedMVar MonadPeelIO m MVar Bool m α m α
withUnsettedMVar mv = bracket_ (liftIO $ do alreadySet takeMVar mv
if alreadySet
then do putMVar mv alreadySet
Expand All @@ -551,7 +553,7 @@ withUnsettedMVar mv = bracket_ (liftIO $ do alreadySet ← takeMVar mv
-- | Internally used function which sets the @MVar@ before the computation is
-- performed. When the computation terminates, wheter normally or by raising an
-- exception, the @MVar@ will be unset again.
withSettedMVar MonadCatchIO m MVar Bool m α m α
withSettedMVar MonadPeelIO m MVar Bool m α m α
withSettedMVar mv = bracket_ (liftIO $ overwriteMVar mv True)
(liftIO $ overwriteMVar mv False)

Expand Down Expand Up @@ -594,7 +596,7 @@ Exceptions:
* Another 'USB.USBException'.
-}
useActiveConfig pr cr α
. (pr `AncestorRegion` cr, MonadCatchIO cr)
. (pr `AncestorRegion` cr, MonadPeelIO cr)
RegionalDeviceHandle pr -- ^ Regional handle to the device
-- from which you want to use the
-- active configuration.
Expand All @@ -603,7 +605,7 @@ useActiveConfig ∷ ∀ pr cr α
useActiveConfig (RegionalDeviceHandle internalDevHndl mv _) f =
withSettedMVar mv $ do
activeConfigValue liftIO $ USB.getConfig internalDevHndl
when (activeConfigValue 0) $ throw NoActiveConfig
when (activeConfigValue 0) $ P.throwIO NoActiveConfig
let activeConfigHandle = ConfigHandle internalDevHndl activeConfigDesc
activeConfigDesc = fromJust $ find isActive $ getConfigDescs internalDevHndl
isActive = (activeConfigValue ) USB.configValue
Expand Down Expand Up @@ -638,7 +640,7 @@ Exceptions:
* Another 'USB.USBException'.
-}
setConfigWhich pr cr α
. (pr `AncestorRegion` cr, MonadCatchIO cr)
. (pr `AncestorRegion` cr, MonadPeelIO cr)
RegionalDeviceHandle pr -- ^ Regional handle to the device for
-- which you want to set a
-- configuration.
Expand Down Expand Up @@ -724,7 +726,7 @@ Exceptions:
* Another 'USB.USBException'.
-}
claim pr sCfg s
. MonadCatchIO pr
. MonadPeelIO pr
Interface sCfg -- ^ Interface you wish to claim
RegionT s pr
(RegionalInterfaceHandle sCfg
Expand All @@ -736,7 +738,7 @@ claim interface@(Interface internalDevHndl ifNum _) = block $ do
return $ RegionalInterfaceHandle interface mv ch

withInterface pr sCfg α
. MonadCatchIO pr
. MonadPeelIO pr
Interface sCfg -- ^ The interface you wish to claim.
( s. RegionalInterfaceHandle sCfg (RegionT s pr)
RegionT s pr α
Expand All @@ -761,7 +763,7 @@ Exceptions:
-}
withInterfaceWhich pr sCfg α
. MonadCatchIO pr
. MonadPeelIO pr
ConfigHandle sCfg -- ^ Handle to a configuration of which
-- you want to claim an interface.
(USB.Interface Bool) -- ^ Predicate on the interface descriptors.
Expand Down Expand Up @@ -841,7 +843,7 @@ Exceptions:
* Another 'USB.USBException'.
-}
setAlternate pr cr sCfg α
. (pr `AncestorRegion` cr, MonadCatchIO cr)
. (pr `AncestorRegion` cr, MonadPeelIO cr)
Alternate sCfg pr -- ^ The alternate you wish to set.
( sAlt. AlternateHandle sAlt pr cr α) -- ^ Continuation function.
cr α
Expand Down Expand Up @@ -872,7 +874,7 @@ Exceptions:
* Another 'USB.USBException'.
-}
useActiveAlternate pr cr sCfg α
. (pr `AncestorRegion` cr, MonadCatchIO cr)
. (pr `AncestorRegion` cr, MonadPeelIO cr)
RegionalInterfaceHandle sCfg pr -- ^ Regional handle to the
-- interface from which you want
-- to use the active alternate.
Expand Down Expand Up @@ -911,7 +913,7 @@ Exceptions:
* Another 'USB.USBException'.
-}
setAlternateWhich pr cr sCfg α
. (pr `AncestorRegion` cr, MonadCatchIO cr)
. (pr `AncestorRegion` cr, MonadPeelIO cr)
RegionalInterfaceHandle sCfg pr -- ^ Regional handle to the
-- interface for which you want
-- to set an alternate.
Expand Down Expand Up @@ -1146,7 +1148,7 @@ instance WriteEndpoint Interrupt where writeEndpoint = transferWith USB.writeInt
class EnumReadEndpoint transType where
-- | An enumerator for an 'In' endpoint
-- with either a 'Bulk' or 'Interrupt' transfer type.
enumReadEndpoint ( pr `AncestorRegion` cr, MonadCatchIO cr, ReadableChunk s Word8
enumReadEndpoint ( pr `AncestorRegion` cr, MonadPeelIO cr, ReadableChunk s Word8
#if MIN_VERSION_iteratee(0,4,0)
, NullPoint s
#endif
Expand Down Expand Up @@ -1435,7 +1437,7 @@ Exceptions:
* Another 'USB.USBException'.
-}
withDetachedKernelDriver (pr `AncestorRegion` cr, MonadCatchIO cr)
withDetachedKernelDriver (pr `AncestorRegion` cr, MonadPeelIO cr)
RegionalDeviceHandle pr
USB.InterfaceNumber
cr α
Expand Down
6 changes: 3 additions & 3 deletions usb-safe.cabal
Expand Up @@ -72,10 +72,10 @@ Library
build-depends: base >= 4 && < 4.4
, base-unicode-symbols >= 0.1.1 && < 0.3
, usb >= 0.5 && < 0.7
, usb-enumerator >= 0.1 && < 0.2
, iteratee >= 0.3.5 && < 0.5
, usb-enumerator >= 0.2 && < 0.3
, iteratee >= 0.3.5 && < 0.6
, bytestring >= 0.9 && < 0.10
, regions >= 0.8 && < 0.9
, transformers >= 0.2 && < 0.3
, MonadCatchIO-transformers >= 0.2 && < 0.3
, monad-peel >= 0.1 && < 0.2
exposed-modules: System.USB.Safe

0 comments on commit f33a5da

Please sign in to comment.