{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- GCancellable is a thread-safe operation cancellation stack used
-- throughout GIO to allow for cancellation of synchronous and
-- asynchronous operations.

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

module GI.Gio.Objects.Cancellable
    ( 

-- * Exported types
    Cancellable(..)                         ,
    IsCancellable                           ,
    toCancellable                           ,
    noCancellable                           ,


 -- * Methods
-- ** Overloaded methods #method:Overloaded methods#

#if defined(ENABLE_OVERLOADING)
    ResolveCancellableMethod                ,
#endif


-- ** cancel #method:cancel#

#if defined(ENABLE_OVERLOADING)
    CancellableCancelMethodInfo             ,
#endif
    cancellableCancel                       ,


-- ** connect #method:connect#

#if defined(ENABLE_OVERLOADING)
    CancellableConnectMethodInfo            ,
#endif
    cancellableConnect                      ,


-- ** disconnect #method:disconnect#

#if defined(ENABLE_OVERLOADING)
    CancellableDisconnectMethodInfo         ,
#endif
    cancellableDisconnect                   ,


-- ** getCurrent #method:getCurrent#

    cancellableGetCurrent                   ,


-- ** getFd #method:getFd#

#if defined(ENABLE_OVERLOADING)
    CancellableGetFdMethodInfo              ,
#endif
    cancellableGetFd                        ,


-- ** isCancelled #method:isCancelled#

#if defined(ENABLE_OVERLOADING)
    CancellableIsCancelledMethodInfo        ,
#endif
    cancellableIsCancelled                  ,


-- ** makePollfd #method:makePollfd#

#if defined(ENABLE_OVERLOADING)
    CancellableMakePollfdMethodInfo         ,
#endif
    cancellableMakePollfd                   ,


-- ** new #method:new#

    cancellableNew                          ,


-- ** popCurrent #method:popCurrent#

#if defined(ENABLE_OVERLOADING)
    CancellablePopCurrentMethodInfo         ,
#endif
    cancellablePopCurrent                   ,


-- ** pushCurrent #method:pushCurrent#

#if defined(ENABLE_OVERLOADING)
    CancellablePushCurrentMethodInfo        ,
#endif
    cancellablePushCurrent                  ,


-- ** releaseFd #method:releaseFd#

#if defined(ENABLE_OVERLOADING)
    CancellableReleaseFdMethodInfo          ,
#endif
    cancellableReleaseFd                    ,


-- ** reset #method:reset#

#if defined(ENABLE_OVERLOADING)
    CancellableResetMethodInfo              ,
#endif
    cancellableReset                        ,


-- ** setErrorIfCancelled #method:setErrorIfCancelled#

#if defined(ENABLE_OVERLOADING)
    CancellableSetErrorIfCancelledMethodInfo,
#endif
    cancellableSetErrorIfCancelled          ,




 -- * Signals
-- ** cancelled #signal:cancelled#

    C_CancellableCancelledCallback          ,
    CancellableCancelledCallback            ,
#if defined(ENABLE_OVERLOADING)
    CancellableCancelledSignalInfo          ,
#endif
    afterCancellableCancelled               ,
    genClosure_CancellableCancelled         ,
    mk_CancellableCancelledCallback         ,
    noCancellableCancelledCallback          ,
    onCancellableCancelled                  ,
    wrap_CancellableCancelledCallback       ,




    ) 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.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 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 GI.GLib.Callbacks as GLib.Callbacks
import qualified GI.GLib.Structs.PollFD as GLib.PollFD
import qualified GI.GObject.Callbacks as GObject.Callbacks
import qualified GI.GObject.Objects.Object as GObject.Object

-- | Memory-managed wrapper type.
newtype Cancellable = Cancellable (ManagedPtr Cancellable)
    deriving (Cancellable -> Cancellable -> Bool
(Cancellable -> Cancellable -> Bool)
-> (Cancellable -> Cancellable -> Bool) -> Eq Cancellable
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Cancellable -> Cancellable -> Bool
$c/= :: Cancellable -> Cancellable -> Bool
== :: Cancellable -> Cancellable -> Bool
$c== :: Cancellable -> Cancellable -> Bool
Eq)
foreign import ccall "g_cancellable_get_type"
    c_g_cancellable_get_type :: IO GType

instance GObject Cancellable where
    gobjectType :: IO GType
gobjectType = IO GType
c_g_cancellable_get_type
    

-- | Convert 'Cancellable' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue Cancellable where
    toGValue :: Cancellable -> IO GValue
toGValue o :: Cancellable
o = do
        GType
gtype <- IO GType
c_g_cancellable_get_type
        Cancellable -> (Ptr Cancellable -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Cancellable
o (GType
-> (GValue -> Ptr Cancellable -> IO ())
-> Ptr Cancellable
-> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr Cancellable -> IO ()
forall a. GObject a => GValue -> Ptr a -> IO ()
B.GValue.set_object)
        
    fromGValue :: GValue -> IO Cancellable
fromGValue gv :: GValue
gv = do
        Ptr Cancellable
ptr <- GValue -> IO (Ptr Cancellable)
forall b. GObject b => GValue -> IO (Ptr b)
B.GValue.get_object GValue
gv :: IO (Ptr Cancellable)
        (ManagedPtr Cancellable -> Cancellable)
-> Ptr Cancellable -> IO Cancellable
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
B.ManagedPtr.newObject ManagedPtr Cancellable -> Cancellable
Cancellable Ptr Cancellable
ptr
        
    

-- | Type class for types which can be safely cast to `Cancellable`, for instance with `toCancellable`.
class (GObject o, O.IsDescendantOf Cancellable o) => IsCancellable o
instance (GObject o, O.IsDescendantOf Cancellable o) => IsCancellable o

instance O.HasParentTypes Cancellable
type instance O.ParentTypes Cancellable = '[GObject.Object.Object]

-- | Cast to `Cancellable`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toCancellable :: (MonadIO m, IsCancellable o) => o -> m Cancellable
toCancellable :: o -> m Cancellable
toCancellable = IO Cancellable -> m Cancellable
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Cancellable -> m Cancellable)
-> (o -> IO Cancellable) -> o -> m Cancellable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr Cancellable -> Cancellable) -> o -> IO Cancellable
forall o o'.
(HasCallStack, GObject o, GObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
unsafeCastTo ManagedPtr Cancellable -> Cancellable
Cancellable

-- | A convenience alias for `Nothing` :: `Maybe` `Cancellable`.
noCancellable :: Maybe Cancellable
noCancellable :: Maybe Cancellable
noCancellable = Maybe Cancellable
forall a. Maybe a
Nothing

#if defined(ENABLE_OVERLOADING)
type family ResolveCancellableMethod (t :: Symbol) (o :: *) :: * where
    ResolveCancellableMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveCancellableMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveCancellableMethod "cancel" o = CancellableCancelMethodInfo
    ResolveCancellableMethod "connect" o = CancellableConnectMethodInfo
    ResolveCancellableMethod "disconnect" o = CancellableDisconnectMethodInfo
    ResolveCancellableMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveCancellableMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveCancellableMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveCancellableMethod "isCancelled" o = CancellableIsCancelledMethodInfo
    ResolveCancellableMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveCancellableMethod "makePollfd" o = CancellableMakePollfdMethodInfo
    ResolveCancellableMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveCancellableMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveCancellableMethod "popCurrent" o = CancellablePopCurrentMethodInfo
    ResolveCancellableMethod "pushCurrent" o = CancellablePushCurrentMethodInfo
    ResolveCancellableMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveCancellableMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveCancellableMethod "releaseFd" o = CancellableReleaseFdMethodInfo
    ResolveCancellableMethod "reset" o = CancellableResetMethodInfo
    ResolveCancellableMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveCancellableMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveCancellableMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveCancellableMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveCancellableMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveCancellableMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveCancellableMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveCancellableMethod "getFd" o = CancellableGetFdMethodInfo
    ResolveCancellableMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveCancellableMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveCancellableMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveCancellableMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveCancellableMethod "setErrorIfCancelled" o = CancellableSetErrorIfCancelledMethodInfo
    ResolveCancellableMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveCancellableMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveCancellableMethod t Cancellable, O.MethodInfo info Cancellable p) => OL.IsLabel t (Cancellable -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#endif

-- signal Cancellable::cancelled
-- | Emitted when the operation has been cancelled.
-- 
-- Can be used by implementations of cancellable operations. If the
-- operation is cancelled from another thread, the signal will be
-- emitted in the thread that cancelled the operation, not the
-- thread that is running the operation.
-- 
-- Note that disconnecting from this signal (or any signal) in a
-- multi-threaded program is prone to race conditions. For instance
-- it is possible that a signal handler may be invoked even after
-- a call to 'GI.GObject.Functions.signalHandlerDisconnect' for that handler has
-- already returned.
-- 
-- There is also a problem when cancellation happens right before
-- connecting to the signal. If this happens the signal will
-- unexpectedly not be emitted, and checking before connecting to
-- the signal leaves a race condition where this is still happening.
-- 
-- In order to make it safe and easy to connect handlers there
-- are two helper functions: 'GI.Gio.Objects.Cancellable.cancellableConnect' and
-- 'GI.Gio.Objects.Cancellable.cancellableDisconnect' which protect against problems
-- like this.
-- 
-- An example of how to us this:
-- 
-- === /C code/
-- >
-- >    // Make sure we don't do unnecessary work if already cancelled
-- >    if (g_cancellable_set_error_if_cancelled (cancellable, error))
-- >      return;
-- >
-- >    // Set up all the data needed to be able to handle cancellation
-- >    // of the operation
-- >    my_data = my_data_new (...);
-- >
-- >    id = 0;
-- >    if (cancellable)
-- >      id = g_cancellable_connect (cancellable,
-- >    			      G_CALLBACK (cancelled_handler)
-- >    			      data, NULL);
-- >
-- >    // cancellable operation here...
-- >
-- >    g_cancellable_disconnect (cancellable, id);
-- >
-- >    // cancelled_handler is never called after this, it is now safe
-- >    // to free the data
-- >    my_data_free (my_data);
-- 
-- 
-- Note that the cancelled signal is emitted in the thread that
-- the user cancelled from, which may be the main thread. So, the
-- cancellable signal should not do something that can block.
type CancellableCancelledCallback =
    IO ()

-- | A convenience synonym for @`Nothing` :: `Maybe` `CancellableCancelledCallback`@.
noCancellableCancelledCallback :: Maybe CancellableCancelledCallback
noCancellableCancelledCallback :: Maybe (IO ())
noCancellableCancelledCallback = Maybe (IO ())
forall a. Maybe a
Nothing

-- | Type for the callback on the (unwrapped) C side.
type C_CancellableCancelledCallback =
    Ptr () ->                               -- object
    Ptr () ->                               -- user_data
    IO ()

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

-- | Wrap the callback into a `GClosure`.
genClosure_CancellableCancelled :: MonadIO m => CancellableCancelledCallback -> m (GClosure C_CancellableCancelledCallback)
genClosure_CancellableCancelled :: IO () -> m (GClosure C_CancellableCancelledCallback)
genClosure_CancellableCancelled cb :: IO ()
cb = IO (GClosure C_CancellableCancelledCallback)
-> m (GClosure C_CancellableCancelledCallback)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (GClosure C_CancellableCancelledCallback)
 -> m (GClosure C_CancellableCancelledCallback))
-> IO (GClosure C_CancellableCancelledCallback)
-> m (GClosure C_CancellableCancelledCallback)
forall a b. (a -> b) -> a -> b
$ do
    let cb' :: C_CancellableCancelledCallback
cb' = IO () -> C_CancellableCancelledCallback
wrap_CancellableCancelledCallback IO ()
cb
    C_CancellableCancelledCallback
-> IO (FunPtr C_CancellableCancelledCallback)
mk_CancellableCancelledCallback C_CancellableCancelledCallback
cb' IO (FunPtr C_CancellableCancelledCallback)
-> (FunPtr C_CancellableCancelledCallback
    -> IO (GClosure C_CancellableCancelledCallback))
-> IO (GClosure C_CancellableCancelledCallback)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= FunPtr C_CancellableCancelledCallback
-> IO (GClosure C_CancellableCancelledCallback)
forall (m :: * -> *) a. MonadIO m => FunPtr a -> m (GClosure a)
B.GClosure.newGClosure


-- | Wrap a `CancellableCancelledCallback` into a `C_CancellableCancelledCallback`.
wrap_CancellableCancelledCallback ::
    CancellableCancelledCallback ->
    C_CancellableCancelledCallback
wrap_CancellableCancelledCallback :: IO () -> C_CancellableCancelledCallback
wrap_CancellableCancelledCallback _cb :: IO ()
_cb _ _ = do
    IO ()
_cb 


-- | Connect a signal handler for the [cancelled](#signal:cancelled) signal, to be run before the default handler.
-- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
-- 
-- @
-- 'Data.GI.Base.Signals.on' cancellable #cancelled callback
-- @
-- 
-- 
onCancellableCancelled :: (IsCancellable a, MonadIO m) => a -> CancellableCancelledCallback -> m SignalHandlerId
onCancellableCancelled :: a -> IO () -> m SignalHandlerId
onCancellableCancelled obj :: a
obj cb :: IO ()
cb = IO SignalHandlerId -> m SignalHandlerId
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO SignalHandlerId -> m SignalHandlerId)
-> IO SignalHandlerId -> m SignalHandlerId
forall a b. (a -> b) -> a -> b
$ do
    let cb' :: C_CancellableCancelledCallback
cb' = IO () -> C_CancellableCancelledCallback
wrap_CancellableCancelledCallback IO ()
cb
    FunPtr C_CancellableCancelledCallback
cb'' <- C_CancellableCancelledCallback
-> IO (FunPtr C_CancellableCancelledCallback)
mk_CancellableCancelledCallback C_CancellableCancelledCallback
cb'
    a
-> Text
-> FunPtr C_CancellableCancelledCallback
-> SignalConnectMode
-> Maybe Text
-> IO SignalHandlerId
forall o a.
GObject o =>
o
-> Text
-> FunPtr a
-> SignalConnectMode
-> Maybe Text
-> IO SignalHandlerId
connectSignalFunPtr a
obj "cancelled" FunPtr C_CancellableCancelledCallback
cb'' SignalConnectMode
SignalConnectBefore Maybe Text
forall a. Maybe a
Nothing

-- | Connect a signal handler for the [cancelled](#signal:cancelled) signal, to be run after the default handler.
-- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
-- 
-- @
-- 'Data.GI.Base.Signals.after' cancellable #cancelled callback
-- @
-- 
-- 
afterCancellableCancelled :: (IsCancellable a, MonadIO m) => a -> CancellableCancelledCallback -> m SignalHandlerId
afterCancellableCancelled :: a -> IO () -> m SignalHandlerId
afterCancellableCancelled obj :: a
obj cb :: IO ()
cb = IO SignalHandlerId -> m SignalHandlerId
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO SignalHandlerId -> m SignalHandlerId)
-> IO SignalHandlerId -> m SignalHandlerId
forall a b. (a -> b) -> a -> b
$ do
    let cb' :: C_CancellableCancelledCallback
cb' = IO () -> C_CancellableCancelledCallback
wrap_CancellableCancelledCallback IO ()
cb
    FunPtr C_CancellableCancelledCallback
cb'' <- C_CancellableCancelledCallback
-> IO (FunPtr C_CancellableCancelledCallback)
mk_CancellableCancelledCallback C_CancellableCancelledCallback
cb'
    a
-> Text
-> FunPtr C_CancellableCancelledCallback
-> SignalConnectMode
-> Maybe Text
-> IO SignalHandlerId
forall o a.
GObject o =>
o
-> Text
-> FunPtr a
-> SignalConnectMode
-> Maybe Text
-> IO SignalHandlerId
connectSignalFunPtr a
obj "cancelled" FunPtr C_CancellableCancelledCallback
cb'' SignalConnectMode
SignalConnectAfter Maybe Text
forall a. Maybe a
Nothing


#if defined(ENABLE_OVERLOADING)
data CancellableCancelledSignalInfo
instance SignalInfo CancellableCancelledSignalInfo where
    type HaskellCallbackType CancellableCancelledSignalInfo = CancellableCancelledCallback
    connectSignal obj cb connectMode detail = do
        let cb' = wrap_CancellableCancelledCallback cb
        cb'' <- mk_CancellableCancelledCallback cb'
        connectSignalFunPtr obj "cancelled" cb'' connectMode detail

#endif

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Cancellable
type instance O.AttributeList Cancellable = CancellableAttributeList
type CancellableAttributeList = ('[ ] :: [(Symbol, *)])
#endif

#if defined(ENABLE_OVERLOADING)
#endif

#if defined(ENABLE_OVERLOADING)
type instance O.SignalList Cancellable = CancellableSignalList
type CancellableSignalList = ('[ '("cancelled", CancellableCancelledSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method Cancellable::new
-- method type : Constructor
-- Args: []
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Gio" , name = "Cancellable" })
-- throws : False
-- Skip return : False

foreign import ccall "g_cancellable_new" g_cancellable_new :: 
    IO (Ptr Cancellable)

-- | Creates a new t'GI.Gio.Objects.Cancellable.Cancellable' object.
-- 
-- Applications that want to start one or more operations
-- that should be cancellable should create a t'GI.Gio.Objects.Cancellable.Cancellable'
-- and pass it to the operations.
-- 
-- One t'GI.Gio.Objects.Cancellable.Cancellable' can be used in multiple consecutive
-- operations or in multiple concurrent operations.
cancellableNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m Cancellable
    -- ^ __Returns:__ a t'GI.Gio.Objects.Cancellable.Cancellable'.
cancellableNew :: m Cancellable
cancellableNew  = IO Cancellable -> m Cancellable
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Cancellable -> m Cancellable)
-> IO Cancellable -> m Cancellable
forall a b. (a -> b) -> a -> b
$ do
    Ptr Cancellable
result <- IO (Ptr Cancellable)
g_cancellable_new
    Text -> Ptr Cancellable -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "cancellableNew" Ptr Cancellable
result
    Cancellable
result' <- ((ManagedPtr Cancellable -> Cancellable)
-> Ptr Cancellable -> IO Cancellable
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr Cancellable -> Cancellable
Cancellable) Ptr Cancellable
result
    Cancellable -> IO Cancellable
forall (m :: * -> *) a. Monad m => a -> m a
return Cancellable
result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method Cancellable::cancel
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GCancellable object."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_cancellable_cancel" g_cancellable_cancel :: 
    Ptr Cancellable ->                      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    IO ()

-- | Will set /@cancellable@/ to cancelled, and will emit the
-- [cancelled]("GI.Gio.Objects.Cancellable#signal:cancelled") signal. (However, see the warning about
-- race conditions in the documentation for that signal if you are
-- planning to connect to it.)
-- 
-- This function is thread-safe. In other words, you can safely call
-- it from a thread other than the one running the operation that was
-- passed the /@cancellable@/.
-- 
-- If /@cancellable@/ is 'P.Nothing', this function returns immediately for convenience.
-- 
-- The convention within GIO is that cancelling an asynchronous
-- operation causes it to complete asynchronously. That is, if you
-- cancel the operation from the same thread in which it is running,
-- then the operation\'s t'GI.Gio.Callbacks.AsyncReadyCallback' will not be invoked until
-- the application returns to the main loop.
cancellableCancel ::
    (B.CallStack.HasCallStack, MonadIO m, IsCancellable a) =>
    a
    -- ^ /@cancellable@/: a t'GI.Gio.Objects.Cancellable.Cancellable' object.
    -> m ()
cancellableCancel :: a -> m ()
cancellableCancel cancellable :: a
cancellable = 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 Cancellable
cancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
cancellable
    Ptr Cancellable -> IO ()
g_cancellable_cancel Ptr Cancellable
cancellable'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
cancellable
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data CancellableCancelMethodInfo
instance (signature ~ (m ()), MonadIO m, IsCancellable a) => O.MethodInfo CancellableCancelMethodInfo a signature where
    overloadedMethod = cancellableCancel

#endif

-- method Cancellable::connect
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "A #GCancellable." , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "callback"
--           , argType =
--               TInterface Name { namespace = "GObject" , name = "Callback" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "The #GCallback to connect."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeNotified
--           , argClosure = 2
--           , argDestroy = 3
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "data"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "Data to pass to @callback."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "data_destroy_func"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "DestroyNotify" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "Free function for @data or %NULL."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeAsync
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TULong)
-- throws : False
-- Skip return : False

foreign import ccall "g_cancellable_connect" g_cancellable_connect :: 
    Ptr Cancellable ->                      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    FunPtr GObject.Callbacks.C_Callback ->  -- callback : TInterface (Name {namespace = "GObject", name = "Callback"})
    Ptr () ->                               -- data : TBasicType TPtr
    FunPtr GLib.Callbacks.C_DestroyNotify -> -- data_destroy_func : TInterface (Name {namespace = "GLib", name = "DestroyNotify"})
    IO CULong

-- | Convenience function to connect to the [cancelled]("GI.Gio.Objects.Cancellable#signal:cancelled")
-- signal. Also handles the race condition that may happen
-- if the cancellable is cancelled right before connecting.
-- 
-- /@callback@/ is called at most once, either directly at the
-- time of the connect if /@cancellable@/ is already cancelled,
-- or when /@cancellable@/ is cancelled in some thread.
-- 
-- /@dataDestroyFunc@/ will be called when the handler is
-- disconnected, or immediately if the cancellable is already
-- cancelled.
-- 
-- See [cancelled]("GI.Gio.Objects.Cancellable#signal:cancelled") for details on how to use this.
-- 
-- Since GLib 2.40, the lock protecting /@cancellable@/ is not held when
-- /@callback@/ is invoked.  This lifts a restriction in place for
-- earlier GLib versions which now makes it easier to write cleanup
-- code that unconditionally invokes e.g. 'GI.Gio.Objects.Cancellable.cancellableCancel'.
-- 
-- /Since: 2.22/
cancellableConnect ::
    (B.CallStack.HasCallStack, MonadIO m, IsCancellable a) =>
    a
    -- ^ /@cancellable@/: A t'GI.Gio.Objects.Cancellable.Cancellable'.
    -> GObject.Callbacks.Callback
    -- ^ /@callback@/: The t'GI.GObject.Callbacks.Callback' to connect.
    -> m CULong
    -- ^ __Returns:__ The id of the signal handler or 0 if /@cancellable@/ has already
    --          been cancelled.
cancellableConnect :: a -> IO () -> m SignalHandlerId
cancellableConnect cancellable :: a
cancellable callback :: IO ()
callback = IO SignalHandlerId -> m SignalHandlerId
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO SignalHandlerId -> m SignalHandlerId)
-> IO SignalHandlerId -> m SignalHandlerId
forall a b. (a -> b) -> a -> b
$ do
    Ptr Cancellable
cancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
cancellable
    FunPtr (IO ())
callback' <- IO () -> IO (FunPtr (IO ()))
GObject.Callbacks.mk_Callback (Maybe (Ptr (FunPtr (IO ()))) -> IO () -> IO ()
GObject.Callbacks.wrap_Callback Maybe (Ptr (FunPtr (IO ())))
forall a. Maybe a
Nothing IO ()
callback)
    let data_ :: Ptr ()
data_ = FunPtr (IO ()) -> Ptr ()
forall a b. FunPtr a -> Ptr b
castFunPtrToPtr FunPtr (IO ())
callback'
    let dataDestroyFunc :: FunPtr (Ptr a -> IO ())
dataDestroyFunc = FunPtr (Ptr a -> IO ())
forall a. FunPtr (Ptr a -> IO ())
safeFreeFunPtrPtr
    SignalHandlerId
result <- Ptr Cancellable
-> FunPtr (IO ())
-> Ptr ()
-> FunPtr C_DestroyNotify
-> IO SignalHandlerId
g_cancellable_connect Ptr Cancellable
cancellable' FunPtr (IO ())
callback' Ptr ()
data_ FunPtr C_DestroyNotify
forall a. FunPtr (Ptr a -> IO ())
dataDestroyFunc
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
cancellable
    SignalHandlerId -> IO SignalHandlerId
forall (m :: * -> *) a. Monad m => a -> m a
return SignalHandlerId
result

#if defined(ENABLE_OVERLOADING)
data CancellableConnectMethodInfo
instance (signature ~ (GObject.Callbacks.Callback -> m CULong), MonadIO m, IsCancellable a) => O.MethodInfo CancellableConnectMethodInfo a signature where
    overloadedMethod = cancellableConnect

#endif

-- method Cancellable::disconnect
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "A #GCancellable or %NULL."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "handler_id"
--           , argType = TBasicType TULong
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "Handler id of the handler to be disconnected, or `0`."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_cancellable_disconnect" g_cancellable_disconnect :: 
    Ptr Cancellable ->                      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    CULong ->                               -- handler_id : TBasicType TULong
    IO ()

-- | Disconnects a handler from a cancellable instance similar to
-- 'GI.GObject.Functions.signalHandlerDisconnect'.  Additionally, in the event that a
-- signal handler is currently running, this call will block until the
-- handler has finished.  Calling this function from a
-- [cancelled]("GI.Gio.Objects.Cancellable#signal:cancelled") signal handler will therefore result in a
-- deadlock.
-- 
-- This avoids a race condition where a thread cancels at the
-- same time as the cancellable operation is finished and the
-- signal handler is removed. See [cancelled]("GI.Gio.Objects.Cancellable#signal:cancelled") for
-- details on how to use this.
-- 
-- If /@cancellable@/ is 'P.Nothing' or /@handlerId@/ is @0@ this function does
-- nothing.
-- 
-- /Since: 2.22/
cancellableDisconnect ::
    (B.CallStack.HasCallStack, MonadIO m, IsCancellable a) =>
    a
    -- ^ /@cancellable@/: A t'GI.Gio.Objects.Cancellable.Cancellable' or 'P.Nothing'.
    -> CULong
    -- ^ /@handlerId@/: Handler id of the handler to be disconnected, or @0@.
    -> m ()
cancellableDisconnect :: a -> SignalHandlerId -> m ()
cancellableDisconnect cancellable :: a
cancellable handlerId :: SignalHandlerId
handlerId = 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 Cancellable
cancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
cancellable
    Ptr Cancellable -> SignalHandlerId -> IO ()
g_cancellable_disconnect Ptr Cancellable
cancellable' SignalHandlerId
handlerId
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
cancellable
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data CancellableDisconnectMethodInfo
instance (signature ~ (CULong -> m ()), MonadIO m, IsCancellable a) => O.MethodInfo CancellableDisconnectMethodInfo a signature where
    overloadedMethod = cancellableDisconnect

#endif

-- method Cancellable::get_fd
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GCancellable." , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TInt)
-- throws : False
-- Skip return : False

foreign import ccall "g_cancellable_get_fd" g_cancellable_get_fd :: 
    Ptr Cancellable ->                      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    IO Int32

-- | Gets the file descriptor for a cancellable job. This can be used to
-- implement cancellable operations on Unix systems. The returned fd will
-- turn readable when /@cancellable@/ is cancelled.
-- 
-- You are not supposed to read from the fd yourself, just check for
-- readable status. Reading to unset the readable status is done
-- with 'GI.Gio.Objects.Cancellable.cancellableReset'.
-- 
-- After a successful return from this function, you should use
-- 'GI.Gio.Objects.Cancellable.cancellableReleaseFd' to free up resources allocated for
-- the returned file descriptor.
-- 
-- See also 'GI.Gio.Objects.Cancellable.cancellableMakePollfd'.
cancellableGetFd ::
    (B.CallStack.HasCallStack, MonadIO m, IsCancellable a) =>
    a
    -- ^ /@cancellable@/: a t'GI.Gio.Objects.Cancellable.Cancellable'.
    -> m Int32
    -- ^ __Returns:__ A valid file descriptor. @-1@ if the file descriptor
    -- is not supported, or on errors.
cancellableGetFd :: a -> m Int32
cancellableGetFd cancellable :: a
cancellable = IO Int32 -> m Int32
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Int32 -> m Int32) -> IO Int32 -> m Int32
forall a b. (a -> b) -> a -> b
$ do
    Ptr Cancellable
cancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
cancellable
    Int32
result <- Ptr Cancellable -> IO Int32
g_cancellable_get_fd Ptr Cancellable
cancellable'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
cancellable
    Int32 -> IO Int32
forall (m :: * -> *) a. Monad m => a -> m a
return Int32
result

#if defined(ENABLE_OVERLOADING)
data CancellableGetFdMethodInfo
instance (signature ~ (m Int32), MonadIO m, IsCancellable a) => O.MethodInfo CancellableGetFdMethodInfo a signature where
    overloadedMethod = cancellableGetFd

#endif

-- method Cancellable::is_cancelled
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GCancellable or %NULL"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "g_cancellable_is_cancelled" g_cancellable_is_cancelled :: 
    Ptr Cancellable ->                      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    IO CInt

-- | Checks if a cancellable job has been cancelled.
cancellableIsCancelled ::
    (B.CallStack.HasCallStack, MonadIO m, IsCancellable a) =>
    a
    -- ^ /@cancellable@/: a t'GI.Gio.Objects.Cancellable.Cancellable' or 'P.Nothing'
    -> m Bool
    -- ^ __Returns:__ 'P.True' if /@cancellable@/ is cancelled,
    -- FALSE if called with 'P.Nothing' or if item is not cancelled.
cancellableIsCancelled :: a -> m Bool
cancellableIsCancelled cancellable :: a
cancellable = IO Bool -> m Bool
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
    Ptr Cancellable
cancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
cancellable
    CInt
result <- Ptr Cancellable -> IO CInt
g_cancellable_is_cancelled Ptr Cancellable
cancellable'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= 0) CInt
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
cancellable
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

#if defined(ENABLE_OVERLOADING)
data CancellableIsCancelledMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsCancellable a) => O.MethodInfo CancellableIsCancelledMethodInfo a signature where
    overloadedMethod = cancellableIsCancelled

#endif

-- method Cancellable::make_pollfd
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GCancellable or %NULL"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "pollfd"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "PollFD" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a pointer to a #GPollFD"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "g_cancellable_make_pollfd" g_cancellable_make_pollfd :: 
    Ptr Cancellable ->                      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr GLib.PollFD.PollFD ->               -- pollfd : TInterface (Name {namespace = "GLib", name = "PollFD"})
    IO CInt

-- | Creates a t'GI.GLib.Structs.PollFD.PollFD' corresponding to /@cancellable@/; this can be passed
-- to 'GI.GLib.Functions.poll' and used to poll for cancellation. This is useful both
-- for unix systems without a native poll and for portability to
-- windows.
-- 
-- When this function returns 'P.True', you should use
-- 'GI.Gio.Objects.Cancellable.cancellableReleaseFd' to free up resources allocated for the
-- /@pollfd@/. After a 'P.False' return, do not call 'GI.Gio.Objects.Cancellable.cancellableReleaseFd'.
-- 
-- If this function returns 'P.False', either no /@cancellable@/ was given or
-- resource limits prevent this function from allocating the necessary
-- structures for polling. (On Linux, you will likely have reached
-- the maximum number of file descriptors.) The suggested way to handle
-- these cases is to ignore the /@cancellable@/.
-- 
-- You are not supposed to read from the fd yourself, just check for
-- readable status. Reading to unset the readable status is done
-- with 'GI.Gio.Objects.Cancellable.cancellableReset'.
-- 
-- /Since: 2.22/
cancellableMakePollfd ::
    (B.CallStack.HasCallStack, MonadIO m, IsCancellable a) =>
    a
    -- ^ /@cancellable@/: a t'GI.Gio.Objects.Cancellable.Cancellable' or 'P.Nothing'
    -> GLib.PollFD.PollFD
    -- ^ /@pollfd@/: a pointer to a t'GI.GLib.Structs.PollFD.PollFD'
    -> m Bool
    -- ^ __Returns:__ 'P.True' if /@pollfd@/ was successfully initialized, 'P.False' on
    --          failure to prepare the cancellable.
cancellableMakePollfd :: a -> PollFD -> m Bool
cancellableMakePollfd cancellable :: a
cancellable pollfd :: PollFD
pollfd = IO Bool -> m Bool
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
    Ptr Cancellable
cancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
cancellable
    Ptr PollFD
pollfd' <- PollFD -> IO (Ptr PollFD)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr PollFD
pollfd
    CInt
result <- Ptr Cancellable -> Ptr PollFD -> IO CInt
g_cancellable_make_pollfd Ptr Cancellable
cancellable' Ptr PollFD
pollfd'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= 0) CInt
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
cancellable
    PollFD -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr PollFD
pollfd
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

#if defined(ENABLE_OVERLOADING)
data CancellableMakePollfdMethodInfo
instance (signature ~ (GLib.PollFD.PollFD -> m Bool), MonadIO m, IsCancellable a) => O.MethodInfo CancellableMakePollfdMethodInfo a signature where
    overloadedMethod = cancellableMakePollfd

#endif

-- method Cancellable::pop_current
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GCancellable object"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_cancellable_pop_current" g_cancellable_pop_current :: 
    Ptr Cancellable ->                      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    IO ()

-- | Pops /@cancellable@/ off the cancellable stack (verifying that /@cancellable@/
-- is on the top of the stack).
cancellablePopCurrent ::
    (B.CallStack.HasCallStack, MonadIO m, IsCancellable a) =>
    a
    -- ^ /@cancellable@/: a t'GI.Gio.Objects.Cancellable.Cancellable' object
    -> m ()
cancellablePopCurrent :: a -> m ()
cancellablePopCurrent cancellable :: a
cancellable = 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 Cancellable
cancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
cancellable
    Ptr Cancellable -> IO ()
g_cancellable_pop_current Ptr Cancellable
cancellable'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
cancellable
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data CancellablePopCurrentMethodInfo
instance (signature ~ (m ()), MonadIO m, IsCancellable a) => O.MethodInfo CancellablePopCurrentMethodInfo a signature where
    overloadedMethod = cancellablePopCurrent

#endif

-- method Cancellable::push_current
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GCancellable object"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_cancellable_push_current" g_cancellable_push_current :: 
    Ptr Cancellable ->                      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    IO ()

-- | Pushes /@cancellable@/ onto the cancellable stack. The current
-- cancellable can then be received using 'GI.Gio.Objects.Cancellable.cancellableGetCurrent'.
-- 
-- This is useful when implementing cancellable operations in
-- code that does not allow you to pass down the cancellable object.
-- 
-- This is typically called automatically by e.g. t'GI.Gio.Interfaces.File.File' operations,
-- so you rarely have to call this yourself.
cancellablePushCurrent ::
    (B.CallStack.HasCallStack, MonadIO m, IsCancellable a) =>
    a
    -- ^ /@cancellable@/: a t'GI.Gio.Objects.Cancellable.Cancellable' object
    -> m ()
cancellablePushCurrent :: a -> m ()
cancellablePushCurrent cancellable :: a
cancellable = 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 Cancellable
cancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
cancellable
    Ptr Cancellable -> IO ()
g_cancellable_push_current Ptr Cancellable
cancellable'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
cancellable
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data CancellablePushCurrentMethodInfo
instance (signature ~ (m ()), MonadIO m, IsCancellable a) => O.MethodInfo CancellablePushCurrentMethodInfo a signature where
    overloadedMethod = cancellablePushCurrent

#endif

-- method Cancellable::release_fd
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GCancellable" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_cancellable_release_fd" g_cancellable_release_fd :: 
    Ptr Cancellable ->                      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    IO ()

-- | Releases a resources previously allocated by 'GI.Gio.Objects.Cancellable.cancellableGetFd'
-- or 'GI.Gio.Objects.Cancellable.cancellableMakePollfd'.
-- 
-- For compatibility reasons with older releases, calling this function
-- is not strictly required, the resources will be automatically freed
-- when the /@cancellable@/ is finalized. However, the /@cancellable@/ will
-- block scarce file descriptors until it is finalized if this function
-- is not called. This can cause the application to run out of file
-- descriptors when many @/GCancellables/@ are used at the same time.
-- 
-- /Since: 2.22/
cancellableReleaseFd ::
    (B.CallStack.HasCallStack, MonadIO m, IsCancellable a) =>
    a
    -- ^ /@cancellable@/: a t'GI.Gio.Objects.Cancellable.Cancellable'
    -> m ()
cancellableReleaseFd :: a -> m ()
cancellableReleaseFd cancellable :: a
cancellable = 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 Cancellable
cancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
cancellable
    Ptr Cancellable -> IO ()
g_cancellable_release_fd Ptr Cancellable
cancellable'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
cancellable
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data CancellableReleaseFdMethodInfo
instance (signature ~ (m ()), MonadIO m, IsCancellable a) => O.MethodInfo CancellableReleaseFdMethodInfo a signature where
    overloadedMethod = cancellableReleaseFd

#endif

-- method Cancellable::reset
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GCancellable object."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_cancellable_reset" g_cancellable_reset :: 
    Ptr Cancellable ->                      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    IO ()

-- | Resets /@cancellable@/ to its uncancelled state.
-- 
-- If cancellable is currently in use by any cancellable operation
-- then the behavior of this function is undefined.
-- 
-- Note that it is generally not a good idea to reuse an existing
-- cancellable for more operations after it has been cancelled once,
-- as this function might tempt you to do. The recommended practice
-- is to drop the reference to a cancellable after cancelling it,
-- and let it die with the outstanding async operations. You should
-- create a fresh cancellable for further async operations.
cancellableReset ::
    (B.CallStack.HasCallStack, MonadIO m, IsCancellable a) =>
    a
    -- ^ /@cancellable@/: a t'GI.Gio.Objects.Cancellable.Cancellable' object.
    -> m ()
cancellableReset :: a -> m ()
cancellableReset cancellable :: a
cancellable = 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 Cancellable
cancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
cancellable
    Ptr Cancellable -> IO ()
g_cancellable_reset Ptr Cancellable
cancellable'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
cancellable
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data CancellableResetMethodInfo
instance (signature ~ (m ()), MonadIO m, IsCancellable a) => O.MethodInfo CancellableResetMethodInfo a signature where
    overloadedMethod = cancellableReset

#endif

-- method Cancellable::set_error_if_cancelled
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GCancellable or %NULL"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "g_cancellable_set_error_if_cancelled" g_cancellable_set_error_if_cancelled :: 
    Ptr Cancellable ->                      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

-- | If the /@cancellable@/ is cancelled, sets the error to notify
-- that the operation was cancelled.
cancellableSetErrorIfCancelled ::
    (B.CallStack.HasCallStack, MonadIO m, IsCancellable a) =>
    a
    -- ^ /@cancellable@/: a t'GI.Gio.Objects.Cancellable.Cancellable' or 'P.Nothing'
    -> m ()
    -- ^ /(Can throw 'Data.GI.Base.GError.GError')/
cancellableSetErrorIfCancelled :: a -> m ()
cancellableSetErrorIfCancelled cancellable :: a
cancellable = 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 Cancellable
cancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
cancellable
    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
$ Ptr Cancellable -> Ptr (Ptr GError) -> IO CInt
g_cancellable_set_error_if_cancelled Ptr Cancellable
cancellable'
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
cancellable
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if defined(ENABLE_OVERLOADING)
data CancellableSetErrorIfCancelledMethodInfo
instance (signature ~ (m ()), MonadIO m, IsCancellable a) => O.MethodInfo CancellableSetErrorIfCancelledMethodInfo a signature where
    overloadedMethod = cancellableSetErrorIfCancelled

#endif

-- method Cancellable::get_current
-- method type : MemberFunction
-- Args: []
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Gio" , name = "Cancellable" })
-- throws : False
-- Skip return : False

foreign import ccall "g_cancellable_get_current" g_cancellable_get_current :: 
    IO (Ptr Cancellable)

-- | Gets the top cancellable from the stack.
cancellableGetCurrent ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m (Maybe Cancellable)
    -- ^ __Returns:__ a t'GI.Gio.Objects.Cancellable.Cancellable' from the top
    -- of the stack, or 'P.Nothing' if the stack is empty.
cancellableGetCurrent :: m (Maybe Cancellable)
cancellableGetCurrent  = IO (Maybe Cancellable) -> m (Maybe Cancellable)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Cancellable) -> m (Maybe Cancellable))
-> IO (Maybe Cancellable) -> m (Maybe Cancellable)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Cancellable
result <- IO (Ptr Cancellable)
g_cancellable_get_current
    Maybe Cancellable
maybeResult <- Ptr Cancellable
-> (Ptr Cancellable -> IO Cancellable) -> IO (Maybe Cancellable)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr Cancellable
result ((Ptr Cancellable -> IO Cancellable) -> IO (Maybe Cancellable))
-> (Ptr Cancellable -> IO Cancellable) -> IO (Maybe Cancellable)
forall a b. (a -> b) -> a -> b
$ \result' :: Ptr Cancellable
result' -> do
        Cancellable
result'' <- ((ManagedPtr Cancellable -> Cancellable)
-> Ptr Cancellable -> IO Cancellable
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr Cancellable -> Cancellable
Cancellable) Ptr Cancellable
result'
        Cancellable -> IO Cancellable
forall (m :: * -> *) a. Monad m => a -> m a
return Cancellable
result''
    Maybe Cancellable -> IO (Maybe Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Cancellable
maybeResult

#if defined(ENABLE_OVERLOADING)
#endif