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

    Structure used for scatter\/gather data output when sending multiple
    messages or packets in one go. You generally pass in an array of
    @/GOutputVectors/@ and the operation will use all the buffers as if they
    were one buffer.

    If /@address@/ is 'Nothing' then the message is sent to the default receiver
    (as previously set by 'GI.Gio.Objects.Socket.socketConnect').

    /Since: 2.44/
    -}

    #define ENABLE_OVERLOADING \
           (!defined(__HADDOCK_VERSION__))

    module GI.Gio.Structs.OutputMessage
        (

    -- * Exported types
        OutputMessage(..)                       ,
        newZeroOutputMessage                    ,
        noOutputMessage                         ,

     -- * Properties
    -- ** address #attr:address#
    {- | a 'GI.Gio.Objects.SocketAddress.SocketAddress', or 'Nothing'
    -}
        clearOutputMessageAddress               ,
        getOutputMessageAddress                 ,
    #if ENABLE_OVERLOADING
        outputMessage_address                   ,
    #endif
        setOutputMessageAddress                 ,

    -- ** bytesSent #attr:bytesSent#
    {- | initialize to 0. Will be set to the number of bytes
        that have been sent
    -}
        getOutputMessageBytesSent               ,
    #if ENABLE_OVERLOADING
        outputMessage_bytesSent                 ,
    #endif
        setOutputMessageBytesSent               ,

    -- ** numControlMessages #attr:numControlMessages#
    {- | number of elements in /@controlMessages@/.
    -}
        getOutputMessageNumControlMessages      ,
    #if ENABLE_OVERLOADING
        outputMessage_numControlMessages        ,
    #endif
        setOutputMessageNumControlMessages      ,

    -- ** numVectors #attr:numVectors#
    {- | the number of output vectors pointed to by /@vectors@/.
    -}
        getOutputMessageNumVectors              ,
    #if ENABLE_OVERLOADING
        outputMessage_numVectors                ,
    #endif
        setOutputMessageNumVectors              ,

    -- ** vectors #attr:vectors#
    {- | pointer to an array of output vectors
    -}
        clearOutputMessageVectors               ,
        getOutputMessageVectors                 ,
    #if ENABLE_OVERLOADING
        outputMessage_vectors                   ,
    #endif
        setOutputMessageVectors                 ,

        ) 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

    import {-# SOURCE #-} qualified GI.Gio.Objects.SocketAddress as Gio.SocketAddress
    import {-# SOURCE #-} qualified GI.Gio.Structs.OutputVector as Gio.OutputVector

    -- | Memory-managed wrapper type.
    newtype OutputMessage = OutputMessage (ManagedPtr OutputMessage)
    instance WrappedPtr OutputMessage where
        wrappedPtrCalloc = callocBytes 40
        wrappedPtrCopy = \p -> withManagedPtr p (copyBytes 40 >=> wrapPtr OutputMessage)
        wrappedPtrFree = Just ptr_to_g_free

    -- | Construct a `OutputMessage` struct initialized to zero.
    newZeroOutputMessage :: MonadIO m => m OutputMessage
    newZeroOutputMessage = liftIO $ wrappedPtrCalloc >>= wrapPtr OutputMessage

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

    -- | A convenience alias for `Nothing` :: `Maybe` `OutputMessage`.
    noOutputMessage :: Maybe OutputMessage
    noOutputMessage = Nothing

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

    @
    'Data.GI.Base.Attributes.get' outputMessage #address
    @
    -}
    getOutputMessageAddress :: MonadIO m => OutputMessage -> m (Maybe Gio.SocketAddress.SocketAddress)
    getOutputMessageAddress s = liftIO $ withManagedPtr s $ \ptr -> do
        val <- peek (ptr `plusPtr` 0) :: IO (Ptr Gio.SocketAddress.SocketAddress)
        result <- SP.convertIfNonNull val $ \val' -> do
            val'' <- (newObject Gio.SocketAddress.SocketAddress) val'
            return val''
        return result

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

    @
    'Data.GI.Base.Attributes.set' outputMessage [ #address 'Data.GI.Base.Attributes.:=' value ]
    @
    -}
    setOutputMessageAddress :: MonadIO m => OutputMessage -> Ptr Gio.SocketAddress.SocketAddress -> m ()
    setOutputMessageAddress s val = liftIO $ withManagedPtr s $ \ptr -> do
        poke (ptr `plusPtr` 0) (val :: Ptr Gio.SocketAddress.SocketAddress)

    {- |
    Set the value of the “@address@” 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' #address
    @
    -}
    clearOutputMessageAddress :: MonadIO m => OutputMessage -> m ()
    clearOutputMessageAddress s = liftIO $ withManagedPtr s $ \ptr -> do
        poke (ptr `plusPtr` 0) (FP.nullPtr :: Ptr Gio.SocketAddress.SocketAddress)

    #if ENABLE_OVERLOADING
    data OutputMessageAddressFieldInfo
    instance AttrInfo OutputMessageAddressFieldInfo where
        type AttrAllowedOps OutputMessageAddressFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
        type AttrSetTypeConstraint OutputMessageAddressFieldInfo = (~) (Ptr Gio.SocketAddress.SocketAddress)
        type AttrBaseTypeConstraint OutputMessageAddressFieldInfo = (~) OutputMessage
        type AttrGetType OutputMessageAddressFieldInfo = Maybe Gio.SocketAddress.SocketAddress
        type AttrLabel OutputMessageAddressFieldInfo = "address"
        type AttrOrigin OutputMessageAddressFieldInfo = OutputMessage
        attrGet _ = getOutputMessageAddress
        attrSet _ = setOutputMessageAddress
        attrConstruct = undefined
        attrClear _ = clearOutputMessageAddress

    outputMessage_address :: AttrLabelProxy "address"
    outputMessage_address = AttrLabelProxy

    #endif

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

    @
    'Data.GI.Base.Attributes.get' outputMessage #vectors
    @
    -}
    getOutputMessageVectors :: MonadIO m => OutputMessage -> m (Maybe Gio.OutputVector.OutputVector)
    getOutputMessageVectors s = liftIO $ withManagedPtr s $ \ptr -> do
        val <- peek (ptr `plusPtr` 8) :: IO (Ptr Gio.OutputVector.OutputVector)
        result <- SP.convertIfNonNull val $ \val' -> do
            val'' <- (newPtr Gio.OutputVector.OutputVector) val'
            return val''
        return result

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

    @
    'Data.GI.Base.Attributes.set' outputMessage [ #vectors 'Data.GI.Base.Attributes.:=' value ]
    @
    -}
    setOutputMessageVectors :: MonadIO m => OutputMessage -> Ptr Gio.OutputVector.OutputVector -> m ()
    setOutputMessageVectors s val = liftIO $ withManagedPtr s $ \ptr -> do
        poke (ptr `plusPtr` 8) (val :: Ptr Gio.OutputVector.OutputVector)

    {- |
    Set the value of the “@vectors@” 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' #vectors
    @
    -}
    clearOutputMessageVectors :: MonadIO m => OutputMessage -> m ()
    clearOutputMessageVectors s = liftIO $ withManagedPtr s $ \ptr -> do
        poke (ptr `plusPtr` 8) (FP.nullPtr :: Ptr Gio.OutputVector.OutputVector)

    #if ENABLE_OVERLOADING
    data OutputMessageVectorsFieldInfo
    instance AttrInfo OutputMessageVectorsFieldInfo where
        type AttrAllowedOps OutputMessageVectorsFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
        type AttrSetTypeConstraint OutputMessageVectorsFieldInfo = (~) (Ptr Gio.OutputVector.OutputVector)
        type AttrBaseTypeConstraint OutputMessageVectorsFieldInfo = (~) OutputMessage
        type AttrGetType OutputMessageVectorsFieldInfo = Maybe Gio.OutputVector.OutputVector
        type AttrLabel OutputMessageVectorsFieldInfo = "vectors"
        type AttrOrigin OutputMessageVectorsFieldInfo = OutputMessage
        attrGet _ = getOutputMessageVectors
        attrSet _ = setOutputMessageVectors
        attrConstruct = undefined
        attrClear _ = clearOutputMessageVectors

    outputMessage_vectors :: AttrLabelProxy "vectors"
    outputMessage_vectors = AttrLabelProxy

    #endif

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

    @
    'Data.GI.Base.Attributes.get' outputMessage #numVectors
    @
    -}
    getOutputMessageNumVectors :: MonadIO m => OutputMessage -> m Word32
    getOutputMessageNumVectors s = liftIO $ withManagedPtr s $ \ptr -> do
        val <- peek (ptr `plusPtr` 16) :: IO Word32
        return val

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

    @
    'Data.GI.Base.Attributes.set' outputMessage [ #numVectors 'Data.GI.Base.Attributes.:=' value ]
    @
    -}
    setOutputMessageNumVectors :: MonadIO m => OutputMessage -> Word32 -> m ()
    setOutputMessageNumVectors s val = liftIO $ withManagedPtr s $ \ptr -> do
        poke (ptr `plusPtr` 16) (val :: Word32)

    #if ENABLE_OVERLOADING
    data OutputMessageNumVectorsFieldInfo
    instance AttrInfo OutputMessageNumVectorsFieldInfo where
        type AttrAllowedOps OutputMessageNumVectorsFieldInfo = '[ 'AttrSet, 'AttrGet]
        type AttrSetTypeConstraint OutputMessageNumVectorsFieldInfo = (~) Word32
        type AttrBaseTypeConstraint OutputMessageNumVectorsFieldInfo = (~) OutputMessage
        type AttrGetType OutputMessageNumVectorsFieldInfo = Word32
        type AttrLabel OutputMessageNumVectorsFieldInfo = "num_vectors"
        type AttrOrigin OutputMessageNumVectorsFieldInfo = OutputMessage
        attrGet _ = getOutputMessageNumVectors
        attrSet _ = setOutputMessageNumVectors
        attrConstruct = undefined
        attrClear _ = undefined

    outputMessage_numVectors :: AttrLabelProxy "numVectors"
    outputMessage_numVectors = AttrLabelProxy

    #endif

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

    @
    'Data.GI.Base.Attributes.get' outputMessage #bytesSent
    @
    -}
    getOutputMessageBytesSent :: MonadIO m => OutputMessage -> m Word32
    getOutputMessageBytesSent s = liftIO $ withManagedPtr s $ \ptr -> do
        val <- peek (ptr `plusPtr` 20) :: IO Word32
        return val

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

    @
    'Data.GI.Base.Attributes.set' outputMessage [ #bytesSent 'Data.GI.Base.Attributes.:=' value ]
    @
    -}
    setOutputMessageBytesSent :: MonadIO m => OutputMessage -> Word32 -> m ()
    setOutputMessageBytesSent s val = liftIO $ withManagedPtr s $ \ptr -> do
        poke (ptr `plusPtr` 20) (val :: Word32)

    #if ENABLE_OVERLOADING
    data OutputMessageBytesSentFieldInfo
    instance AttrInfo OutputMessageBytesSentFieldInfo where
        type AttrAllowedOps OutputMessageBytesSentFieldInfo = '[ 'AttrSet, 'AttrGet]
        type AttrSetTypeConstraint OutputMessageBytesSentFieldInfo = (~) Word32
        type AttrBaseTypeConstraint OutputMessageBytesSentFieldInfo = (~) OutputMessage
        type AttrGetType OutputMessageBytesSentFieldInfo = Word32
        type AttrLabel OutputMessageBytesSentFieldInfo = "bytes_sent"
        type AttrOrigin OutputMessageBytesSentFieldInfo = OutputMessage
        attrGet _ = getOutputMessageBytesSent
        attrSet _ = setOutputMessageBytesSent
        attrConstruct = undefined
        attrClear _ = undefined

    outputMessage_bytesSent :: AttrLabelProxy "bytesSent"
    outputMessage_bytesSent = AttrLabelProxy

    #endif

    -- XXX Skipped attribute for "OutputMessage:control_messages" :: Not implemented: "Don't know how to unpack C array of type TCArray False (-1) 5 (TInterface (Name {namespace = \"Gio\", name = \"SocketControlMessage\"}))"
    {- |
    Get the value of the “@num_control_messages@” field.
    When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

    @
    'Data.GI.Base.Attributes.get' outputMessage #numControlMessages
    @
    -}
    getOutputMessageNumControlMessages :: MonadIO m => OutputMessage -> m Word32
    getOutputMessageNumControlMessages s = liftIO $ withManagedPtr s $ \ptr -> do
        val <- peek (ptr `plusPtr` 32) :: IO Word32
        return val

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

    @
    'Data.GI.Base.Attributes.set' outputMessage [ #numControlMessages 'Data.GI.Base.Attributes.:=' value ]
    @
    -}
    setOutputMessageNumControlMessages :: MonadIO m => OutputMessage -> Word32 -> m ()
    setOutputMessageNumControlMessages s val = liftIO $ withManagedPtr s $ \ptr -> do
        poke (ptr `plusPtr` 32) (val :: Word32)

    #if ENABLE_OVERLOADING
    data OutputMessageNumControlMessagesFieldInfo
    instance AttrInfo OutputMessageNumControlMessagesFieldInfo where
        type AttrAllowedOps OutputMessageNumControlMessagesFieldInfo = '[ 'AttrSet, 'AttrGet]
        type AttrSetTypeConstraint OutputMessageNumControlMessagesFieldInfo = (~) Word32
        type AttrBaseTypeConstraint OutputMessageNumControlMessagesFieldInfo = (~) OutputMessage
        type AttrGetType OutputMessageNumControlMessagesFieldInfo = Word32
        type AttrLabel OutputMessageNumControlMessagesFieldInfo = "num_control_messages"
        type AttrOrigin OutputMessageNumControlMessagesFieldInfo = OutputMessage
        attrGet _ = getOutputMessageNumControlMessages
        attrSet _ = setOutputMessageNumControlMessages
        attrConstruct = undefined
        attrClear _ = undefined

    outputMessage_numControlMessages :: AttrLabelProxy "numControlMessages"
    outputMessage_numControlMessages = AttrLabelProxy

    #endif

    #if ENABLE_OVERLOADING
    instance O.HasAttributeList OutputMessage
    type instance O.AttributeList OutputMessage = OutputMessageAttributeList
    type OutputMessageAttributeList = ('[ '("address", OutputMessageAddressFieldInfo), '("vectors", OutputMessageVectorsFieldInfo), '("numVectors", OutputMessageNumVectorsFieldInfo), '("bytesSent", OutputMessageBytesSentFieldInfo), '("numControlMessages", OutputMessageNumControlMessagesFieldInfo)] :: [(Symbol, *)])
    #endif

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

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

    #if MIN_VERSION_base(4,9,0)
    instance (info ~ ResolveOutputMessageMethod t OutputMessage, O.MethodInfo info OutputMessage p) => O.IsLabel t (OutputMessage -> 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