{-# LINE 1 "src/Poll.hsc" #-}
{-# LANGUAGE NoImplicitPrelude #-}



module Poll ( toEvent ) where

-- from base:
import Data.Bits       ( (.&.) )
import Data.Bool       ( otherwise )
import Data.Eq         ( (/=) )
import Data.Monoid     ( mempty, mappend )
import Foreign.C.Types ( CShort )

-- from usb:
-- I need to import GHC.Event or System.Event based on the version of base.
-- However it's currently not possible to use cabal macros in .hsc files.
-- See: http://hackage.haskell.org/trac/hackage/ticket/870
-- So I use an intermediate module that makes the choice:
import Event ( Event, evtRead, evtWrite )

toEvent :: CShort -> Event
toEvent e = remap (1)  evtRead `mappend`
{-# LINE 23 "src/Poll.hsc" #-}
            remap (4) evtWrite
{-# LINE 24 "src/Poll.hsc" #-}
  where
    remap evt to
        | e .&. evt /= 0 = to
        | otherwise      = mempty