module Data.GI.Base.GClosure
( GClosure(..)
, newGClosure
, wrapGClosurePtr
, newGClosureFromPtr
, noGClosure
, unrefGClosure
, disownGClosure
) where
import Foreign
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.GI.Base.BasicTypes
import Data.GI.Base.CallStack (HasCallStack)
import Data.GI.Base.ManagedPtr (newBoxed, wrapBoxed, freeBoxed,
disownManagedPtr)
newtype GClosure a = GClosure (ManagedPtr (GClosure a))
noGClosure :: Maybe (GClosure a)
noGClosure = Nothing
foreign import ccall "g_closure_get_type" c_g_closure_get_type ::
IO GType
instance BoxedObject (GClosure a) where
boxedType _ = c_g_closure_get_type
foreign import ccall "g_cclosure_new" g_cclosure_new
:: FunPtr a -> Ptr () -> FunPtr c -> IO (Ptr (GClosure a))
foreign import ccall "& haskell_gi_release_signal_closure"
ptr_to_release_closure :: FunPtr (Ptr () -> Ptr () -> IO ())
newGClosure :: MonadIO m => FunPtr a -> m (GClosure a)
newGClosure ptr = liftIO $ do
closure <- g_cclosure_new ptr nullPtr ptr_to_release_closure
wrapGClosurePtr closure
wrapGClosurePtr :: Ptr (GClosure a) -> IO (GClosure a)
wrapGClosurePtr = wrapBoxed GClosure
newGClosureFromPtr :: Ptr (GClosure a) -> IO (GClosure a)
newGClosureFromPtr = newBoxed GClosure
unrefGClosure :: (HasCallStack, MonadIO m) => GClosure a -> m ()
unrefGClosure closure = liftIO $ freeBoxed closure
disownGClosure :: GClosure a -> IO (Ptr (GClosure a))
disownGClosure = disownManagedPtr