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

The #GThreadPool struct represents a thread pool. It has three
public read-only members, but the underlying struct is bigger,
so you must not copy this struct.
-}

module GI.GLib.Structs.ThreadPool
    ( 

-- * Exported types
    ThreadPool(..)                          ,
    noThreadPool                            ,


 -- * Methods
-- ** threadPoolFree
    threadPoolFree                          ,


-- ** threadPoolGetMaxThreads
    threadPoolGetMaxThreads                 ,


-- ** threadPoolGetNumThreads
    threadPoolGetNumThreads                 ,


-- ** threadPoolMoveToFront
    threadPoolMoveToFront                   ,


-- ** threadPoolPush
    threadPoolPush                          ,


-- ** threadPoolSetMaxThreads
    threadPoolSetMaxThreads                 ,


-- ** threadPoolUnprocessed
    threadPoolUnprocessed                   ,




 -- * Properties
-- ** Exclusive
    threadPoolReadExclusive                 ,


-- ** UserData
    threadPoolReadUserData                  ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.GLib.Types
import GI.GLib.Callbacks

newtype ThreadPool = ThreadPool (ForeignPtr ThreadPool)
noThreadPool :: Maybe ThreadPool
noThreadPool = Nothing

-- XXX Skipped getter for "ThreadPool:func" :: Not implemented: "Wrapping foreign callbacks is not supported yet"

threadPoolReadUserData :: ThreadPool -> IO (Ptr ())
threadPoolReadUserData s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO (Ptr ())
    return val

threadPoolReadExclusive :: ThreadPool -> IO Bool
threadPoolReadExclusive s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 16) :: IO CInt
    let val' = (/= 0) val
    return val'

-- method ThreadPool::free
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "ThreadPool", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "immediate", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "wait_", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "ThreadPool", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "immediate", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "wait_", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_thread_pool_free" g_thread_pool_free :: 
    Ptr ThreadPool ->                       -- _obj : TInterface "GLib" "ThreadPool"
    CInt ->                                 -- immediate : TBasicType TBoolean
    CInt ->                                 -- wait_ : TBasicType TBoolean
    IO ()


threadPoolFree ::
    (MonadIO m) =>
    ThreadPool ->                           -- _obj
    Bool ->                                 -- immediate
    Bool ->                                 -- wait_
    m ()
threadPoolFree _obj immediate wait_ = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    let immediate' = (fromIntegral . fromEnum) immediate
    let wait_' = (fromIntegral . fromEnum) wait_
    g_thread_pool_free _obj' immediate' wait_'
    touchManagedPtr _obj
    return ()

-- method ThreadPool::get_max_threads
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "ThreadPool", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "ThreadPool", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TInt32
-- throws : False
-- Skip return : False

foreign import ccall "g_thread_pool_get_max_threads" g_thread_pool_get_max_threads :: 
    Ptr ThreadPool ->                       -- _obj : TInterface "GLib" "ThreadPool"
    IO Int32


threadPoolGetMaxThreads ::
    (MonadIO m) =>
    ThreadPool ->                           -- _obj
    m Int32
threadPoolGetMaxThreads _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- g_thread_pool_get_max_threads _obj'
    touchManagedPtr _obj
    return result

-- method ThreadPool::get_num_threads
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "ThreadPool", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "ThreadPool", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUInt32
-- throws : False
-- Skip return : False

foreign import ccall "g_thread_pool_get_num_threads" g_thread_pool_get_num_threads :: 
    Ptr ThreadPool ->                       -- _obj : TInterface "GLib" "ThreadPool"
    IO Word32


threadPoolGetNumThreads ::
    (MonadIO m) =>
    ThreadPool ->                           -- _obj
    m Word32
threadPoolGetNumThreads _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- g_thread_pool_get_num_threads _obj'
    touchManagedPtr _obj
    return result

-- method ThreadPool::move_to_front
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "ThreadPool", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "data", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "ThreadPool", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "data", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False

foreign import ccall "g_thread_pool_move_to_front" g_thread_pool_move_to_front :: 
    Ptr ThreadPool ->                       -- _obj : TInterface "GLib" "ThreadPool"
    Ptr () ->                               -- data : TBasicType TVoid
    IO CInt


threadPoolMoveToFront ::
    (MonadIO m) =>
    ThreadPool ->                           -- _obj
    Ptr () ->                               -- data
    m Bool
threadPoolMoveToFront _obj data_ = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- g_thread_pool_move_to_front _obj' data_
    let result' = (/= 0) result
    touchManagedPtr _obj
    return result'

-- method ThreadPool::push
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "ThreadPool", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "data", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "ThreadPool", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "data", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : True
-- Skip return : False

foreign import ccall "g_thread_pool_push" g_thread_pool_push :: 
    Ptr ThreadPool ->                       -- _obj : TInterface "GLib" "ThreadPool"
    Ptr () ->                               -- data : TBasicType TVoid
    Ptr (Ptr GError) ->                     -- error
    IO CInt


threadPoolPush ::
    (MonadIO m) =>
    ThreadPool ->                           -- _obj
    Ptr () ->                               -- data
    m ()
threadPoolPush _obj data_ = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    onException (do
        _ <- propagateGError $ g_thread_pool_push _obj' data_
        touchManagedPtr _obj
        return ()
     ) (do
        return ()
     )

-- method ThreadPool::set_max_threads
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "ThreadPool", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "max_threads", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "ThreadPool", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "max_threads", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : True
-- Skip return : False

foreign import ccall "g_thread_pool_set_max_threads" g_thread_pool_set_max_threads :: 
    Ptr ThreadPool ->                       -- _obj : TInterface "GLib" "ThreadPool"
    Int32 ->                                -- max_threads : TBasicType TInt32
    Ptr (Ptr GError) ->                     -- error
    IO CInt


threadPoolSetMaxThreads ::
    (MonadIO m) =>
    ThreadPool ->                           -- _obj
    Int32 ->                                -- max_threads
    m ()
threadPoolSetMaxThreads _obj max_threads = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    onException (do
        _ <- propagateGError $ g_thread_pool_set_max_threads _obj' max_threads
        touchManagedPtr _obj
        return ()
     ) (do
        return ()
     )

-- method ThreadPool::unprocessed
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "ThreadPool", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "ThreadPool", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUInt32
-- throws : False
-- Skip return : False

foreign import ccall "g_thread_pool_unprocessed" g_thread_pool_unprocessed :: 
    Ptr ThreadPool ->                       -- _obj : TInterface "GLib" "ThreadPool"
    IO Word32


threadPoolUnprocessed ::
    (MonadIO m) =>
    ThreadPool ->                           -- _obj
    m Word32
threadPoolUnprocessed _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- g_thread_pool_unprocessed _obj'
    touchManagedPtr _obj
    return result