{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

The #GMappedFile represents a file mapping created with
g_mapped_file_new(). It has only private members and should
not be accessed directly.
-}

module GI.GLib.Structs.MappedFile
    ( 

-- * Exported types
    MappedFile(..)                          ,
    noMappedFile                            ,


 -- * Methods
-- ** mappedFileFree
    mappedFileFree                          ,


-- ** mappedFileGetBytes
    mappedFileGetBytes                      ,


-- ** mappedFileGetContents
    mappedFileGetContents                   ,


-- ** mappedFileGetLength
    mappedFileGetLength                     ,


-- ** mappedFileNew
    mappedFileNew                           ,


-- ** mappedFileNewFromFd
    mappedFileNewFromFd                     ,


-- ** mappedFileRef
    mappedFileRef                           ,


-- ** mappedFileUnref
    mappedFileUnref                         ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.GLib.Types
import GI.GLib.Callbacks

newtype MappedFile = MappedFile (ForeignPtr MappedFile)
foreign import ccall "g_mapped_file_get_type" c_g_mapped_file_get_type :: 
    IO GType

instance BoxedObject MappedFile where
    boxedType _ = c_g_mapped_file_get_type

noMappedFile :: Maybe MappedFile
noMappedFile = Nothing

-- method MappedFile::new
-- method type : Constructor
-- Args : [Arg {argName = "filename", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "writable", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "filename", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "writable", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "GLib" "MappedFile"
-- throws : True
-- Skip return : False

foreign import ccall "g_mapped_file_new" g_mapped_file_new :: 
    CString ->                              -- filename : TBasicType TUTF8
    CInt ->                                 -- writable : TBasicType TBoolean
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr MappedFile)


mappedFileNew ::
    (MonadIO m) =>
    T.Text ->                               -- filename
    Bool ->                                 -- writable
    m MappedFile
mappedFileNew filename writable = liftIO $ do
    filename' <- textToCString filename
    let writable' = (fromIntegral . fromEnum) writable
    onException (do
        result <- propagateGError $ g_mapped_file_new filename' writable'
        checkUnexpectedReturnNULL "g_mapped_file_new" result
        result' <- (wrapBoxed MappedFile) result
        freeMem filename'
        return result'
     ) (do
        freeMem filename'
     )

-- method MappedFile::new_from_fd
-- method type : Constructor
-- Args : [Arg {argName = "fd", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "writable", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "fd", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "writable", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "GLib" "MappedFile"
-- throws : True
-- Skip return : False

foreign import ccall "g_mapped_file_new_from_fd" g_mapped_file_new_from_fd :: 
    Int32 ->                                -- fd : TBasicType TInt32
    CInt ->                                 -- writable : TBasicType TBoolean
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr MappedFile)


mappedFileNewFromFd ::
    (MonadIO m) =>
    Int32 ->                                -- fd
    Bool ->                                 -- writable
    m MappedFile
mappedFileNewFromFd fd writable = liftIO $ do
    let writable' = (fromIntegral . fromEnum) writable
    onException (do
        result <- propagateGError $ g_mapped_file_new_from_fd fd writable'
        checkUnexpectedReturnNULL "g_mapped_file_new_from_fd" result
        result' <- (wrapBoxed MappedFile) result
        return result'
     ) (do
        return ()
     )

-- method MappedFile::free
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "MappedFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "MappedFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_mapped_file_free" g_mapped_file_free :: 
    Ptr MappedFile ->                       -- _obj : TInterface "GLib" "MappedFile"
    IO ()

{-# DEPRECATED mappedFileFree ["(Since version 2.22)","Use g_mapped_file_unref() instead."]#-}
mappedFileFree ::
    (MonadIO m) =>
    MappedFile ->                           -- _obj
    m ()
mappedFileFree _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    g_mapped_file_free _obj'
    touchManagedPtr _obj
    return ()

-- method MappedFile::get_bytes
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "MappedFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "MappedFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "GLib" "Bytes"
-- throws : False
-- Skip return : False

foreign import ccall "g_mapped_file_get_bytes" g_mapped_file_get_bytes :: 
    Ptr MappedFile ->                       -- _obj : TInterface "GLib" "MappedFile"
    IO (Ptr Bytes)


mappedFileGetBytes ::
    (MonadIO m) =>
    MappedFile ->                           -- _obj
    m Bytes
mappedFileGetBytes _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- g_mapped_file_get_bytes _obj'
    checkUnexpectedReturnNULL "g_mapped_file_get_bytes" result
    result' <- (wrapBoxed Bytes) result
    touchManagedPtr _obj
    return result'

-- method MappedFile::get_contents
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "MappedFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "MappedFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "g_mapped_file_get_contents" g_mapped_file_get_contents :: 
    Ptr MappedFile ->                       -- _obj : TInterface "GLib" "MappedFile"
    IO CString


mappedFileGetContents ::
    (MonadIO m) =>
    MappedFile ->                           -- _obj
    m T.Text
mappedFileGetContents _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- g_mapped_file_get_contents _obj'
    checkUnexpectedReturnNULL "g_mapped_file_get_contents" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr _obj
    return result'

-- method MappedFile::get_length
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "MappedFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "MappedFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUInt64
-- throws : False
-- Skip return : False

foreign import ccall "g_mapped_file_get_length" g_mapped_file_get_length :: 
    Ptr MappedFile ->                       -- _obj : TInterface "GLib" "MappedFile"
    IO Word64


mappedFileGetLength ::
    (MonadIO m) =>
    MappedFile ->                           -- _obj
    m Word64
mappedFileGetLength _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- g_mapped_file_get_length _obj'
    touchManagedPtr _obj
    return result

-- method MappedFile::ref
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "MappedFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "MappedFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "GLib" "MappedFile"
-- throws : False
-- Skip return : False

foreign import ccall "g_mapped_file_ref" g_mapped_file_ref :: 
    Ptr MappedFile ->                       -- _obj : TInterface "GLib" "MappedFile"
    IO (Ptr MappedFile)


mappedFileRef ::
    (MonadIO m) =>
    MappedFile ->                           -- _obj
    m MappedFile
mappedFileRef _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- g_mapped_file_ref _obj'
    checkUnexpectedReturnNULL "g_mapped_file_ref" result
    result' <- (wrapBoxed MappedFile) result
    touchManagedPtr _obj
    return result'

-- method MappedFile::unref
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "MappedFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "MappedFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_mapped_file_unref" g_mapped_file_unref :: 
    Ptr MappedFile ->                       -- _obj : TInterface "GLib" "MappedFile"
    IO ()


mappedFileUnref ::
    (MonadIO m) =>
    MappedFile ->                           -- _obj
    m ()
mappedFileUnref _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    g_mapped_file_unref _obj'
    touchManagedPtr _obj
    return ()