-- | 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.Gsk.Callbacks
    ( 

 -- * Signals


-- ** ParseErrorFunc #signal:ParseErrorFunc#

    C_ParseErrorFunc                        ,
    ParseErrorFunc                          ,
    ParseErrorFunc_WithClosures             ,
    drop_closures_ParseErrorFunc            ,
    dynamic_ParseErrorFunc                  ,
    genClosure_ParseErrorFunc               ,
    mk_ParseErrorFunc                       ,
    noParseErrorFunc                        ,
    noParseErrorFunc_WithClosures           ,
    wrap_ParseErrorFunc                     ,


-- ** PathForeachFunc #signal:PathForeachFunc#

    C_PathForeachFunc                       ,
    PathForeachFunc                         ,
    PathForeachFunc_WithClosures            ,
    drop_closures_PathForeachFunc           ,
    dynamic_PathForeachFunc                 ,
    genClosure_PathForeachFunc              ,
    mk_PathForeachFunc                      ,
    noPathForeachFunc                       ,
    noPathForeachFunc_WithClosures          ,
    wrap_PathForeachFunc                    ,




    ) 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)
import qualified GI.Graphene.Structs.Point as Graphene.Point
import {-# SOURCE #-} qualified GI.Gsk.Enums as Gsk.Enums
import {-# SOURCE #-} qualified GI.Gsk.Structs.ParseLocation as Gsk.ParseLocation

#else
import qualified GI.Graphene.Structs.Point as Graphene.Point
import {-# SOURCE #-} qualified GI.Gsk.Enums as Gsk.Enums
import {-# SOURCE #-} qualified GI.Gsk.Structs.ParseLocation as Gsk.ParseLocation

#endif

-- callback PathForeachFunc
{- Callable
  { returnType = Just (TBasicType TBoolean)
  , returnMayBeNull = False
  , returnTransfer = TransferNothing
  , returnDocumentation =
      Documentation
        { rawDocText =
            Just
              "%TRUE to continue iterating the path, %FALSE to\n  immediately abort and not call the function again."
        , sinceVersion = Nothing
        }
  , args =
      [ Arg
          { argCName = "op"
          , argType =
              TInterface Name { namespace = "Gsk" , name = "PathOperation" }
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "The operation" , sinceVersion = Nothing }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "pts"
          , argType =
              TInterface Name { namespace = "Graphene" , name = "Point" }
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "The points of the operation"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "n_pts"
          , argType = TBasicType TSize
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "The number of points"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "weight"
          , argType = TBasicType TFloat
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText =
                    Just "The weight for conic curves, or unused if not a conic curve"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "user_data"
          , argType = TBasicType TPtr
          , direction = DirectionIn
          , mayBeNull = True
          , argDoc =
              Documentation
                { rawDocText = Just "The user data provided with the function"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = True
          , transfer = TransferNothing
          }
      ]
  , skipReturn = False
  , callableThrows = False
  , callableDeprecated = Nothing
  , callableDocumentation =
      Documentation
        { rawDocText =
            Just
              "Prototype of the callback to iterate through the operations of\na path.\n\nFor each operation, the callback is given the @op itself, the points\nthat the operation is applied to in @pts, and a @weight for conic\ncurves. The @n_pts argument is somewhat redundant, since the number\nof points can be inferred from the operation.\n\nEach contour of the path starts with a @GSK_PATH_MOVE operation.\nClosed contours end with a @GSK_PATH_CLOSE operation."
        , sinceVersion = Nothing
        }
  , callableResolvable = Nothing
  }
-}
-- | Type for the callback on the (unwrapped) C side.
type C_PathForeachFunc =
    CUInt ->
    Ptr Graphene.Point.Point ->
    FCT.CSize ->
    CFloat ->
    Ptr () ->
    IO CInt

-- Args: [ Arg
--           { argCName = "op"
--           , argType =
--               TInterface Name { namespace = "Gsk" , name = "PathOperation" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "The operation" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "pts"
--           , argType =
--               TInterface Name { namespace = "Graphene" , name = "Point" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "The points of the operation"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "n_pts"
--           , argType = TBasicType TSize
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "The number of points"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "weight"
--           , argType = TBasicType TFloat
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "The weight for conic curves, or unused if not a conic curve"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "user_data"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "The user data provided with the function"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = True
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "dynamic" __dynamic_C_PathForeachFunc :: FunPtr C_PathForeachFunc -> C_PathForeachFunc

-- | Given a pointer to a foreign C function, wrap it into a function callable from Haskell.
dynamic_PathForeachFunc ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    FunPtr C_PathForeachFunc
    -> Gsk.Enums.PathOperation
    -- ^ /@op@/: The operation
    -> Graphene.Point.Point
    -- ^ /@pts@/: The points of the operation
    -> FCT.CSize
    -- ^ /@nPts@/: The number of points
    -> Float
    -- ^ /@weight@/: The weight for conic curves, or unused if not a conic curve
    -> Ptr ()
    -- ^ /@userData@/: The user data provided with the function
    -> m Bool
    -- ^ __Returns:__ 'P.True' to continue iterating the path, 'P.False' to
    --   immediately abort and not call the function again.
dynamic_PathForeachFunc :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
FunPtr C_PathForeachFunc
-> PathOperation -> Point -> CSize -> Float -> Ptr () -> m Bool
dynamic_PathForeachFunc FunPtr C_PathForeachFunc
__funPtr PathOperation
op Point
pts CSize
nPts Float
weight Ptr ()
userData = IO Bool -> m Bool
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    let op' :: CUInt
op' = (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CUInt) -> (PathOperation -> Int) -> PathOperation -> CUInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PathOperation -> Int
forall a. Enum a => a -> Int
fromEnum) PathOperation
op
    Ptr Point
pts' <- Point -> IO (Ptr Point)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Point
pts
    let weight' :: CFloat
weight' = Float -> CFloat
forall a b. (Real a, Fractional b) => a -> b
realToFrac Float
weight
    CInt
result <- (FunPtr C_PathForeachFunc -> C_PathForeachFunc
__dynamic_C_PathForeachFunc FunPtr C_PathForeachFunc
__funPtr) CUInt
op' Ptr Point
pts' CSize
nPts CFloat
weight' Ptr ()
userData
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
    Point -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Point
pts
    Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

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

-- | Prototype of the callback to iterate through the operations of
-- a path.
-- 
-- For each operation, the callback is given the /@op@/ itself, the points
-- that the operation is applied to in /@pts@/, and a /@weight@/ for conic
-- curves. The /@nPts@/ argument is somewhat redundant, since the number
-- of points can be inferred from the operation.
-- 
-- Each contour of the path starts with a /@gSKPATHMOVE@/ operation.
-- Closed contours end with a /@gSKPATHCLOSE@/ operation.
type PathForeachFunc =
    Gsk.Enums.PathOperation
    -- ^ /@op@/: The operation
    -> Graphene.Point.Point
    -- ^ /@pts@/: The points of the operation
    -> FCT.CSize
    -- ^ /@nPts@/: The number of points
    -> Float
    -- ^ /@weight@/: The weight for conic curves, or unused if not a conic curve
    -> IO Bool
    -- ^ __Returns:__ 'P.True' to continue iterating the path, 'P.False' to
    --   immediately abort and not call the function again.

-- | A convenience synonym for @`Nothing` :: `Maybe` `PathForeachFunc`@.
noPathForeachFunc :: Maybe PathForeachFunc
noPathForeachFunc :: Maybe PathForeachFunc
noPathForeachFunc = Maybe PathForeachFunc
forall a. Maybe a
Nothing

-- | Prototype of the callback to iterate through the operations of
-- a path.
-- 
-- For each operation, the callback is given the /@op@/ itself, the points
-- that the operation is applied to in /@pts@/, and a /@weight@/ for conic
-- curves. The /@nPts@/ argument is somewhat redundant, since the number
-- of points can be inferred from the operation.
-- 
-- Each contour of the path starts with a /@gSKPATHMOVE@/ operation.
-- Closed contours end with a /@gSKPATHCLOSE@/ operation.
type PathForeachFunc_WithClosures =
    Gsk.Enums.PathOperation
    -- ^ /@op@/: The operation
    -> Graphene.Point.Point
    -- ^ /@pts@/: The points of the operation
    -> FCT.CSize
    -- ^ /@nPts@/: The number of points
    -> Float
    -- ^ /@weight@/: The weight for conic curves, or unused if not a conic curve
    -> Ptr ()
    -- ^ /@userData@/: The user data provided with the function
    -> IO Bool
    -- ^ __Returns:__ 'P.True' to continue iterating the path, 'P.False' to
    --   immediately abort and not call the function again.

-- | A convenience synonym for @`Nothing` :: `Maybe` `PathForeachFunc_WithClosures`@.
noPathForeachFunc_WithClosures :: Maybe PathForeachFunc_WithClosures
noPathForeachFunc_WithClosures :: Maybe PathForeachFunc_WithClosures
noPathForeachFunc_WithClosures = Maybe PathForeachFunc_WithClosures
forall a. Maybe a
Nothing

-- | A simple wrapper that ignores the closure arguments.
drop_closures_PathForeachFunc :: PathForeachFunc -> PathForeachFunc_WithClosures
drop_closures_PathForeachFunc :: PathForeachFunc -> PathForeachFunc_WithClosures
drop_closures_PathForeachFunc PathForeachFunc
_f PathOperation
op Point
pts CSize
nPts Float
weight Ptr ()
_ = PathForeachFunc
_f PathOperation
op Point
pts CSize
nPts Float
weight

-- | Wrap the callback into a `GClosure`.
genClosure_PathForeachFunc :: MonadIO m => PathForeachFunc -> m (GClosure C_PathForeachFunc)
genClosure_PathForeachFunc :: forall (m :: * -> *).
MonadIO m =>
PathForeachFunc -> m (GClosure C_PathForeachFunc)
genClosure_PathForeachFunc PathForeachFunc
cb = IO (GClosure C_PathForeachFunc) -> m (GClosure C_PathForeachFunc)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (GClosure C_PathForeachFunc) -> m (GClosure C_PathForeachFunc))
-> IO (GClosure C_PathForeachFunc)
-> m (GClosure C_PathForeachFunc)
forall a b. (a -> b) -> a -> b
$ do
    let cb' :: PathForeachFunc_WithClosures
cb' = PathForeachFunc -> PathForeachFunc_WithClosures
drop_closures_PathForeachFunc PathForeachFunc
cb
    let cb'' :: C_PathForeachFunc
cb'' = Maybe (Ptr (FunPtr C_PathForeachFunc))
-> PathForeachFunc_WithClosures -> C_PathForeachFunc
wrap_PathForeachFunc Maybe (Ptr (FunPtr C_PathForeachFunc))
forall a. Maybe a
Nothing PathForeachFunc_WithClosures
cb'
    C_PathForeachFunc -> IO (FunPtr C_PathForeachFunc)
mk_PathForeachFunc C_PathForeachFunc
cb'' IO (FunPtr C_PathForeachFunc)
-> (FunPtr C_PathForeachFunc -> IO (GClosure C_PathForeachFunc))
-> IO (GClosure C_PathForeachFunc)
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_PathForeachFunc -> IO (GClosure C_PathForeachFunc)
forall (m :: * -> *) a. MonadIO m => FunPtr a -> m (GClosure a)
B.GClosure.newGClosure


-- | Wrap a `PathForeachFunc` into a `C_PathForeachFunc`.
wrap_PathForeachFunc :: 
    Maybe (Ptr (FunPtr C_PathForeachFunc)) ->
    PathForeachFunc_WithClosures ->
    C_PathForeachFunc
wrap_PathForeachFunc :: Maybe (Ptr (FunPtr C_PathForeachFunc))
-> PathForeachFunc_WithClosures -> C_PathForeachFunc
wrap_PathForeachFunc Maybe (Ptr (FunPtr C_PathForeachFunc))
gi'funptrptr PathForeachFunc_WithClosures
gi'cb CUInt
op Ptr Point
pts CSize
nPts CFloat
weight Ptr ()
userData = do
    let op' :: PathOperation
op' = (Int -> PathOperation
forall a. Enum a => Int -> a
toEnum (Int -> PathOperation) -> (CUInt -> Int) -> CUInt -> PathOperation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CUInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral) CUInt
op
    Ptr Point -> (Point -> IO CInt) -> IO CInt
forall a b.
(HasCallStack, ManagedPtrNewtype a) =>
Ptr a -> (a -> IO b) -> IO b
B.ManagedPtr.withTransient  Ptr Point
pts ((Point -> IO CInt) -> IO CInt) -> (Point -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Point
pts' -> do
        let weight' :: Float
weight' = CFloat -> Float
forall a b. (Real a, Fractional b) => a -> b
realToFrac CFloat
weight
        Bool
result <- PathForeachFunc_WithClosures
gi'cb  PathOperation
op' Point
pts' CSize
nPts Float
weight' Ptr ()
userData
        Maybe (Ptr (FunPtr C_PathForeachFunc)) -> IO ()
forall a. Maybe (Ptr (FunPtr a)) -> IO ()
maybeReleaseFunPtr Maybe (Ptr (FunPtr C_PathForeachFunc))
gi'funptrptr
        let result' :: CInt
result' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
P.fromIntegral (Int -> CInt) -> (Bool -> Int) -> Bool -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
P.fromEnum) Bool
result
        CInt -> IO CInt
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return CInt
result'


-- callback ParseErrorFunc
{- Callable
  { returnType = Nothing
  , returnMayBeNull = False
  , returnTransfer = TransferNothing
  , returnDocumentation =
      Documentation { rawDocText = Nothing , sinceVersion = Nothing }
  , args =
      [ Arg
          { argCName = "start"
          , argType =
              TInterface Name { namespace = "Gsk" , name = "ParseLocation" }
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "start of the error location"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "end"
          , argType =
              TInterface Name { namespace = "Gsk" , name = "ParseLocation" }
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "end of the error location"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "error"
          , argType = TError
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "the error" , sinceVersion = Nothing }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "user_data"
          , argType = TBasicType TPtr
          , direction = DirectionIn
          , mayBeNull = True
          , argDoc =
              Documentation
                { rawDocText = Just "user data" , sinceVersion = Nothing }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = True
          , transfer = TransferNothing
          }
      ]
  , skipReturn = False
  , callableThrows = False
  , callableDeprecated = Nothing
  , callableDocumentation =
      Documentation
        { rawDocText =
            Just
              "Type of callback that is called when an error occurs\nduring node deserialization."
        , sinceVersion = Nothing
        }
  , callableResolvable = Nothing
  }
-}
-- | Type for the callback on the (unwrapped) C side.
type C_ParseErrorFunc =
    Ptr Gsk.ParseLocation.ParseLocation ->
    Ptr Gsk.ParseLocation.ParseLocation ->
    Ptr GError ->
    Ptr () ->
    IO ()

-- Args: [ Arg
--           { argCName = "start"
--           , argType =
--               TInterface Name { namespace = "Gsk" , name = "ParseLocation" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "start of the error location"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "end"
--           , argType =
--               TInterface Name { namespace = "Gsk" , name = "ParseLocation" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "end of the error location"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "error"
--           , argType = TError
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the error" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "user_data"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "user data" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = True
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "dynamic" __dynamic_C_ParseErrorFunc :: FunPtr C_ParseErrorFunc -> C_ParseErrorFunc

-- | Given a pointer to a foreign C function, wrap it into a function callable from Haskell.
dynamic_ParseErrorFunc ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    FunPtr C_ParseErrorFunc
    -> Gsk.ParseLocation.ParseLocation
    -- ^ /@start@/: start of the error location
    -> Gsk.ParseLocation.ParseLocation
    -- ^ /@end@/: end of the error location
    -> GError
    -- ^ /@error@/: the error
    -> Ptr ()
    -- ^ /@userData@/: user data
    -> m ()
dynamic_ParseErrorFunc :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
FunPtr C_ParseErrorFunc
-> ParseLocation -> ParseLocation -> GError -> Ptr () -> m ()
dynamic_ParseErrorFunc FunPtr C_ParseErrorFunc
__funPtr ParseLocation
start ParseLocation
end GError
error_ Ptr ()
userData = 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
    Ptr ParseLocation
start' <- ParseLocation -> IO (Ptr ParseLocation)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr ParseLocation
start
    Ptr ParseLocation
end' <- ParseLocation -> IO (Ptr ParseLocation)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr ParseLocation
end
    Ptr GError
error_' <- GError -> IO (Ptr GError)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr GError
error_
    (FunPtr C_ParseErrorFunc -> C_ParseErrorFunc
__dynamic_C_ParseErrorFunc FunPtr C_ParseErrorFunc
__funPtr) Ptr ParseLocation
start' Ptr ParseLocation
end' Ptr GError
error_' Ptr ()
userData
    ParseLocation -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr ParseLocation
start
    ParseLocation -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr ParseLocation
end
    GError -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr GError
error_
    () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

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

-- | Type of callback that is called when an error occurs
-- during node deserialization.
type ParseErrorFunc =
    Gsk.ParseLocation.ParseLocation
    -- ^ /@start@/: start of the error location
    -> Gsk.ParseLocation.ParseLocation
    -- ^ /@end@/: end of the error location
    -> GError
    -- ^ /@error@/: the error
    -> IO ()

-- | A convenience synonym for @`Nothing` :: `Maybe` `ParseErrorFunc`@.
noParseErrorFunc :: Maybe ParseErrorFunc
noParseErrorFunc :: Maybe ParseErrorFunc
noParseErrorFunc = Maybe ParseErrorFunc
forall a. Maybe a
Nothing

-- | Type of callback that is called when an error occurs
-- during node deserialization.
type ParseErrorFunc_WithClosures =
    Gsk.ParseLocation.ParseLocation
    -- ^ /@start@/: start of the error location
    -> Gsk.ParseLocation.ParseLocation
    -- ^ /@end@/: end of the error location
    -> GError
    -- ^ /@error@/: the error
    -> Ptr ()
    -- ^ /@userData@/: user data
    -> IO ()

-- | A convenience synonym for @`Nothing` :: `Maybe` `ParseErrorFunc_WithClosures`@.
noParseErrorFunc_WithClosures :: Maybe ParseErrorFunc_WithClosures
noParseErrorFunc_WithClosures :: Maybe ParseErrorFunc_WithClosures
noParseErrorFunc_WithClosures = Maybe ParseErrorFunc_WithClosures
forall a. Maybe a
Nothing

-- | A simple wrapper that ignores the closure arguments.
drop_closures_ParseErrorFunc :: ParseErrorFunc -> ParseErrorFunc_WithClosures
drop_closures_ParseErrorFunc :: ParseErrorFunc -> ParseErrorFunc_WithClosures
drop_closures_ParseErrorFunc ParseErrorFunc
_f ParseLocation
start ParseLocation
end GError
error_ Ptr ()
_ = ParseErrorFunc
_f ParseLocation
start ParseLocation
end GError
error_

-- | Wrap the callback into a `GClosure`.
genClosure_ParseErrorFunc :: MonadIO m => ParseErrorFunc -> m (GClosure C_ParseErrorFunc)
genClosure_ParseErrorFunc :: forall (m :: * -> *).
MonadIO m =>
ParseErrorFunc -> m (GClosure C_ParseErrorFunc)
genClosure_ParseErrorFunc ParseErrorFunc
cb = IO (GClosure C_ParseErrorFunc) -> m (GClosure C_ParseErrorFunc)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (GClosure C_ParseErrorFunc) -> m (GClosure C_ParseErrorFunc))
-> IO (GClosure C_ParseErrorFunc) -> m (GClosure C_ParseErrorFunc)
forall a b. (a -> b) -> a -> b
$ do
    let cb' :: ParseErrorFunc_WithClosures
cb' = ParseErrorFunc -> ParseErrorFunc_WithClosures
drop_closures_ParseErrorFunc ParseErrorFunc
cb
    let cb'' :: C_ParseErrorFunc
cb'' = Maybe (Ptr (FunPtr C_ParseErrorFunc))
-> ParseErrorFunc_WithClosures -> C_ParseErrorFunc
wrap_ParseErrorFunc Maybe (Ptr (FunPtr C_ParseErrorFunc))
forall a. Maybe a
Nothing ParseErrorFunc_WithClosures
cb'
    C_ParseErrorFunc -> IO (FunPtr C_ParseErrorFunc)
mk_ParseErrorFunc C_ParseErrorFunc
cb'' IO (FunPtr C_ParseErrorFunc)
-> (FunPtr C_ParseErrorFunc -> IO (GClosure C_ParseErrorFunc))
-> IO (GClosure C_ParseErrorFunc)
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_ParseErrorFunc -> IO (GClosure C_ParseErrorFunc)
forall (m :: * -> *) a. MonadIO m => FunPtr a -> m (GClosure a)
B.GClosure.newGClosure


-- | Wrap a `ParseErrorFunc` into a `C_ParseErrorFunc`.
wrap_ParseErrorFunc :: 
    Maybe (Ptr (FunPtr C_ParseErrorFunc)) ->
    ParseErrorFunc_WithClosures ->
    C_ParseErrorFunc
wrap_ParseErrorFunc :: Maybe (Ptr (FunPtr C_ParseErrorFunc))
-> ParseErrorFunc_WithClosures -> C_ParseErrorFunc
wrap_ParseErrorFunc Maybe (Ptr (FunPtr C_ParseErrorFunc))
gi'funptrptr ParseErrorFunc_WithClosures
gi'cb Ptr ParseLocation
start Ptr ParseLocation
end Ptr GError
error_ Ptr ()
userData = do
    ParseLocation
start' <- ((ManagedPtr ParseLocation -> ParseLocation)
-> Ptr ParseLocation -> IO ParseLocation
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
newPtr ManagedPtr ParseLocation -> ParseLocation
Gsk.ParseLocation.ParseLocation) Ptr ParseLocation
start
    ParseLocation
end' <- ((ManagedPtr ParseLocation -> ParseLocation)
-> Ptr ParseLocation -> IO ParseLocation
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
newPtr ManagedPtr ParseLocation -> ParseLocation
Gsk.ParseLocation.ParseLocation) Ptr ParseLocation
end
    GError
error_' <- ((ManagedPtr GError -> GError) -> Ptr GError -> IO GError
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
newBoxed ManagedPtr GError -> GError
GError) Ptr GError
error_
    ParseErrorFunc_WithClosures
gi'cb  ParseLocation
start' ParseLocation
end' GError
error_' Ptr ()
userData
    Maybe (Ptr (FunPtr C_ParseErrorFunc)) -> IO ()
forall a. Maybe (Ptr (FunPtr a)) -> IO ()
maybeReleaseFunPtr Maybe (Ptr (FunPtr C_ParseErrorFunc))
gi'funptrptr