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

module GI.Gio.Objects.FileIOStream
    ( 

-- * Exported types
    FileIOStream(..)                        ,
    FileIOStreamK                           ,
    toFileIOStream                          ,
    noFileIOStream                          ,


 -- * Methods
-- ** fileIOStreamGetEtag
    fileIOStreamGetEtag                     ,


-- ** fileIOStreamQueryInfo
    fileIOStreamQueryInfo                   ,


-- ** fileIOStreamQueryInfoAsync
    fileIOStreamQueryInfoAsync              ,


-- ** fileIOStreamQueryInfoFinish
    fileIOStreamQueryInfoFinish             ,




    ) 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.Gio.Types
import GI.Gio.Callbacks
import qualified GI.GObject as GObject

newtype FileIOStream = FileIOStream (ForeignPtr FileIOStream)
foreign import ccall "g_file_io_stream_get_type"
    c_g_file_io_stream_get_type :: IO GType

type instance ParentTypes FileIOStream = FileIOStreamParentTypes
type FileIOStreamParentTypes = '[IOStream, GObject.Object, Seekable]

instance GObject FileIOStream where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_g_file_io_stream_get_type
    

class GObject o => FileIOStreamK o
instance (GObject o, IsDescendantOf FileIOStream o) => FileIOStreamK o

toFileIOStream :: FileIOStreamK o => o -> IO FileIOStream
toFileIOStream = unsafeCastTo FileIOStream

noFileIOStream :: Maybe FileIOStream
noFileIOStream = Nothing

type instance AttributeList FileIOStream = FileIOStreamAttributeList
type FileIOStreamAttributeList = ('[ '("closed", IOStreamClosedPropertyInfo), '("input-stream", IOStreamInputStreamPropertyInfo), '("output-stream", IOStreamOutputStreamPropertyInfo)] :: [(Symbol, *)])

type instance SignalList FileIOStream = FileIOStreamSignalList
type FileIOStreamSignalList = ('[ '("notify", GObject.ObjectNotifySignalInfo), '("notify::[property]", GObjectNotifySignalInfo)] :: [(Symbol, *)])

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

foreign import ccall "g_file_io_stream_get_etag" g_file_io_stream_get_etag :: 
    Ptr FileIOStream ->                     -- _obj : TInterface "Gio" "FileIOStream"
    IO CString


fileIOStreamGetEtag ::
    (MonadIO m, FileIOStreamK a) =>
    a ->                                    -- _obj
    m T.Text
fileIOStreamGetEtag _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_file_io_stream_get_etag _obj'
    checkUnexpectedReturnNULL "g_file_io_stream_get_etag" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr _obj
    return result'

-- method FileIOStream::query_info
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "FileIOStream", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "attributes", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "FileIOStream", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "attributes", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gio" "FileInfo"
-- throws : True
-- Skip return : False

foreign import ccall "g_file_io_stream_query_info" g_file_io_stream_query_info :: 
    Ptr FileIOStream ->                     -- _obj : TInterface "Gio" "FileIOStream"
    CString ->                              -- attributes : TBasicType TUTF8
    Ptr Cancellable ->                      -- cancellable : TInterface "Gio" "Cancellable"
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr FileInfo)


fileIOStreamQueryInfo ::
    (MonadIO m, FileIOStreamK a, CancellableK b) =>
    a ->                                    -- _obj
    T.Text ->                               -- attributes
    Maybe (b) ->                            -- cancellable
    m FileInfo
fileIOStreamQueryInfo _obj attributes cancellable = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    attributes' <- textToCString attributes
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            let jCancellable' = unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    onException (do
        result <- propagateGError $ g_file_io_stream_query_info _obj' attributes' maybeCancellable
        checkUnexpectedReturnNULL "g_file_io_stream_query_info" result
        result' <- (wrapObject FileInfo) result
        touchManagedPtr _obj
        whenJust cancellable touchManagedPtr
        freeMem attributes'
        return result'
     ) (do
        freeMem attributes'
     )

-- method FileIOStream::query_info_async
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "FileIOStream", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "attributes", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "io_priority", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "callback", argType = TInterface "Gio" "AsyncReadyCallback", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeAsync, argClosure = 5, argDestroy = -1, transfer = TransferNothing},Arg {argName = "user_data", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "FileIOStream", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "attributes", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "io_priority", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "callback", argType = TInterface "Gio" "AsyncReadyCallback", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeAsync, argClosure = 5, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_file_io_stream_query_info_async" g_file_io_stream_query_info_async :: 
    Ptr FileIOStream ->                     -- _obj : TInterface "Gio" "FileIOStream"
    CString ->                              -- attributes : TBasicType TUTF8
    Int32 ->                                -- io_priority : TBasicType TInt32
    Ptr Cancellable ->                      -- cancellable : TInterface "Gio" "Cancellable"
    FunPtr AsyncReadyCallbackC ->           -- callback : TInterface "Gio" "AsyncReadyCallback"
    Ptr () ->                               -- user_data : TBasicType TVoid
    IO ()


fileIOStreamQueryInfoAsync ::
    (MonadIO m, FileIOStreamK a, CancellableK b) =>
    a ->                                    -- _obj
    T.Text ->                               -- attributes
    Int32 ->                                -- io_priority
    Maybe (b) ->                            -- cancellable
    Maybe (AsyncReadyCallback) ->           -- callback
    m ()
fileIOStreamQueryInfoAsync _obj attributes io_priority cancellable callback = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    attributes' <- textToCString attributes
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            let jCancellable' = unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    ptrcallback <- callocMem :: IO (Ptr (FunPtr AsyncReadyCallbackC))
    maybeCallback <- case callback of
        Nothing -> return (castPtrToFunPtr nullPtr)
        Just jCallback -> do
            jCallback' <- mkAsyncReadyCallback (asyncReadyCallbackWrapper (Just ptrcallback) jCallback)
            poke ptrcallback jCallback'
            return jCallback'
    let user_data = nullPtr
    g_file_io_stream_query_info_async _obj' attributes' io_priority maybeCancellable maybeCallback user_data
    touchManagedPtr _obj
    whenJust cancellable touchManagedPtr
    freeMem attributes'
    return ()

-- method FileIOStream::query_info_finish
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "FileIOStream", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "result", argType = TInterface "Gio" "AsyncResult", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "FileIOStream", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "result", argType = TInterface "Gio" "AsyncResult", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gio" "FileInfo"
-- throws : True
-- Skip return : False

foreign import ccall "g_file_io_stream_query_info_finish" g_file_io_stream_query_info_finish :: 
    Ptr FileIOStream ->                     -- _obj : TInterface "Gio" "FileIOStream"
    Ptr AsyncResult ->                      -- result : TInterface "Gio" "AsyncResult"
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr FileInfo)


fileIOStreamQueryInfoFinish ::
    (MonadIO m, FileIOStreamK a, AsyncResultK b) =>
    a ->                                    -- _obj
    b ->                                    -- result
    m FileInfo
fileIOStreamQueryInfoFinish _obj result_ = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let result_' = unsafeManagedPtrCastPtr result_
    onException (do
        result <- propagateGError $ g_file_io_stream_query_info_finish _obj' result_'
        checkUnexpectedReturnNULL "g_file_io_stream_query_info_finish" result
        result' <- (wrapObject FileInfo) result
        touchManagedPtr _obj
        touchManagedPtr result_
        return result'
     ) (do
        return ()
     )