{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

A set of utility functions for thread locking. This interface and
all his related methods are deprecated since 2.12.
-}

module GI.Atk.Objects.Misc
    ( 

-- * Exported types
    Misc(..)                                ,
    IsMisc                                  ,
    toMisc                                  ,
    noMisc                                  ,


 -- * Methods
-- ** getInstance #method:getInstance#
    miscGetInstance                         ,


-- ** threadsEnter #method:threadsEnter#
    MiscThreadsEnterMethodInfo              ,
    miscThreadsEnter                        ,


-- ** threadsLeave #method:threadsLeave#
    MiscThreadsLeaveMethodInfo              ,
    miscThreadsLeave                        ,




    ) 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 qualified GI.GObject.Objects.Object as GObject.Object

newtype Misc = Misc (ManagedPtr Misc)
foreign import ccall "atk_misc_get_type"
    c_atk_misc_get_type :: IO GType

instance GObject Misc where
    gobjectType _ = c_atk_misc_get_type
    

class GObject o => IsMisc o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError Misc a) =>
    IsMisc a
#endif
instance IsMisc Misc
instance GObject.Object.IsObject Misc

toMisc :: IsMisc o => o -> IO Misc
toMisc = unsafeCastTo Misc

noMisc :: Maybe Misc
noMisc = Nothing

type family ResolveMiscMethod (t :: Symbol) (o :: *) :: * where
    ResolveMiscMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveMiscMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveMiscMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveMiscMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveMiscMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveMiscMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveMiscMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveMiscMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveMiscMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveMiscMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveMiscMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveMiscMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveMiscMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveMiscMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveMiscMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveMiscMethod "threadsEnter" o = MiscThreadsEnterMethodInfo
    ResolveMiscMethod "threadsLeave" o = MiscThreadsLeaveMethodInfo
    ResolveMiscMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveMiscMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveMiscMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveMiscMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveMiscMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveMiscMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveMiscMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveMiscMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveMiscMethod t Misc, O.MethodInfo info Misc p) => O.IsLabelProxy t (Misc -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveMiscMethod t Misc, O.MethodInfo info Misc p) => O.IsLabel t (Misc -> p) where
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

instance O.HasAttributeList Misc
type instance O.AttributeList Misc = MiscAttributeList
type MiscAttributeList = ('[ ] :: [(Symbol, *)])

type instance O.SignalList Misc = MiscSignalList
type MiscSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method Misc::threads_enter
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "misc", argType = TInterface (Name {namespace = "Atk", name = "Misc"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an AtkMisc instance for this application.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "atk_misc_threads_enter" atk_misc_threads_enter :: 
    Ptr Misc ->                             -- misc : TInterface (Name {namespace = "Atk", name = "Misc"})
    IO ()

{-# DEPRECATED miscThreadsEnter ["Since 2.12."] #-}
{- |
Take the thread mutex for the GUI toolkit,
if one exists.
(This method is implemented by the toolkit ATK implementation layer;
 for instance, for GTK+, GAIL implements this via GDK_THREADS_ENTER).

@since 1.13
-}
miscThreadsEnter ::
    (B.CallStack.HasCallStack, MonadIO m, IsMisc a) =>
    a
    {- ^ /@misc@/: an AtkMisc instance for this application. -}
    -> m ()
miscThreadsEnter misc = liftIO $ do
    misc' <- unsafeManagedPtrCastPtr misc
    atk_misc_threads_enter misc'
    touchManagedPtr misc
    return ()

data MiscThreadsEnterMethodInfo
instance (signature ~ (m ()), MonadIO m, IsMisc a) => O.MethodInfo MiscThreadsEnterMethodInfo a signature where
    overloadedMethod _ = miscThreadsEnter

-- method Misc::threads_leave
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "misc", argType = TInterface (Name {namespace = "Atk", name = "Misc"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an AtkMisc instance for this application.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "atk_misc_threads_leave" atk_misc_threads_leave :: 
    Ptr Misc ->                             -- misc : TInterface (Name {namespace = "Atk", name = "Misc"})
    IO ()

{-# DEPRECATED miscThreadsLeave ["Since 2.12."] #-}
{- |
Release the thread mutex for the GUI toolkit,
if one exists. This method, and atk_misc_threads_enter,
are needed in some situations by threaded application code which
services ATK requests, since fulfilling ATK requests often
requires calling into the GUI toolkit.  If a long-running or
potentially blocking call takes place inside such a block, it should
be bracketed by atk_misc_threads_leave\/atk_misc_threads_enter calls.
(This method is implemented by the toolkit ATK implementation layer;
 for instance, for GTK+, GAIL implements this via GDK_THREADS_LEAVE).

@since 1.13
-}
miscThreadsLeave ::
    (B.CallStack.HasCallStack, MonadIO m, IsMisc a) =>
    a
    {- ^ /@misc@/: an AtkMisc instance for this application. -}
    -> m ()
miscThreadsLeave misc = liftIO $ do
    misc' <- unsafeManagedPtrCastPtr misc
    atk_misc_threads_leave misc'
    touchManagedPtr misc
    return ()

data MiscThreadsLeaveMethodInfo
instance (signature ~ (m ()), MonadIO m, IsMisc a) => O.MethodInfo MiscThreadsLeaveMethodInfo a signature where
    overloadedMethod _ = miscThreadsLeave

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

foreign import ccall "atk_misc_get_instance" atk_misc_get_instance :: 
    IO (Ptr Misc)

{-# DEPRECATED miscGetInstance ["Since 2.12."] #-}
{- |
Obtain the singleton instance of AtkMisc for this application.

@since 1.13
-}
miscGetInstance ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m Misc
    {- ^ __Returns:__ The singleton instance of AtkMisc for this application. -}
miscGetInstance  = liftIO $ do
    result <- atk_misc_get_instance
    checkUnexpectedReturnNULL "miscGetInstance" result
    result' <- (newObject Misc) result
    return result'