module Sound.Pulse.Serverinfo
( ServerInfo(..)
, getServerInfo
, getServerInfoM
)
where
import Control.Applicative ((<$>), (<*>))
import Data.Word (Word32, Word)
import Sound.Pulse
import Sound.Pulse.SampleSpec
import Sound.Pulse.ChannelPosition
import Sound.Pulse.Context
import Sound.Pulse.Userdata
import Sound.Pulse.Operation
import Foreign.Storable
import Foreign.Ptr
import Foreign.C.String
data ServerInfo = ServerInfo
{ userName :: String
, hostName :: String
, serverVersion :: String
, serverName :: String
, sampleSpec :: SampleSpec
, defaultSinkName :: String
, defaultSourceName :: String
, cookie :: Word32
, channelMap :: ChannelMap
} deriving (Eq, Show)
instance Storable ServerInfo where
sizeOf _ = (200)
alignment _ = (8)
peek p = ServerInfo
<$> (peekCString =<< (\hsc_ptr -> peekByteOff hsc_ptr 0) p)
<*> (peekCString =<< (\hsc_ptr -> peekByteOff hsc_ptr 8) p)
<*> (peekCString =<< (\hsc_ptr -> peekByteOff hsc_ptr 16) p)
<*> (peekCString =<< (\hsc_ptr -> peekByteOff hsc_ptr 24) p)
<*> (\hsc_ptr -> peekByteOff hsc_ptr 32) p
<*> (peekCString =<< (\hsc_ptr -> peekByteOff hsc_ptr 48) p)
<*> (peekCString =<< (\hsc_ptr -> peekByteOff hsc_ptr 56) p)
<*> (\hsc_ptr -> peekByteOff hsc_ptr 64) p
<*> (\hsc_ptr -> peekByteOff hsc_ptr 68) p
poke _ _ = error "PA: no poke for ServerInfo yet"
type ServerInfoCB = Context -> Ptr ServerInfo -> Ptr Userdata -> IO ()
foreign import ccall "wrapper" mkServerInfoCB :: ServerInfoCB -> IO (FunPtr ServerInfoCB)
foreign import ccall "pa_context_get_server_info" pa_context_get_server_info :: Context -> FunPtr ServerInfoCB -> Ptr Userdata -> IO (Ptr UOperation)
getServerInfo
:: Context
-> (ServerInfo -> IO ())
-> IO ()
getServerInfo cxt fun = do
funP <- mkServerInfoCB $ \_ ptr fP -> do
fun =<< peek ptr
freeHaskellFunPtr (castPtrToFunPtr fP)
_ <- ptrToOperation =<< pa_context_get_server_info cxt funP (castFunPtrToPtr funP)
return ()
getServerInfoM :: Pulse ServerInfo
getServerInfoM = Pulse getServerInfo