{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- Contains the Traffic Class byte of an IPv6 header.
-- 
-- This consists of the DSCP field as per
-- <https://www.rfc-editor.org/rfc/rfc2474#section-3 RFC 2474>,
-- and the ECN field as per
-- <https://www.rfc-editor.org/rfc/rfc3168#section-5 RFC 3168>.
-- 
-- It may be received using 'GI.Gio.Objects.Socket.socketReceiveMessage' over UDP sockets
-- (i.e. sockets in the @G_SOCKET_FAMILY_IPV6@ family with
-- @G_SOCKET_TYPE_DATAGRAM@ type). The message is not meant for sending. To set
-- Traffic Class field to be used in datagrams sent on a t'GI.Gio.Objects.Socket.Socket' use:
-- 
-- === /c code/
-- >g_socket_set_option (socket, IPPROTO_IPV6, IPV6_TCLASS, <TC value>, &error);
-- 
-- 
-- /Since: 2.88/

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

module GI.Gio.Objects.IPv6TclassMessage
    ( 

-- * Exported types
    IPv6TclassMessage(..)                   ,
    IsIPv6TclassMessage                     ,
    toIPv6TclassMessage                     ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [bindProperty]("GI.GObject.Objects.Object#g:method:bindProperty"), [bindPropertyFull]("GI.GObject.Objects.Object#g:method:bindPropertyFull"), [forceFloating]("GI.GObject.Objects.Object#g:method:forceFloating"), [freezeNotify]("GI.GObject.Objects.Object#g:method:freezeNotify"), [getv]("GI.GObject.Objects.Object#g:method:getv"), [isFloating]("GI.GObject.Objects.Object#g:method:isFloating"), [notify]("GI.GObject.Objects.Object#g:method:notify"), [notifyByPspec]("GI.GObject.Objects.Object#g:method:notifyByPspec"), [ref]("GI.GObject.Objects.Object#g:method:ref"), [refSink]("GI.GObject.Objects.Object#g:method:refSink"), [runDispose]("GI.GObject.Objects.Object#g:method:runDispose"), [serialize]("GI.Gio.Objects.SocketControlMessage#g:method:serialize"), [stealData]("GI.GObject.Objects.Object#g:method:stealData"), [stealQdata]("GI.GObject.Objects.Object#g:method:stealQdata"), [thawNotify]("GI.GObject.Objects.Object#g:method:thawNotify"), [unref]("GI.GObject.Objects.Object#g:method:unref"), [watchClosure]("GI.GObject.Objects.Object#g:method:watchClosure").
-- 
-- ==== Getters
-- [getData]("GI.GObject.Objects.Object#g:method:getData"), [getDscp]("GI.Gio.Objects.IPv6TclassMessage#g:method:getDscp"), [getEcn]("GI.Gio.Objects.IPv6TclassMessage#g:method:getEcn"), [getLevel]("GI.Gio.Objects.SocketControlMessage#g:method:getLevel"), [getMsgType]("GI.Gio.Objects.SocketControlMessage#g:method:getMsgType"), [getProperty]("GI.GObject.Objects.Object#g:method:getProperty"), [getQdata]("GI.GObject.Objects.Object#g:method:getQdata"), [getSize]("GI.Gio.Objects.SocketControlMessage#g:method:getSize").
-- 
-- ==== Setters
-- [setData]("GI.GObject.Objects.Object#g:method:setData"), [setDataFull]("GI.GObject.Objects.Object#g:method:setDataFull"), [setProperty]("GI.GObject.Objects.Object#g:method:setProperty").

#if defined(ENABLE_OVERLOADING)
    ResolveIPv6TclassMessageMethod          ,
#endif

-- ** getDscp #method:getDscp#

#if defined(ENABLE_OVERLOADING)
    IPv6TclassMessageGetDscpMethodInfo      ,
#endif
    iPv6TclassMessageGetDscp                ,


-- ** getEcn #method:getEcn#

#if defined(ENABLE_OVERLOADING)
    IPv6TclassMessageGetEcnMethodInfo       ,
#endif
    iPv6TclassMessageGetEcn                 ,


-- ** new #method:new#

    iPv6TclassMessageNew                    ,




    ) 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 qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Gio.Enums as Gio.Enums
import {-# SOURCE #-} qualified GI.Gio.Objects.SocketControlMessage as Gio.SocketControlMessage

#else
import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Gio.Enums as Gio.Enums
import {-# SOURCE #-} qualified GI.Gio.Objects.SocketControlMessage as Gio.SocketControlMessage

#endif

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

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

foreign import ccall "g_ipv6_tclass_message_get_type"
    c_g_ipv6_tclass_message_get_type :: IO B.Types.GType

instance B.Types.TypedObject IPv6TclassMessage where
    glibType = c_g_ipv6_tclass_message_get_type

instance B.Types.GObject IPv6TclassMessage

-- | Type class for types which can be safely cast to t'IPv6TclassMessage', for instance with `toIPv6TclassMessage`.
class (SP.GObject o, O.IsDescendantOf IPv6TclassMessage o) => IsIPv6TclassMessage o
instance (SP.GObject o, O.IsDescendantOf IPv6TclassMessage o) => IsIPv6TclassMessage o

instance O.HasParentTypes IPv6TclassMessage
type instance O.ParentTypes IPv6TclassMessage = '[Gio.SocketControlMessage.SocketControlMessage, GObject.Object.Object]

-- | Cast to t'IPv6TclassMessage', for types for which this is known to be safe. For general casts, use 'Data.GI.Base.ManagedPtr.castTo'.
toIPv6TclassMessage :: (MIO.MonadIO m, IsIPv6TclassMessage o) => o -> m IPv6TclassMessage
toIPv6TclassMessage = MIO.liftIO . B.ManagedPtr.unsafeCastTo IPv6TclassMessage

-- | Convert t'IPv6TclassMessage' to and from t'Data.GI.Base.GValue.GValue'. See 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue (Maybe IPv6TclassMessage) where
    gvalueGType_ = c_g_ipv6_tclass_message_get_type
    gvalueSet_ gv P.Nothing = B.GValue.set_object gv (FP.nullPtr :: FP.Ptr IPv6TclassMessage)
    gvalueSet_ gv (P.Just obj) = B.ManagedPtr.withManagedPtr obj (B.GValue.set_object gv)
    gvalueGet_ gv = do
        ptr <- B.GValue.get_object gv :: IO (FP.Ptr IPv6TclassMessage)
        if ptr /= FP.nullPtr
        then P.Just <$> B.ManagedPtr.newObject IPv6TclassMessage ptr
        else return P.Nothing
        
    

#if defined(ENABLE_OVERLOADING)
type family ResolveIPv6TclassMessageMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
    ResolveIPv6TclassMessageMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveIPv6TclassMessageMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveIPv6TclassMessageMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveIPv6TclassMessageMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveIPv6TclassMessageMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveIPv6TclassMessageMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveIPv6TclassMessageMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveIPv6TclassMessageMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveIPv6TclassMessageMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveIPv6TclassMessageMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveIPv6TclassMessageMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveIPv6TclassMessageMethod "serialize" o = Gio.SocketControlMessage.SocketControlMessageSerializeMethodInfo
    ResolveIPv6TclassMessageMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveIPv6TclassMessageMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveIPv6TclassMessageMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveIPv6TclassMessageMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveIPv6TclassMessageMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveIPv6TclassMessageMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveIPv6TclassMessageMethod "getDscp" o = IPv6TclassMessageGetDscpMethodInfo
    ResolveIPv6TclassMessageMethod "getEcn" o = IPv6TclassMessageGetEcnMethodInfo
    ResolveIPv6TclassMessageMethod "getLevel" o = Gio.SocketControlMessage.SocketControlMessageGetLevelMethodInfo
    ResolveIPv6TclassMessageMethod "getMsgType" o = Gio.SocketControlMessage.SocketControlMessageGetMsgTypeMethodInfo
    ResolveIPv6TclassMessageMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveIPv6TclassMessageMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveIPv6TclassMessageMethod "getSize" o = Gio.SocketControlMessage.SocketControlMessageGetSizeMethodInfo
    ResolveIPv6TclassMessageMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveIPv6TclassMessageMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveIPv6TclassMessageMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveIPv6TclassMessageMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveIPv6TclassMessageMethod t IPv6TclassMessage, O.OverloadedMethod info IPv6TclassMessage p) => OL.IsLabel t (IPv6TclassMessage -> 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 ~ ResolveIPv6TclassMessageMethod t IPv6TclassMessage, O.OverloadedMethod info IPv6TclassMessage p, R.HasField t IPv6TclassMessage p) => R.HasField t IPv6TclassMessage p where
    getField = O.overloadedMethod @info

#endif

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

#endif

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList IPv6TclassMessage
type instance O.AttributeList IPv6TclassMessage = IPv6TclassMessageAttributeList
type IPv6TclassMessageAttributeList = ('[ ] :: [(Symbol, DK.Type)])
#endif

#if defined(ENABLE_OVERLOADING)
#endif

#if defined(ENABLE_OVERLOADING)
type instance O.SignalList IPv6TclassMessage = IPv6TclassMessageSignalList
type IPv6TclassMessageSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, DK.Type)])

#endif

-- method IPv6TclassMessage::new
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "dscp"
--           , argType = TBasicType TUInt8
--           , argCType = Just "guint8"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the DSCP value of the message"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "ecn"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "EcnCodePoint" }
--           , argCType = Just "GEcnCodePoint"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the ECN value of the message"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just
--               (TInterface
--                  Name { namespace = "Gio" , name = "IPv6TclassMessage" })
-- throws : False
-- Skip return : False

foreign import ccall "g_ipv6_tclass_message_new" g_ipv6_tclass_message_new :: 
    Word8 ->                                -- dscp : TBasicType TUInt8
    CUInt ->                                -- ecn : TInterface (Name {namespace = "Gio", name = "EcnCodePoint"})
    IO (Ptr IPv6TclassMessage)

-- | Creates a new traffic class message with given DSCP and ECN values.
-- 
-- /Since: 2.88/
iPv6TclassMessageNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Word8
    -- ^ /@dscp@/: the DSCP value of the message
    -> Gio.Enums.EcnCodePoint
    -- ^ /@ecn@/: the ECN value of the message
    -> m IPv6TclassMessage
    -- ^ __Returns:__ a new traffic class message
iPv6TclassMessageNew dscp ecn = liftIO $ do
    let ecn' = (fromIntegral . fromEnum) ecn
    result <- g_ipv6_tclass_message_new dscp ecn'
    checkUnexpectedReturnNULL "iPv6TclassMessageNew" result
    result' <- (wrapObject IPv6TclassMessage) result
    return result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method IPv6TclassMessage::get_dscp
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "message"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "IPv6TclassMessage" }
--           , argCType = Just "GIPv6TclassMessage*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a traffic class message"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUInt8)
-- throws : False
-- Skip return : False

foreign import ccall "g_ipv6_tclass_message_get_dscp" g_ipv6_tclass_message_get_dscp :: 
    Ptr IPv6TclassMessage ->                -- message : TInterface (Name {namespace = "Gio", name = "IPv6TclassMessage"})
    IO Word8

-- | Gets the differentiated services code point stored in /@message@/.
-- 
-- /Since: 2.88/
iPv6TclassMessageGetDscp ::
    (B.CallStack.HasCallStack, MonadIO m, IsIPv6TclassMessage a) =>
    a
    -- ^ /@message@/: a traffic class message
    -> m Word8
    -- ^ __Returns:__ A DSCP value as described in <https://www.rfc-editor.org/rfc/rfc2474.html#section-3 RFC 2474>.
iPv6TclassMessageGetDscp message = liftIO $ do
    message' <- unsafeManagedPtrCastPtr message
    result <- g_ipv6_tclass_message_get_dscp message'
    touchManagedPtr message
    return result

#if defined(ENABLE_OVERLOADING)
data IPv6TclassMessageGetDscpMethodInfo
instance (signature ~ (m Word8), MonadIO m, IsIPv6TclassMessage a) => O.OverloadedMethod IPv6TclassMessageGetDscpMethodInfo a signature where
    overloadedMethod = iPv6TclassMessageGetDscp

instance O.OverloadedMethodInfo IPv6TclassMessageGetDscpMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Gio.Objects.IPv6TclassMessage.iPv6TclassMessageGetDscp",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gio-2.0.38/docs/GI-Gio-Objects-IPv6TclassMessage.html#v:iPv6TclassMessageGetDscp"
        })


#endif

-- method IPv6TclassMessage::get_ecn
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "message"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "IPv6TclassMessage" }
--           , argCType = Just "GIPv6TclassMessage*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a traffic class message"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "Gio" , name = "EcnCodePoint" })
-- throws : False
-- Skip return : False

foreign import ccall "g_ipv6_tclass_message_get_ecn" g_ipv6_tclass_message_get_ecn :: 
    Ptr IPv6TclassMessage ->                -- message : TInterface (Name {namespace = "Gio", name = "IPv6TclassMessage"})
    IO CUInt

-- | Gets the Explicit Congestion Notification code point stored in /@message@/.
-- 
-- /Since: 2.88/
iPv6TclassMessageGetEcn ::
    (B.CallStack.HasCallStack, MonadIO m, IsIPv6TclassMessage a) =>
    a
    -- ^ /@message@/: a traffic class message
    -> m Gio.Enums.EcnCodePoint
    -- ^ __Returns:__ An ECN value as described in <https://www.rfc-editor.org/rfc/rfc3168#section-5 RFC 3168>.
iPv6TclassMessageGetEcn message = liftIO $ do
    message' <- unsafeManagedPtrCastPtr message
    result <- g_ipv6_tclass_message_get_ecn message'
    let result' = (toEnum . fromIntegral) result
    touchManagedPtr message
    return result'

#if defined(ENABLE_OVERLOADING)
data IPv6TclassMessageGetEcnMethodInfo
instance (signature ~ (m Gio.Enums.EcnCodePoint), MonadIO m, IsIPv6TclassMessage a) => O.OverloadedMethod IPv6TclassMessageGetEcnMethodInfo a signature where
    overloadedMethod = iPv6TclassMessageGetEcn

instance O.OverloadedMethodInfo IPv6TclassMessageGetEcnMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Gio.Objects.IPv6TclassMessage.iPv6TclassMessageGetEcn",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gio-2.0.38/docs/GI-Gio-Objects-IPv6TclassMessage.html#v:iPv6TclassMessageGetEcn"
        })


#endif


