{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- A structure representing a log topic.

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

module GI.Wp.Structs.LogTopic
    ( 

-- * Exported types
    LogTopic(..)                            ,
    newZeroLogTopic                         ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [init]("GI.Wp.Structs.LogTopic#g:method:init"), [register]("GI.Wp.Structs.LogTopic#g:method:register"), [unregister]("GI.Wp.Structs.LogTopic#g:method:unregister").
-- 
-- ==== Getters
-- /None/.
-- 
-- ==== Setters
-- /None/.

#if defined(ENABLE_OVERLOADING)
    ResolveLogTopicMethod                   ,
#endif

-- ** init #method:init#

#if defined(ENABLE_OVERLOADING)
    LogTopicInitMethodInfo                  ,
#endif
    logTopicInit                            ,


-- ** register #method:register#

#if defined(ENABLE_OVERLOADING)
    LogTopicRegisterMethodInfo              ,
#endif
    logTopicRegister                        ,


-- ** unregister #method:unregister#

#if defined(ENABLE_OVERLOADING)
    LogTopicUnregisterMethodInfo            ,
#endif
    logTopicUnregister                      ,




 -- * Properties


-- ** flags #attr:flags#
-- | /No description available in the introspection data./

    getLogTopicFlags                        ,
#if defined(ENABLE_OVERLOADING)
    logTopic_flags                          ,
#endif
    setLogTopicFlags                        ,


-- ** topicName #attr:topicName#
-- | /No description available in the introspection data./

    clearLogTopicTopicName                  ,
    getLogTopicTopicName                    ,
#if defined(ENABLE_OVERLOADING)
    logTopic_topicName                      ,
#endif
    setLogTopicTopicName                    ,




    ) 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.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GArray as B.GArray
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GHashTable as B.GHT
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 Control.Monad.IO.Class as MIO
import qualified Data.Coerce as Coerce
import qualified Data.Text as T
import qualified Data.Kind as DK
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 GHC.Records as R
import qualified Data.Word as DW
import qualified Data.Int as DI
import qualified System.Posix.Types as SPT
import qualified Foreign.C.Types as FCT

-- Workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/23392
#if MIN_VERSION_base(4,18,0)
import {-# SOURCE #-} qualified GI.Wp.Flags as Wp.Flags

#else
import {-# SOURCE #-} qualified GI.Wp.Flags as Wp.Flags

#endif

-- | Memory-managed wrapper type.
newtype LogTopic = LogTopic (SP.ManagedPtr LogTopic)
    deriving (Eq)

instance SP.ManagedPtrNewtype LogTopic where
    toManagedPtr (LogTopic p) = p

instance BoxedPtr LogTopic where
    boxedPtrCopy = \p -> B.ManagedPtr.withManagedPtr p (copyBytes 40 >=> B.ManagedPtr.wrapPtr LogTopic)
    boxedPtrFree = \x -> SP.withManagedPtr x SP.freeMem
instance CallocPtr LogTopic where
    boxedPtrCalloc = callocBytes 40


-- | Construct a t'LogTopic' struct initialized to zero.
newZeroLogTopic :: MonadIO m => m LogTopic
newZeroLogTopic = liftIO $ boxedPtrCalloc >>= wrapPtr LogTopic

instance tag ~ 'AttrSet => Constructible LogTopic tag where
    new _ attrs = do
        o <- newZeroLogTopic
        GI.Attributes.set o attrs
        return o


-- | Get the value of the “@topic_name@” field.
-- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
-- 
-- @
-- 'Data.GI.Base.Attributes.get' logTopic #topicName
-- @
getLogTopicTopicName :: MonadIO m => LogTopic -> m (Maybe T.Text)
getLogTopicTopicName s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO CString
    result <- SP.convertIfNonNull val $ \val' -> do
        val'' <- cstringToText val'
        return val''
    return result

-- | Set the value of the “@topic_name@” field.
-- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
-- 
-- @
-- 'Data.GI.Base.Attributes.set' logTopic [ #topicName 'Data.GI.Base.Attributes.:=' value ]
-- @
setLogTopicTopicName :: MonadIO m => LogTopic -> CString -> m ()
setLogTopicTopicName s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (val :: CString)

-- | Set the value of the “@topic_name@” field to `Nothing`.
-- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
-- 
-- @
-- 'Data.GI.Base.Attributes.clear' #topicName
-- @
clearLogTopicTopicName :: MonadIO m => LogTopic -> m ()
clearLogTopicTopicName s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (FP.nullPtr :: CString)

#if defined(ENABLE_OVERLOADING)
data LogTopicTopicNameFieldInfo
instance AttrInfo LogTopicTopicNameFieldInfo where
    type AttrBaseTypeConstraint LogTopicTopicNameFieldInfo = (~) LogTopic
    type AttrAllowedOps LogTopicTopicNameFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint LogTopicTopicNameFieldInfo = (~) CString
    type AttrTransferTypeConstraint LogTopicTopicNameFieldInfo = (~)CString
    type AttrTransferType LogTopicTopicNameFieldInfo = CString
    type AttrGetType LogTopicTopicNameFieldInfo = Maybe T.Text
    type AttrLabel LogTopicTopicNameFieldInfo = "topic_name"
    type AttrOrigin LogTopicTopicNameFieldInfo = LogTopic
    attrGet = getLogTopicTopicName
    attrSet = setLogTopicTopicName
    attrConstruct = undefined
    attrClear = clearLogTopicTopicName
    attrTransfer _ v = do
        return v
    dbgAttrInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Wp.Structs.LogTopic.topicName"
        , O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-wireplumber-0.5.14.2/docs/GI-Wp-Structs-LogTopic.html#g:attr:topicName"
        })

logTopic_topicName :: AttrLabelProxy "topicName"
logTopic_topicName = AttrLabelProxy

#endif


-- | Get the value of the “@flags@” field.
-- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
-- 
-- @
-- 'Data.GI.Base.Attributes.get' logTopic #flags
-- @
getLogTopicFlags :: MonadIO m => LogTopic -> m [Wp.Flags.LogTopicFlags]
getLogTopicFlags s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO CUInt
    let val' = wordToGFlags val
    return val'

-- | Set the value of the “@flags@” field.
-- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
-- 
-- @
-- 'Data.GI.Base.Attributes.set' logTopic [ #flags 'Data.GI.Base.Attributes.:=' value ]
-- @
setLogTopicFlags :: MonadIO m => LogTopic -> [Wp.Flags.LogTopicFlags] -> m ()
setLogTopicFlags s val = liftIO $ withManagedPtr s $ \ptr -> do
    let val' = gflagsToWord val
    poke (ptr `plusPtr` 8) (val' :: CUInt)

#if defined(ENABLE_OVERLOADING)
data LogTopicFlagsFieldInfo
instance AttrInfo LogTopicFlagsFieldInfo where
    type AttrBaseTypeConstraint LogTopicFlagsFieldInfo = (~) LogTopic
    type AttrAllowedOps LogTopicFlagsFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint LogTopicFlagsFieldInfo = (~) [Wp.Flags.LogTopicFlags]
    type AttrTransferTypeConstraint LogTopicFlagsFieldInfo = (~)[Wp.Flags.LogTopicFlags]
    type AttrTransferType LogTopicFlagsFieldInfo = [Wp.Flags.LogTopicFlags]
    type AttrGetType LogTopicFlagsFieldInfo = [Wp.Flags.LogTopicFlags]
    type AttrLabel LogTopicFlagsFieldInfo = "flags"
    type AttrOrigin LogTopicFlagsFieldInfo = LogTopic
    attrGet = getLogTopicFlags
    attrSet = setLogTopicFlags
    attrConstruct = undefined
    attrClear = undefined
    attrTransfer _ v = do
        return v
    dbgAttrInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Wp.Structs.LogTopic.flags"
        , O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-wireplumber-0.5.14.2/docs/GI-Wp-Structs-LogTopic.html#g:attr:flags"
        })

logTopic_flags :: AttrLabelProxy "flags"
logTopic_flags = AttrLabelProxy

#endif



#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList LogTopic
type instance O.AttributeList LogTopic = LogTopicAttributeList
type LogTopicAttributeList = ('[ '("topicName", LogTopicTopicNameFieldInfo), '("flags", LogTopicFlagsFieldInfo)] :: [(Symbol, DK.Type)])
#endif

-- method LogTopic::init
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "topic"
--           , argType =
--               TInterface Name { namespace = "Wp" , name = "LogTopic" }
--           , argCType = Just "WpLogTopic*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation { rawDocText = Nothing , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "wp_log_topic_init" wp_log_topic_init :: 
    Ptr LogTopic ->                         -- topic : TInterface (Name {namespace = "Wp", name = "LogTopic"})
    IO ()

-- | Initializes a log topic. Internal function, don\'t use it directly.
logTopicInit ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    LogTopic
    -> m ()
logTopicInit topic = liftIO $ do
    topic' <- unsafeManagedPtrGetPtr topic
    wp_log_topic_init topic'
    touchManagedPtr topic
    return ()

#if defined(ENABLE_OVERLOADING)
data LogTopicInitMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.OverloadedMethod LogTopicInitMethodInfo LogTopic signature where
    overloadedMethod = logTopicInit

instance O.OverloadedMethodInfo LogTopicInitMethodInfo LogTopic where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Wp.Structs.LogTopic.logTopicInit",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-wireplumber-0.5.14.2/docs/GI-Wp-Structs-LogTopic.html#v:logTopicInit"
        })


#endif

-- method LogTopic::register
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "topic"
--           , argType =
--               TInterface Name { namespace = "Wp" , name = "LogTopic" }
--           , argCType = Just "WpLogTopic*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation { rawDocText = Nothing , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "wp_log_topic_register" wp_log_topic_register :: 
    Ptr LogTopic ->                         -- topic : TInterface (Name {namespace = "Wp", name = "LogTopic"})
    IO ()

-- | Registers a log topic.
-- 
-- 
-- The log topic must be unregistered using wp_log_topic_unregister before its lifetime ends.
-- This function is threadsafe.
logTopicRegister ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    LogTopic
    -> m ()
logTopicRegister topic = liftIO $ do
    topic' <- unsafeManagedPtrGetPtr topic
    wp_log_topic_register topic'
    touchManagedPtr topic
    return ()

#if defined(ENABLE_OVERLOADING)
data LogTopicRegisterMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.OverloadedMethod LogTopicRegisterMethodInfo LogTopic signature where
    overloadedMethod = logTopicRegister

instance O.OverloadedMethodInfo LogTopicRegisterMethodInfo LogTopic where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Wp.Structs.LogTopic.logTopicRegister",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-wireplumber-0.5.14.2/docs/GI-Wp-Structs-LogTopic.html#v:logTopicRegister"
        })


#endif

-- method LogTopic::unregister
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "topic"
--           , argType =
--               TInterface Name { namespace = "Wp" , name = "LogTopic" }
--           , argCType = Just "WpLogTopic*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation { rawDocText = Nothing , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "wp_log_topic_unregister" wp_log_topic_unregister :: 
    Ptr LogTopic ->                         -- topic : TInterface (Name {namespace = "Wp", name = "LogTopic"})
    IO ()

-- | Unregisters a log topic.
-- 
-- 
-- This function is threadsafe.
logTopicUnregister ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    LogTopic
    -> m ()
logTopicUnregister topic = liftIO $ do
    topic' <- unsafeManagedPtrGetPtr topic
    wp_log_topic_unregister topic'
    touchManagedPtr topic
    return ()

#if defined(ENABLE_OVERLOADING)
data LogTopicUnregisterMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.OverloadedMethod LogTopicUnregisterMethodInfo LogTopic signature where
    overloadedMethod = logTopicUnregister

instance O.OverloadedMethodInfo LogTopicUnregisterMethodInfo LogTopic where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Wp.Structs.LogTopic.logTopicUnregister",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-wireplumber-0.5.14.2/docs/GI-Wp-Structs-LogTopic.html#v:logTopicUnregister"
        })


#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveLogTopicMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
    ResolveLogTopicMethod "init" o = LogTopicInitMethodInfo
    ResolveLogTopicMethod "register" o = LogTopicRegisterMethodInfo
    ResolveLogTopicMethod "unregister" o = LogTopicUnregisterMethodInfo
    ResolveLogTopicMethod l o = O.MethodResolutionFailed l o

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

#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolveLogTopicMethod t LogTopic, O.OverloadedMethod info LogTopic p, R.HasField t LogTopic p) => R.HasField t LogTopic p where
    getField = O.overloadedMethod @info

#endif

instance (info ~ ResolveLogTopicMethod t LogTopic, O.OverloadedMethodInfo info LogTopic) => OL.IsLabel t (O.MethodProxy info LogTopic) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.MethodProxy
#else
    fromLabel _ = O.MethodProxy
#endif

#endif


