module Network.XMMS.Client (
Connection,
Result,
XMMSCV(..),
SeekMode(..),
init,
connect,
getLastError,
quit,
broadcastQuit,
userConfigDirGet,
resultWait,
propdictToDict,
resultGetValue,
resultNotifierSet,
resultGetConnection
)where
import Network.XMMS.Constants
import Network.XMMS.Types
import Network.XMMS.Utilities
import Foreign
import Foreign.Ptr
import Foreign.C.Types
import Network.XMMS.UTF8Strings
import Foreign.ForeignPtr
import Foreign.Marshal.Alloc
import Prelude hiding (init)
import Network.XMMS.Result
import Network.XMMS.Value
foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_init"
xmmsc_init :: CString -> IO (Ptr C_xmmsc_connection)
init :: String -> IO Connection
init name = do
c_name <- newCString name
ptr <- xmmsc_init c_name
free c_name
newForeignPtr xmmsc_unref ptr
foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_connect"
xmmsc_connect :: Ptr C_xmmsc_connection -> CString -> IO CInt
connect :: Connection -> String -> IO Int
connect connection ipcpath =
withForeignPtr connection ( \ptrCon -> do
res <- if ipcpath == ""
then xmmsc_connect ptrCon nullPtr
else do c_ipcpath <- newCString ipcpath
xmmsc_connect ptrCon c_ipcpath
return $ fromIntegral res)
foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_get_last_error"
xmmsc_get_last_error :: Ptr C_xmmsc_connection -> IO CString
getLastError :: Connection -> IO String
getLastError connection =
withForeignPtr connection ( \ptrCon -> do
c_errorMsg <- xmmsc_get_last_error ptrCon
safePeekUTF8String c_errorMsg)
foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_quit"
xmmsc_quit :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)
quit :: Connection -> IO Result
quit = wrapCallResult xmmsc_quit
foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_broadcast_quit"
xmmsc_broadcast_quit :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)
broadcastQuit :: Connection -> IO Result
broadcastQuit = wrapCallResult xmmsc_broadcast_quit
foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_userconfdir_get"
xmmsc_userconfdir_get :: Ptr CChar -> CInt -> IO (Ptr CChar)
userConfigDirGet :: Int -> IO String
userConfigDirGet len = do
let c = (castCharToCChar 'c') :: CChar
bufPtr <- mallocBytes (len * sizeOf c)
xmmsc_userconfdir_get bufPtr (fromIntegral len)
res <- safePeekUTF8String bufPtr
free bufPtr
return res