module System.Gnome.VFS.Ops (
Handle,
Result(..),
OpenMode(..),
SeekPosition(..),
FilePermissions(..),
FileSize,
FileOffset,
open,
openURI,
create,
createURI,
close,
seek,
tell,
forgetCache,
truncate,
truncateURI,
truncateHandle,
getFileInfo,
getFileInfoURI,
getFileInfoFromHandle,
setFileInfo,
setFileInfoURI
) where
import Control.Exception
import Control.Monad (liftM)
import Prelude hiding (read, truncate)
import System.Glib.FFI
import System.Glib.UTFString (withUTFString, peekUTFString)
import System.Gnome.VFS.BasicTypes
import System.Gnome.VFS.FileInfo
import System.Gnome.VFS.Marshal
open :: TextURI
-> OpenMode
-> IO Handle
open textURI openMode =
let cOpenMode = cFromEnum openMode
in withUTFString textURI $ \cTextURI ->
newObjectResultMarshal Handle $ \cHandlePtr ->
gnome_vfs_open (castPtr cHandlePtr) cTextURI cOpenMode
openURI :: URI
-> OpenMode
-> IO Handle
openURI uri openMode =
let cOpenMode = cFromEnum openMode
in newObjectResultMarshal Handle $ \cHandlePtr ->
(\arg1 (URI arg2) arg3 -> withForeignPtr arg2 $ \argPtr2 ->gnome_vfs_open_uri arg1 argPtr2 arg3) (castPtr cHandlePtr) uri cOpenMode
create :: TextURI
-> OpenMode
-> Bool
-> [FilePermissions]
-> IO Handle
create textURI openMode exclusive perm =
let cOpenMode = cFromEnum openMode
cExclusive = fromBool exclusive
cPerm = cFromFlags perm
in withUTFString textURI $ \cTextURI ->
newObjectResultMarshal Handle $ \cHandlePtr ->
gnome_vfs_create (castPtr cHandlePtr) cTextURI cOpenMode cExclusive cPerm
createURI :: URI
-> OpenMode
-> Bool
-> [FilePermissions]
-> IO Handle
createURI uri openMode exclusive perm =
let cOpenMode = cFromEnum openMode
cExclusive = fromBool exclusive
cPerm = cFromFlags perm
in newObjectResultMarshal Handle $ \cHandlePtr ->
(\arg1 (URI arg2) arg3 arg4 arg5 -> withForeignPtr arg2 $ \argPtr2 ->gnome_vfs_create_uri arg1 argPtr2 arg3 arg4 arg5) (castPtr cHandlePtr) uri cOpenMode cExclusive cPerm
close :: Handle
-> IO ()
close handle =
voidResultMarshal $ (\(Handle arg1) -> withForeignPtr arg1 $ \argPtr1 ->gnome_vfs_close argPtr1) handle
seek :: Handle
-> SeekPosition
-> FileOffset
-> IO ()
seek handle whence offset =
let cWhence = cFromEnum whence
cOffset = fromIntegral offset
in voidResultMarshal $ (\(Handle arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gnome_vfs_seek argPtr1 arg2 arg3) handle cWhence cOffset
tell :: Handle
-> IO FileSize
tell handle =
alloca $ \cOffsetReturnPtr ->
genericResultMarshal
(do poke cOffsetReturnPtr 0
(\(Handle arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gnome_vfs_tell argPtr1 arg2) handle cOffsetReturnPtr)
(liftM fromIntegral $ peek cOffsetReturnPtr)
(do cOffsetReturn <- peek cOffsetReturnPtr
assert (cOffsetReturn == 0) $ return ())
forgetCache :: Handle
-> FileOffset
-> FileSize
-> IO ()
forgetCache handle offset size =
let cOffset = fromIntegral offset
cSize = fromIntegral size
in voidResultMarshal $ (\(Handle arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gnome_vfs_forget_cache argPtr1 arg2 arg3) handle cOffset cSize
truncate :: String
-> FileSize
-> IO ()
truncate textURI length =
let cLength = fromIntegral length
in withUTFString textURI $ \cTextURI ->
voidResultMarshal $ gnome_vfs_truncate cTextURI cLength
truncateURI :: URI
-> FileSize
-> IO ()
truncateURI uri length =
let cLength = fromIntegral length
in voidResultMarshal $ (\(URI arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gnome_vfs_truncate_uri argPtr1 arg2) uri cLength
truncateHandle :: Handle
-> FileSize
-> IO ()
truncateHandle handle length =
let cLength = fromIntegral length
in voidResultMarshal $ (\(Handle arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gnome_vfs_truncate_handle argPtr1 arg2) handle cLength
getFileInfo :: String
-> [FileInfoOptions]
-> IO FileInfo
getFileInfo textURI options =
let cOptions = cFromFlags options
in withUTFString textURI $ \cTextURI ->
bracket gnome_vfs_file_info_new
gnome_vfs_file_info_unref
(\cFileInfo ->
genericResultMarshal
(gnome_vfs_get_file_info cTextURI cFileInfo cOptions)
(peek $ castPtr cFileInfo)
(return ()))
getFileInfoURI :: URI
-> [FileInfoOptions]
-> IO FileInfo
getFileInfoURI uri options =
let cOptions = cFromFlags options
in bracket gnome_vfs_file_info_new
gnome_vfs_file_info_unref
(\cFileInfo ->
genericResultMarshal
((\(URI arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gnome_vfs_get_file_info_uri argPtr1 arg2 arg3) uri cFileInfo cOptions)
(peek $ castPtr cFileInfo)
(return ()))
getFileInfoFromHandle :: Handle
-> [FileInfoOptions]
-> IO FileInfo
getFileInfoFromHandle handle options =
let cOptions = cFromFlags options
in bracket gnome_vfs_file_info_new
gnome_vfs_file_info_unref
(\cFileInfo ->
genericResultMarshal
((\(Handle arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gnome_vfs_get_file_info_from_handle argPtr1 arg2 arg3) handle cFileInfo cOptions)
(peek $ castPtr cFileInfo)
(return ()))
setFileInfo :: String
-> FileInfo
-> [SetFileInfoMask]
-> IO ()
setFileInfo textURI info mask =
withUTFString textURI $ \cTextURI ->
with info $ \cInfo ->
voidResultMarshal $ gnome_vfs_set_file_info cTextURI (castPtr cInfo) $ cFromFlags mask
setFileInfoURI :: URI
-> FileInfo
-> [SetFileInfoMask]
-> IO ()
setFileInfoURI uri info mask =
with info $ \cInfo ->
voidResultMarshal $ (\(URI arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gnome_vfs_set_file_info_uri argPtr1 arg2 arg3) uri (castPtr cInfo) $ cFromFlags mask
foreign import ccall safe "gnome_vfs_open"
gnome_vfs_open :: ((Ptr Handle) -> ((Ptr CChar) -> (CInt -> (IO CInt))))
foreign import ccall safe "gnome_vfs_open_uri"
gnome_vfs_open_uri :: ((Ptr Handle) -> ((Ptr URI) -> (CInt -> (IO CInt))))
foreign import ccall safe "gnome_vfs_create"
gnome_vfs_create :: ((Ptr Handle) -> ((Ptr CChar) -> (CInt -> (CInt -> (CUInt -> (IO CInt))))))
foreign import ccall safe "gnome_vfs_create_uri"
gnome_vfs_create_uri :: ((Ptr Handle) -> ((Ptr URI) -> (CInt -> (CInt -> (CUInt -> (IO CInt))))))
foreign import ccall safe "gnome_vfs_close"
gnome_vfs_close :: ((Ptr Handle) -> (IO CInt))
foreign import ccall safe "gnome_vfs_seek"
gnome_vfs_seek :: ((Ptr Handle) -> (CInt -> (CLLong -> (IO CInt))))
foreign import ccall safe "gnome_vfs_tell"
gnome_vfs_tell :: ((Ptr Handle) -> ((Ptr CULLong) -> (IO CInt)))
foreign import ccall safe "gnome_vfs_forget_cache"
gnome_vfs_forget_cache :: ((Ptr Handle) -> (CLLong -> (CULLong -> (IO CInt))))
foreign import ccall safe "gnome_vfs_truncate"
gnome_vfs_truncate :: ((Ptr CChar) -> (CULLong -> (IO CInt)))
foreign import ccall safe "gnome_vfs_truncate_uri"
gnome_vfs_truncate_uri :: ((Ptr URI) -> (CULLong -> (IO CInt)))
foreign import ccall safe "gnome_vfs_truncate_handle"
gnome_vfs_truncate_handle :: ((Ptr Handle) -> (CULLong -> (IO CInt)))
foreign import ccall safe "gnome_vfs_file_info_new"
gnome_vfs_file_info_new :: (IO (Ptr ()))
foreign import ccall safe "gnome_vfs_file_info_unref"
gnome_vfs_file_info_unref :: ((Ptr ()) -> (IO ()))
foreign import ccall safe "gnome_vfs_get_file_info"
gnome_vfs_get_file_info :: ((Ptr CChar) -> ((Ptr ()) -> (CInt -> (IO CInt))))
foreign import ccall safe "gnome_vfs_get_file_info_uri"
gnome_vfs_get_file_info_uri :: ((Ptr URI) -> ((Ptr ()) -> (CInt -> (IO CInt))))
foreign import ccall safe "gnome_vfs_get_file_info_from_handle"
gnome_vfs_get_file_info_from_handle :: ((Ptr Handle) -> ((Ptr ()) -> (CInt -> (IO CInt))))
foreign import ccall safe "gnome_vfs_set_file_info"
gnome_vfs_set_file_info :: ((Ptr CChar) -> ((Ptr ()) -> (CInt -> (IO CInt))))
foreign import ccall safe "gnome_vfs_set_file_info_uri"
gnome_vfs_set_file_info_uri :: ((Ptr URI) -> ((Ptr ()) -> (CInt -> (IO CInt))))