-- | 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                     ,




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

-- 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
          , 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
          , 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
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "user_data"
          , argType = TBasicType TPtr
          , direction = DirectionIn
          , mayBeNull = True
          , argDoc =
              Documentation
                { rawDocText = Just "user data" , sinceVersion = Nothing }
          , argScope = ScopeTypeInvalid
          , argClosure = 3
          , argDestroy = -1
          , argCallerAllocates = False
          , 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
--           , 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
--           , 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
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "user_data"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "user data" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = 3
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , 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 (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 (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 (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 (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