{- |
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.Poppler.Callbacks
    ( 

 -- * Signals
-- ** AttachmentSaveFunc #signal:AttachmentSaveFunc#
    AttachmentSaveFunc                      ,
    AttachmentSaveFunc_WithClosures         ,
    C_AttachmentSaveFunc                    ,
    drop_closures_AttachmentSaveFunc        ,
    dynamic_AttachmentSaveFunc              ,
    mk_AttachmentSaveFunc                   ,
    noAttachmentSaveFunc                    ,
    noAttachmentSaveFunc_WithClosures       ,


-- ** MediaSaveFunc #signal:MediaSaveFunc#
    C_MediaSaveFunc                         ,
    MediaSaveFunc                           ,
    MediaSaveFunc_WithClosures              ,
    drop_closures_MediaSaveFunc             ,
    dynamic_MediaSaveFunc                   ,
    mk_MediaSaveFunc                        ,
    noMediaSaveFunc                         ,
    noMediaSaveFunc_WithClosures            ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP


-- callback MediaSaveFunc
--          -> Callable {returnType = Just (TBasicType TBoolean), returnMayBeNull = False, returnTransfer = TransferNothing, returnDocumentation = Documentation {rawDocText = Just "%TRUE if successful, %FALSE (with @error set) if failed.", sinceVersion = Nothing}, args = [Arg {argCName = "buf", argType = TCArray False (-1) 1 (TBasicType TUInt8), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "buffer containing\n  bytes to be written.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "count", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of bytes in @buf.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "user data passed to poppler_media_save_to_callback()", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = 2, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}], skipReturn = False, callableThrows = True, callableDeprecated = Nothing, callableDocumentation = Documentation {rawDocText = Just "Specifies the type of the function passed to\npoppler_media_save_to_callback().  It is called once for each block of\nbytes that is \"written\" by poppler_media_save_to_callback().  If\nsuccessful it should return %TRUE.  If an error occurs it should set\n@error and return %FALSE, in which case poppler_media_save_to_callback()\nwill fail with the same error.", sinceVersion = Just "0.14"}}
type C_MediaSaveFunc =
    Ptr Word8 ->
    Word64 ->
    Ptr () ->
    Ptr (Ptr GError) ->
    IO CInt

-- Args : [Arg {argCName = "buf", argType = TCArray False (-1) 1 (TBasicType TUInt8), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "buffer containing\n  bytes to be written.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "count", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of bytes in @buf.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "user data passed to poppler_media_save_to_callback()", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = 2, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : [Arg {argCName = "count", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of bytes in @buf.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "dynamic" __dynamic_C_MediaSaveFunc :: FunPtr C_MediaSaveFunc -> C_MediaSaveFunc

dynamic_MediaSaveFunc ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    FunPtr C_MediaSaveFunc
    -> ByteString
    {- ^ /@buf@/: buffer containing
  bytes to be written. -}
    -> Ptr ()
    {- ^ /@data@/: user data passed to 'GI.Poppler.Objects.Media.mediaSaveToCallback' -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
dynamic_MediaSaveFunc __funPtr buf data_ = liftIO $ do
    let count = fromIntegral $ B.length buf
    buf' <- packByteString buf
    onException (do
        _ <- propagateGError $ (__dynamic_C_MediaSaveFunc __funPtr) buf' count data_
        freeMem buf'
        return ()
     ) (do
        freeMem buf'
     )

foreign import ccall "wrapper"
    mk_MediaSaveFunc :: C_MediaSaveFunc -> IO (FunPtr C_MediaSaveFunc)

type MediaSaveFunc =
    ByteString ->
    IO ()

noMediaSaveFunc :: Maybe MediaSaveFunc
noMediaSaveFunc = Nothing

type MediaSaveFunc_WithClosures =
    ByteString ->
    Ptr () ->
    IO ()

noMediaSaveFunc_WithClosures :: Maybe MediaSaveFunc_WithClosures
noMediaSaveFunc_WithClosures = Nothing

drop_closures_MediaSaveFunc :: MediaSaveFunc -> MediaSaveFunc_WithClosures
drop_closures_MediaSaveFunc _f buf _ = _f buf

-- No Haskell->C wrapper generated since the function throws.

-- callback AttachmentSaveFunc
--          -> Callable {returnType = Just (TBasicType TBoolean), returnMayBeNull = False, returnTransfer = TransferNothing, returnDocumentation = Documentation {rawDocText = Just "%TRUE if successful, %FALSE (with @error set) if failed.", sinceVersion = Nothing}, args = [Arg {argCName = "buf", argType = TCArray False (-1) 1 (TBasicType TUInt8), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "buffer containing\n  bytes to be written.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "count", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of bytes in @buf.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "user data passed to poppler_attachment_save_to_callback()", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = 2, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}], skipReturn = False, callableThrows = True, callableDeprecated = Nothing, callableDocumentation = Documentation {rawDocText = Just "Specifies the type of the function passed to\npoppler_attachment_save_to_callback().  It is called once for each block of\nbytes that is \"written\" by poppler_attachment_save_to_callback().  If\nsuccessful it should return %TRUE.  If an error occurs it should set\n@error and return %FALSE, in which case poppler_attachment_save_to_callback()\nwill fail with the same error.", sinceVersion = Nothing}}
type C_AttachmentSaveFunc =
    Ptr Word8 ->
    Word64 ->
    Ptr () ->
    Ptr (Ptr GError) ->
    IO CInt

-- Args : [Arg {argCName = "buf", argType = TCArray False (-1) 1 (TBasicType TUInt8), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "buffer containing\n  bytes to be written.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "count", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of bytes in @buf.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "user data passed to poppler_attachment_save_to_callback()", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = 2, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : [Arg {argCName = "count", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of bytes in @buf.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "dynamic" __dynamic_C_AttachmentSaveFunc :: FunPtr C_AttachmentSaveFunc -> C_AttachmentSaveFunc

dynamic_AttachmentSaveFunc ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    FunPtr C_AttachmentSaveFunc
    -> ByteString
    {- ^ /@buf@/: buffer containing
  bytes to be written. -}
    -> Ptr ()
    {- ^ /@data@/: user data passed to 'GI.Poppler.Objects.Attachment.attachmentSaveToCallback' -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
dynamic_AttachmentSaveFunc __funPtr buf data_ = liftIO $ do
    let count = fromIntegral $ B.length buf
    buf' <- packByteString buf
    onException (do
        _ <- propagateGError $ (__dynamic_C_AttachmentSaveFunc __funPtr) buf' count data_
        freeMem buf'
        return ()
     ) (do
        freeMem buf'
     )

foreign import ccall "wrapper"
    mk_AttachmentSaveFunc :: C_AttachmentSaveFunc -> IO (FunPtr C_AttachmentSaveFunc)

type AttachmentSaveFunc =
    ByteString ->
    IO ()

noAttachmentSaveFunc :: Maybe AttachmentSaveFunc
noAttachmentSaveFunc = Nothing

type AttachmentSaveFunc_WithClosures =
    ByteString ->
    Ptr () ->
    IO ()

noAttachmentSaveFunc_WithClosures :: Maybe AttachmentSaveFunc_WithClosures
noAttachmentSaveFunc_WithClosures = Nothing

drop_closures_AttachmentSaveFunc :: AttachmentSaveFunc -> AttachmentSaveFunc_WithClosures
drop_closures_AttachmentSaveFunc _f buf _ = _f buf

-- No Haskell->C wrapper generated since the function throws.