-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria

#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif

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            ,


-- ** NssPasswordFunc #signal:NssPasswordFunc#

    C_NssPasswordFunc                       ,
    NssPasswordFunc                         ,
    dynamic_NssPasswordFunc                 ,
    genClosure_NssPasswordFunc              ,
    mk_NssPasswordFunc                      ,
    noNssPasswordFunc                       ,
    wrap_NssPasswordFunc                    ,




    ) 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.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GArray as B.GArray
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GHashTable as B.GHT
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
import qualified Data.Coerce as Coerce
import qualified Data.Text as T
import qualified Data.Kind as DK
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL
import qualified GHC.Records as R
import qualified Data.Word as DW
import qualified Data.Int as DI
import qualified System.Posix.Types as SPT
import qualified Foreign.C.Types as FCT

-- Workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/23392
#if MIN_VERSION_base(4,18,0)

#else

#endif

-- callback NssPasswordFunc
{- Callable
  { returnType = Just (TBasicType TUTF8)
  , returnMayBeNull = False
  , returnTransfer = TransferEverything
  , returnDocumentation =
      Documentation { rawDocText = Nothing , sinceVersion = Nothing }
  , args =
      [ Arg
          { argCName = "text"
          , argType = TBasicType TUTF8
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation { rawDocText = Nothing , sinceVersion = Nothing }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = False
          , transfer = TransferNothing
          }
      ]
  , skipReturn = False
  , callableThrows = False
  , callableDeprecated = Nothing
  , callableDocumentation =
      Documentation { rawDocText = Nothing , sinceVersion = Nothing }
  , callableResolvable = Nothing
  }
-}
-- | Type for the callback on the (unwrapped) C side.
type C_NssPasswordFunc =
    CString ->
    IO CString

-- Args: [ Arg
--           { argCName = "text"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation { rawDocText = Nothing , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "dynamic" __dynamic_C_NssPasswordFunc :: FunPtr C_NssPasswordFunc -> C_NssPasswordFunc

-- | Given a pointer to a foreign C function, wrap it into a function callable from Haskell.
dynamic_NssPasswordFunc ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    FunPtr C_NssPasswordFunc
    -> T.Text
    -> m T.Text
dynamic_NssPasswordFunc :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
FunPtr C_NssPasswordFunc -> Text -> m Text
dynamic_NssPasswordFunc FunPtr C_NssPasswordFunc
__funPtr Text
text = IO Text -> m Text
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Text -> m Text) -> IO Text -> m Text
forall a b. (a -> b) -> a -> b
$ do
    CString
text' <- Text -> IO CString
textToCString Text
text
    CString
result <- (FunPtr C_NssPasswordFunc -> C_NssPasswordFunc
__dynamic_C_NssPasswordFunc FunPtr C_NssPasswordFunc
__funPtr) CString
text'
    Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"nssPasswordFunc" CString
result
    Text
result' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
result
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
text'
    Text -> IO Text
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result'

-- | Generate a function pointer callable from C code, from a `C_NssPasswordFunc`.
foreign import ccall "wrapper"
    mk_NssPasswordFunc :: C_NssPasswordFunc -> IO (FunPtr C_NssPasswordFunc)

-- | /No description available in the introspection data./
type NssPasswordFunc =
    T.Text
    -> IO T.Text

-- | A convenience synonym for @`Nothing` :: `Maybe` `NssPasswordFunc`@.
noNssPasswordFunc :: Maybe NssPasswordFunc
noNssPasswordFunc :: Maybe (Text -> IO Text)
noNssPasswordFunc = Maybe (Text -> IO Text)
forall a. Maybe a
Nothing

-- | Wrap the callback into a `GClosure`.
genClosure_NssPasswordFunc :: MonadIO m => NssPasswordFunc -> m (GClosure C_NssPasswordFunc)
genClosure_NssPasswordFunc :: forall (m :: * -> *).
MonadIO m =>
(Text -> IO Text) -> m (GClosure C_NssPasswordFunc)
genClosure_NssPasswordFunc Text -> IO Text
cb = IO (GClosure C_NssPasswordFunc) -> m (GClosure C_NssPasswordFunc)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (GClosure C_NssPasswordFunc) -> m (GClosure C_NssPasswordFunc))
-> IO (GClosure C_NssPasswordFunc)
-> m (GClosure C_NssPasswordFunc)
forall a b. (a -> b) -> a -> b
$ do
    let cb' :: C_NssPasswordFunc
cb' = Maybe (Ptr (FunPtr C_NssPasswordFunc))
-> (Text -> IO Text) -> C_NssPasswordFunc
wrap_NssPasswordFunc Maybe (Ptr (FunPtr C_NssPasswordFunc))
forall a. Maybe a
Nothing Text -> IO Text
cb
    C_NssPasswordFunc -> IO (FunPtr C_NssPasswordFunc)
mk_NssPasswordFunc C_NssPasswordFunc
cb' IO (FunPtr C_NssPasswordFunc)
-> (FunPtr C_NssPasswordFunc -> IO (GClosure C_NssPasswordFunc))
-> IO (GClosure C_NssPasswordFunc)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= FunPtr C_NssPasswordFunc -> IO (GClosure C_NssPasswordFunc)
forall (m :: * -> *) a. MonadIO m => FunPtr a -> m (GClosure a)
B.GClosure.newGClosure


-- | Wrap a `NssPasswordFunc` into a `C_NssPasswordFunc`.
wrap_NssPasswordFunc :: 
    Maybe (Ptr (FunPtr C_NssPasswordFunc)) ->
    NssPasswordFunc ->
    C_NssPasswordFunc
wrap_NssPasswordFunc :: Maybe (Ptr (FunPtr C_NssPasswordFunc))
-> (Text -> IO Text) -> C_NssPasswordFunc
wrap_NssPasswordFunc Maybe (Ptr (FunPtr C_NssPasswordFunc))
gi'funptrptr Text -> IO Text
gi'cb CString
text = do
    Text
text' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
text
    Text
result <- Text -> IO Text
gi'cb  Text
text'
    Maybe (Ptr (FunPtr C_NssPasswordFunc)) -> IO ()
forall a. Maybe (Ptr (FunPtr a)) -> IO ()
maybeReleaseFunPtr Maybe (Ptr (FunPtr C_NssPasswordFunc))
gi'funptrptr
    CString
result' <- Text -> IO CString
textToCString Text
result
    C_NssPasswordFunc
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return CString
result'


-- 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
          , argCallbackUserData = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "count"
          , argType = TBasicType TSize
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "number of bytes in @buf."
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = 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 = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = True
          , 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"
        }
  , callableResolvable = Nothing
  }
-}
-- | Type for the callback on the (unwrapped) C side.
type C_MediaSaveFunc =
    Ptr Word8 ->
    FCT.CSize ->
    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
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "count"
--           , argType = TBasicType TSize
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "number of bytes in @buf."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = 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 = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = True
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: [ Arg
--              { argCName = "count"
--              , argType = TBasicType TSize
--              , direction = DirectionIn
--              , mayBeNull = False
--              , argDoc =
--                  Documentation
--                    { rawDocText = Just "number of bytes in @buf."
--                    , sinceVersion = Nothing
--                    }
--              , argScope = ScopeTypeInvalid
--              , argClosure = -1
--              , argDestroy = -1
--              , argCallerAllocates = False
--              , argCallbackUserData = False
--              , transfer = TransferNothing
--              }
--          ]
-- returnType: Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

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

-- | Given a pointer to a foreign C function, wrap it into a function callable from Haskell.
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 :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
FunPtr C_MediaSaveFunc -> ByteString -> Ptr () -> m ()
dynamic_MediaSaveFunc FunPtr C_MediaSaveFunc
__funPtr ByteString
buf Ptr ()
data_ = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    let count :: CSize
count = Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CSize) -> Int -> CSize
forall a b. (a -> b) -> a -> b
$ ByteString -> Int
B.length ByteString
buf
    Ptr Word8
buf' <- ByteString -> IO (Ptr Word8)
packByteString ByteString
buf
    IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
onException (do
        CInt
_ <- (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CInt) -> IO CInt)
-> (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ (FunPtr C_MediaSaveFunc -> C_MediaSaveFunc
__dynamic_C_MediaSaveFunc FunPtr C_MediaSaveFunc
__funPtr) Ptr Word8
buf' CSize
count Ptr ()
data_
        Ptr Word8 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word8
buf'
        () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     ) (do
        Ptr Word8 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word8
buf'
     )

-- | Generate a function pointer callable from C code, from a `C_MediaSaveFunc`.
foreign import ccall "wrapper"
    mk_MediaSaveFunc :: C_MediaSaveFunc -> IO (FunPtr C_MediaSaveFunc)

-- | Specifies the type of the function passed to
-- 'GI.Poppler.Objects.Media.mediaSaveToCallback'.  It is called once for each block of
-- bytes that is \"written\" by 'GI.Poppler.Objects.Media.mediaSaveToCallback'.  If
-- successful it should return 'P.True'.  If an error occurs it should set
-- /@error@/ and return 'P.False', in which case 'GI.Poppler.Objects.Media.mediaSaveToCallback'
-- will fail with the same error.
-- 
-- /Since: 0.14/
type MediaSaveFunc =
    ByteString
    -- ^ /@buf@/: buffer containing
    --   bytes to be written.
    -> IO ()
    -- ^ __Returns:__ 'P.True' if successful, 'P.False' (with /@error@/ set) if failed. /(Can throw 'Data.GI.Base.GError.GError')/

-- | A convenience synonym for @`Nothing` :: `Maybe` `MediaSaveFunc`@.
noMediaSaveFunc :: Maybe MediaSaveFunc
noMediaSaveFunc :: Maybe MediaSaveFunc
noMediaSaveFunc = Maybe MediaSaveFunc
forall a. Maybe a
Nothing

-- | Specifies the type of the function passed to
-- 'GI.Poppler.Objects.Media.mediaSaveToCallback'.  It is called once for each block of
-- bytes that is \"written\" by 'GI.Poppler.Objects.Media.mediaSaveToCallback'.  If
-- successful it should return 'P.True'.  If an error occurs it should set
-- /@error@/ and return 'P.False', in which case 'GI.Poppler.Objects.Media.mediaSaveToCallback'
-- will fail with the same error.
-- 
-- /Since: 0.14/
type MediaSaveFunc_WithClosures =
    ByteString
    -- ^ /@buf@/: buffer containing
    --   bytes to be written.
    -> Ptr ()
    -- ^ /@data@/: user data passed to 'GI.Poppler.Objects.Media.mediaSaveToCallback'
    -> IO ()
    -- ^ __Returns:__ 'P.True' if successful, 'P.False' (with /@error@/ set) if failed. /(Can throw 'Data.GI.Base.GError.GError')/

-- | A convenience synonym for @`Nothing` :: `Maybe` `MediaSaveFunc_WithClosures`@.
noMediaSaveFunc_WithClosures :: Maybe MediaSaveFunc_WithClosures
noMediaSaveFunc_WithClosures :: Maybe MediaSaveFunc_WithClosures
noMediaSaveFunc_WithClosures = Maybe MediaSaveFunc_WithClosures
forall a. Maybe a
Nothing

-- | A simple wrapper that ignores the closure arguments.
drop_closures_MediaSaveFunc :: MediaSaveFunc -> MediaSaveFunc_WithClosures
drop_closures_MediaSaveFunc :: MediaSaveFunc -> MediaSaveFunc_WithClosures
drop_closures_MediaSaveFunc MediaSaveFunc
_f ByteString
buf Ptr ()
_ = MediaSaveFunc
_f ByteString
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
          , argCallbackUserData = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "count"
          , argType = TBasicType TSize
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "number of bytes in @buf."
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = 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 = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = True
          , 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
        }
  , callableResolvable = Nothing
  }
-}
-- | Type for the callback on the (unwrapped) C side.
type C_AttachmentSaveFunc =
    Ptr Word8 ->
    FCT.CSize ->
    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
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "count"
--           , argType = TBasicType TSize
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "number of bytes in @buf."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = 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 = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = True
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: [ Arg
--              { argCName = "count"
--              , argType = TBasicType TSize
--              , direction = DirectionIn
--              , mayBeNull = False
--              , argDoc =
--                  Documentation
--                    { rawDocText = Just "number of bytes in @buf."
--                    , sinceVersion = Nothing
--                    }
--              , argScope = ScopeTypeInvalid
--              , argClosure = -1
--              , argDestroy = -1
--              , argCallerAllocates = False
--              , argCallbackUserData = False
--              , transfer = TransferNothing
--              }
--          ]
-- returnType: Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

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

-- | Given a pointer to a foreign C function, wrap it into a function callable from Haskell.
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 :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
FunPtr C_MediaSaveFunc -> ByteString -> Ptr () -> m ()
dynamic_AttachmentSaveFunc FunPtr C_MediaSaveFunc
__funPtr ByteString
buf Ptr ()
data_ = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    let count :: CSize
count = Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CSize) -> Int -> CSize
forall a b. (a -> b) -> a -> b
$ ByteString -> Int
B.length ByteString
buf
    Ptr Word8
buf' <- ByteString -> IO (Ptr Word8)
packByteString ByteString
buf
    IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
onException (do
        CInt
_ <- (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CInt) -> IO CInt)
-> (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ (FunPtr C_MediaSaveFunc -> C_MediaSaveFunc
__dynamic_C_AttachmentSaveFunc FunPtr C_MediaSaveFunc
__funPtr) Ptr Word8
buf' CSize
count Ptr ()
data_
        Ptr Word8 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word8
buf'
        () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     ) (do
        Ptr Word8 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word8
buf'
     )

-- | Generate a function pointer callable from C code, from a `C_AttachmentSaveFunc`.
foreign import ccall "wrapper"
    mk_AttachmentSaveFunc :: C_AttachmentSaveFunc -> IO (FunPtr C_AttachmentSaveFunc)

-- | Specifies the type of the function passed to
-- 'GI.Poppler.Objects.Attachment.attachmentSaveToCallback'.  It is called once for each block of
-- bytes that is \"written\" by 'GI.Poppler.Objects.Attachment.attachmentSaveToCallback'.  If
-- successful it should return 'P.True'.  If an error occurs it should set
-- /@error@/ and return 'P.False', in which case 'GI.Poppler.Objects.Attachment.attachmentSaveToCallback'
-- will fail with the same error.
type AttachmentSaveFunc =
    ByteString
    -- ^ /@buf@/: buffer containing
    --   bytes to be written.
    -> IO ()
    -- ^ __Returns:__ 'P.True' if successful, 'P.False' (with /@error@/ set) if failed. /(Can throw 'Data.GI.Base.GError.GError')/

-- | A convenience synonym for @`Nothing` :: `Maybe` `AttachmentSaveFunc`@.
noAttachmentSaveFunc :: Maybe AttachmentSaveFunc
noAttachmentSaveFunc :: Maybe MediaSaveFunc
noAttachmentSaveFunc = Maybe MediaSaveFunc
forall a. Maybe a
Nothing

-- | Specifies the type of the function passed to
-- 'GI.Poppler.Objects.Attachment.attachmentSaveToCallback'.  It is called once for each block of
-- bytes that is \"written\" by 'GI.Poppler.Objects.Attachment.attachmentSaveToCallback'.  If
-- successful it should return 'P.True'.  If an error occurs it should set
-- /@error@/ and return 'P.False', in which case 'GI.Poppler.Objects.Attachment.attachmentSaveToCallback'
-- will fail with the same error.
type AttachmentSaveFunc_WithClosures =
    ByteString
    -- ^ /@buf@/: buffer containing
    --   bytes to be written.
    -> Ptr ()
    -- ^ /@data@/: user data passed to 'GI.Poppler.Objects.Attachment.attachmentSaveToCallback'
    -> IO ()
    -- ^ __Returns:__ 'P.True' if successful, 'P.False' (with /@error@/ set) if failed. /(Can throw 'Data.GI.Base.GError.GError')/

-- | A convenience synonym for @`Nothing` :: `Maybe` `AttachmentSaveFunc_WithClosures`@.
noAttachmentSaveFunc_WithClosures :: Maybe AttachmentSaveFunc_WithClosures
noAttachmentSaveFunc_WithClosures :: Maybe MediaSaveFunc_WithClosures
noAttachmentSaveFunc_WithClosures = Maybe MediaSaveFunc_WithClosures
forall a. Maybe a
Nothing

-- | A simple wrapper that ignores the closure arguments.
drop_closures_AttachmentSaveFunc :: AttachmentSaveFunc -> AttachmentSaveFunc_WithClosures
drop_closures_AttachmentSaveFunc :: MediaSaveFunc -> MediaSaveFunc_WithClosures
drop_closures_AttachmentSaveFunc MediaSaveFunc
_f ByteString
buf Ptr ()
_ = MediaSaveFunc
_f ByteString
buf

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