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

Struct used in 'GI.Gio.Functions.dbusErrorRegisterErrorDomain'.

/Since: 2.26/
-}

#define ENABLE_OVERLOADING \
       (!defined(__HADDOCK_VERSION__))

module GI.Gio.Structs.DBusErrorEntry
    ( 

-- * Exported types
    DBusErrorEntry(..)                      ,
    newZeroDBusErrorEntry                   ,
    noDBusErrorEntry                        ,


 -- * Properties
-- ** dbusErrorName #attr:dbusErrorName#
{- | The D-Bus error name to associate with /@errorCode@/.
-}
    clearDBusErrorEntryDbusErrorName        ,
#if ENABLE_OVERLOADING
    dBusErrorEntry_dbusErrorName            ,
#endif
    getDBusErrorEntryDbusErrorName          ,
    setDBusErrorEntryDbusErrorName          ,


-- ** errorCode #attr:errorCode#
{- | An error code.
-}
#if ENABLE_OVERLOADING
    dBusErrorEntry_errorCode                ,
#endif
    getDBusErrorEntryErrorCode              ,
    setDBusErrorEntryErrorCode              ,




    ) 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.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.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP


-- | Memory-managed wrapper type.
newtype DBusErrorEntry = DBusErrorEntry (ManagedPtr DBusErrorEntry)
instance WrappedPtr DBusErrorEntry where
    wrappedPtrCalloc :: IO (Ptr DBusErrorEntry)
wrappedPtrCalloc = Int -> IO (Ptr DBusErrorEntry)
forall a. Int -> IO (Ptr a)
callocBytes 16
    wrappedPtrCopy :: DBusErrorEntry -> IO DBusErrorEntry
wrappedPtrCopy = \p :: DBusErrorEntry
p -> DBusErrorEntry
-> (Ptr DBusErrorEntry -> IO DBusErrorEntry) -> IO DBusErrorEntry
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr DBusErrorEntry
p (Int -> Ptr DBusErrorEntry -> IO (Ptr DBusErrorEntry)
forall a. WrappedPtr a => Int -> Ptr a -> IO (Ptr a)
copyBytes 16 (Ptr DBusErrorEntry -> IO (Ptr DBusErrorEntry))
-> (Ptr DBusErrorEntry -> IO DBusErrorEntry)
-> Ptr DBusErrorEntry
-> IO DBusErrorEntry
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> (ManagedPtr DBusErrorEntry -> DBusErrorEntry)
-> Ptr DBusErrorEntry -> IO DBusErrorEntry
forall a.
(HasCallStack, WrappedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr DBusErrorEntry -> DBusErrorEntry
DBusErrorEntry)
    wrappedPtrFree :: Maybe (FunPtr (Ptr DBusErrorEntry -> IO ()))
wrappedPtrFree = FunPtr (Ptr DBusErrorEntry -> IO ())
-> Maybe (FunPtr (Ptr DBusErrorEntry -> IO ()))
forall a. a -> Maybe a
Just FunPtr (Ptr DBusErrorEntry -> IO ())
forall a. FunPtr (Ptr a -> IO ())
ptr_to_g_free

-- | Construct a `DBusErrorEntry` struct initialized to zero.
newZeroDBusErrorEntry :: MonadIO m => m DBusErrorEntry
newZeroDBusErrorEntry :: m DBusErrorEntry
newZeroDBusErrorEntry = IO DBusErrorEntry -> m DBusErrorEntry
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO DBusErrorEntry -> m DBusErrorEntry)
-> IO DBusErrorEntry -> m DBusErrorEntry
forall a b. (a -> b) -> a -> b
$ IO (Ptr DBusErrorEntry)
forall a. WrappedPtr a => IO (Ptr a)
wrappedPtrCalloc IO (Ptr DBusErrorEntry)
-> (Ptr DBusErrorEntry -> IO DBusErrorEntry) -> IO DBusErrorEntry
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ManagedPtr DBusErrorEntry -> DBusErrorEntry)
-> Ptr DBusErrorEntry -> IO DBusErrorEntry
forall a.
(HasCallStack, WrappedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr DBusErrorEntry -> DBusErrorEntry
DBusErrorEntry

instance tag ~ 'AttrSet => Constructible DBusErrorEntry tag where
    new :: (ManagedPtr DBusErrorEntry -> DBusErrorEntry)
-> [AttrOp DBusErrorEntry tag] -> m DBusErrorEntry
new _ attrs :: [AttrOp DBusErrorEntry tag]
attrs = do
        DBusErrorEntry
o <- m DBusErrorEntry
forall (m :: * -> *). MonadIO m => m DBusErrorEntry
newZeroDBusErrorEntry
        DBusErrorEntry -> [AttrOp DBusErrorEntry 'AttrSet] -> m ()
forall o (m :: * -> *).
MonadIO m =>
o -> [AttrOp o 'AttrSet] -> m ()
GI.Attributes.set DBusErrorEntry
o [AttrOp DBusErrorEntry tag]
[AttrOp DBusErrorEntry 'AttrSet]
attrs
        DBusErrorEntry -> m DBusErrorEntry
forall (m :: * -> *) a. Monad m => a -> m a
return DBusErrorEntry
o


-- | A convenience alias for `Nothing` :: `Maybe` `DBusErrorEntry`.
noDBusErrorEntry :: Maybe DBusErrorEntry
noDBusErrorEntry :: Maybe DBusErrorEntry
noDBusErrorEntry = Maybe DBusErrorEntry
forall a. Maybe a
Nothing

{- |
Get the value of the “@error_code@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' dBusErrorEntry #errorCode
@
-}
getDBusErrorEntryErrorCode :: MonadIO m => DBusErrorEntry -> m Int32
getDBusErrorEntryErrorCode :: DBusErrorEntry -> m Int32
getDBusErrorEntryErrorCode s :: DBusErrorEntry
s = 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
$ DBusErrorEntry -> (Ptr DBusErrorEntry -> IO Int32) -> IO Int32
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr DBusErrorEntry
s ((Ptr DBusErrorEntry -> IO Int32) -> IO Int32)
-> (Ptr DBusErrorEntry -> IO Int32) -> IO Int32
forall a b. (a -> b) -> a -> b
$ \ptr :: Ptr DBusErrorEntry
ptr -> do
    Int32
val <- Ptr Int32 -> IO Int32
forall a. Storable a => Ptr a -> IO a
peek (Ptr DBusErrorEntry
ptr Ptr DBusErrorEntry -> Int -> Ptr Int32
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0) :: IO Int32
    Int32 -> IO Int32
forall (m :: * -> *) a. Monad m => a -> m a
return Int32
val

{- |
Set the value of the “@error_code@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' dBusErrorEntry [ #errorCode 'Data.GI.Base.Attributes.:=' value ]
@
-}
setDBusErrorEntryErrorCode :: MonadIO m => DBusErrorEntry -> Int32 -> m ()
setDBusErrorEntryErrorCode :: DBusErrorEntry -> Int32 -> m ()
setDBusErrorEntryErrorCode s :: DBusErrorEntry
s val :: Int32
val = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ DBusErrorEntry -> (Ptr DBusErrorEntry -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr DBusErrorEntry
s ((Ptr DBusErrorEntry -> IO ()) -> IO ())
-> (Ptr DBusErrorEntry -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ptr :: Ptr DBusErrorEntry
ptr -> do
    Ptr Int32 -> Int32 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr DBusErrorEntry
ptr Ptr DBusErrorEntry -> Int -> Ptr Int32
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0) (Int32
val :: Int32)

#if ENABLE_OVERLOADING
data DBusErrorEntryErrorCodeFieldInfo
instance AttrInfo DBusErrorEntryErrorCodeFieldInfo where
    type AttrAllowedOps DBusErrorEntryErrorCodeFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint DBusErrorEntryErrorCodeFieldInfo = (~) Int32
    type AttrBaseTypeConstraint DBusErrorEntryErrorCodeFieldInfo = (~) DBusErrorEntry
    type AttrGetType DBusErrorEntryErrorCodeFieldInfo = Int32
    type AttrLabel DBusErrorEntryErrorCodeFieldInfo = "error_code"
    type AttrOrigin DBusErrorEntryErrorCodeFieldInfo = DBusErrorEntry
    attrGet _ = getDBusErrorEntryErrorCode
    attrSet _ = setDBusErrorEntryErrorCode
    attrConstruct = undefined
    attrClear _ = undefined

dBusErrorEntry_errorCode :: AttrLabelProxy "errorCode"
dBusErrorEntry_errorCode = AttrLabelProxy

#endif


{- |
Get the value of the “@dbus_error_name@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' dBusErrorEntry #dbusErrorName
@
-}
getDBusErrorEntryDbusErrorName :: MonadIO m => DBusErrorEntry -> m (Maybe T.Text)
getDBusErrorEntryDbusErrorName :: DBusErrorEntry -> m (Maybe Text)
getDBusErrorEntryDbusErrorName s :: DBusErrorEntry
s = IO (Maybe Text) -> m (Maybe Text)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Text) -> m (Maybe Text))
-> IO (Maybe Text) -> m (Maybe Text)
forall a b. (a -> b) -> a -> b
$ DBusErrorEntry
-> (Ptr DBusErrorEntry -> IO (Maybe Text)) -> IO (Maybe Text)
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr DBusErrorEntry
s ((Ptr DBusErrorEntry -> IO (Maybe Text)) -> IO (Maybe Text))
-> (Ptr DBusErrorEntry -> IO (Maybe Text)) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \ptr :: Ptr DBusErrorEntry
ptr -> do
    CString
val <- Ptr CString -> IO CString
forall a. Storable a => Ptr a -> IO a
peek (Ptr DBusErrorEntry
ptr Ptr DBusErrorEntry -> Int -> Ptr CString
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8) :: IO CString
    Maybe Text
result <- CString -> (CString -> IO Text) -> IO (Maybe Text)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
SP.convertIfNonNull CString
val ((CString -> IO Text) -> IO (Maybe Text))
-> (CString -> IO Text) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \val' :: CString
val' -> do
        Text
val'' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
val'
        Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
val''
    Maybe Text -> IO (Maybe Text)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Text
result

{- |
Set the value of the “@dbus_error_name@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' dBusErrorEntry [ #dbusErrorName 'Data.GI.Base.Attributes.:=' value ]
@
-}
setDBusErrorEntryDbusErrorName :: MonadIO m => DBusErrorEntry -> CString -> m ()
setDBusErrorEntryDbusErrorName :: DBusErrorEntry -> CString -> m ()
setDBusErrorEntryDbusErrorName s :: DBusErrorEntry
s val :: CString
val = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ DBusErrorEntry -> (Ptr DBusErrorEntry -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr DBusErrorEntry
s ((Ptr DBusErrorEntry -> IO ()) -> IO ())
-> (Ptr DBusErrorEntry -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ptr :: Ptr DBusErrorEntry
ptr -> do
    Ptr CString -> CString -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr DBusErrorEntry
ptr Ptr DBusErrorEntry -> Int -> Ptr CString
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8) (CString
val :: CString)

{- |
Set the value of the “@dbus_error_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' #dbusErrorName
@
-}
clearDBusErrorEntryDbusErrorName :: MonadIO m => DBusErrorEntry -> m ()
clearDBusErrorEntryDbusErrorName :: DBusErrorEntry -> m ()
clearDBusErrorEntryDbusErrorName s :: DBusErrorEntry
s = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ DBusErrorEntry -> (Ptr DBusErrorEntry -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr DBusErrorEntry
s ((Ptr DBusErrorEntry -> IO ()) -> IO ())
-> (Ptr DBusErrorEntry -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ptr :: Ptr DBusErrorEntry
ptr -> do
    Ptr CString -> CString -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr DBusErrorEntry
ptr Ptr DBusErrorEntry -> Int -> Ptr CString
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8) (CString
forall a. Ptr a
FP.nullPtr :: CString)

#if ENABLE_OVERLOADING
data DBusErrorEntryDbusErrorNameFieldInfo
instance AttrInfo DBusErrorEntryDbusErrorNameFieldInfo where
    type AttrAllowedOps DBusErrorEntryDbusErrorNameFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint DBusErrorEntryDbusErrorNameFieldInfo = (~) CString
    type AttrBaseTypeConstraint DBusErrorEntryDbusErrorNameFieldInfo = (~) DBusErrorEntry
    type AttrGetType DBusErrorEntryDbusErrorNameFieldInfo = Maybe T.Text
    type AttrLabel DBusErrorEntryDbusErrorNameFieldInfo = "dbus_error_name"
    type AttrOrigin DBusErrorEntryDbusErrorNameFieldInfo = DBusErrorEntry
    attrGet _ = getDBusErrorEntryDbusErrorName
    attrSet _ = setDBusErrorEntryDbusErrorName
    attrConstruct = undefined
    attrClear _ = clearDBusErrorEntryDbusErrorName

dBusErrorEntry_dbusErrorName :: AttrLabelProxy "dbusErrorName"
dBusErrorEntry_dbusErrorName = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList DBusErrorEntry
type instance O.AttributeList DBusErrorEntry = DBusErrorEntryAttributeList
type DBusErrorEntryAttributeList = ('[ '("errorCode", DBusErrorEntryErrorCodeFieldInfo), '("dbusErrorName", DBusErrorEntryDbusErrorNameFieldInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
type family ResolveDBusErrorEntryMethod (t :: Symbol) (o :: *) :: * where
    ResolveDBusErrorEntryMethod l o = O.MethodResolutionFailed l o

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

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

#endif