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

 -- * Signals
-- ** ActionCallback #signal:ActionCallback#
    ActionCallback                          ,
    ActionCallback_WithClosures             ,
    C_ActionCallback                        ,
    drop_closures_ActionCallback            ,
    dynamic_ActionCallback                  ,
    genClosure_ActionCallback               ,
    mk_ActionCallback                       ,
    noActionCallback                        ,
    noActionCallback_WithClosures           ,
    wrap_ActionCallback                     ,




    ) 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

import {-# SOURCE #-} qualified GI.Notify.Objects.Notification as Notify.Notification

-- callback ActionCallback
--          -> Callable {returnType = Nothing, returnMayBeNull = False, returnTransfer = TransferNothing, returnDocumentation = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, args = [Arg {argCName = "notification", argType = TInterface (Name {namespace = "Notify", name = "Notification"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "action", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, 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 = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = 2, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}], skipReturn = False, callableThrows = False, callableDeprecated = Nothing, callableDocumentation = Documentation {rawDocText = Just "An action callback function.", sinceVersion = Nothing}}
type C_ActionCallback =
    Ptr Notify.Notification.Notification ->
    CString ->
    Ptr () ->
    IO ()

-- Args : [Arg {argCName = "notification", argType = TInterface (Name {namespace = "Notify", name = "Notification"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "action", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, 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 = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = 2, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "dynamic" __dynamic_C_ActionCallback :: FunPtr C_ActionCallback -> C_ActionCallback

dynamic_ActionCallback ::
    (B.CallStack.HasCallStack, MonadIO m, Notify.Notification.IsNotification a) =>
    FunPtr C_ActionCallback
    -> a
    -> T.Text
    -> Ptr ()
    -> m ()
dynamic_ActionCallback __funPtr notification action userData = liftIO $ do
    notification' <- unsafeManagedPtrCastPtr notification
    action' <- textToCString action
    (__dynamic_C_ActionCallback __funPtr) notification' action' userData
    touchManagedPtr notification
    freeMem action'
    return ()

foreign import ccall "wrapper"
    mk_ActionCallback :: C_ActionCallback -> IO (FunPtr C_ActionCallback)

type ActionCallback =
    Notify.Notification.Notification ->
    T.Text ->
    IO ()

noActionCallback :: Maybe ActionCallback
noActionCallback = Nothing

type ActionCallback_WithClosures =
    Notify.Notification.Notification ->
    T.Text ->
    Ptr () ->
    IO ()

noActionCallback_WithClosures :: Maybe ActionCallback_WithClosures
noActionCallback_WithClosures = Nothing

drop_closures_ActionCallback :: ActionCallback -> ActionCallback_WithClosures
drop_closures_ActionCallback _f notification action _ = _f notification action

genClosure_ActionCallback :: ActionCallback -> IO Closure
genClosure_ActionCallback cb = do
    let cb' = drop_closures_ActionCallback cb
    let cb'' = wrap_ActionCallback Nothing cb'
    mk_ActionCallback cb'' >>= newCClosure


wrap_ActionCallback ::
    Maybe (Ptr (FunPtr C_ActionCallback)) ->
    ActionCallback_WithClosures ->
    Ptr Notify.Notification.Notification ->
    CString ->
    Ptr () ->
    IO ()
wrap_ActionCallback funptrptr _cb notification action userData = do
    notification' <- (newObject Notify.Notification.Notification) notification
    action' <- cstringToText action
    _cb  notification' action' userData
    maybeReleaseFunPtr funptrptr