{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- Contains the type of service (ToS) byte of an IPv4 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_IPV4@ family with
-- @G_SOCKET_TYPE_DATAGRAM@ type). The message is not meant for sending. To set
-- ToS field to be used in datagrams sent on a t'GI.Gio.Objects.Socket.Socket' use:
-- 
-- === /c code/
-- >g_socket_set_option (socket, IPPROTO_IP, IP_TOS, <ToS 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.IPTosMessage
    ( 

-- * Exported types
    IPTosMessage(..)                        ,
    IsIPTosMessage                          ,
    toIPTosMessage                          ,


 -- * 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.IPTosMessage#g:method:getDscp"), [getEcn]("GI.Gio.Objects.IPTosMessage#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)
    ResolveIPTosMessageMethod               ,
#endif

-- ** getDscp #method:getDscp#

#if defined(ENABLE_OVERLOADING)
    IPTosMessageGetDscpMethodInfo           ,
#endif
    iPTosMessageGetDscp                     ,


-- ** getEcn #method:getEcn#

#if defined(ENABLE_OVERLOADING)
    IPTosMessageGetEcnMethodInfo            ,
#endif
    iPTosMessageGetEcn                      ,


-- ** new #method:new#

    iPTosMessageNew                         ,




    ) 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 IPTosMessage = IPTosMessage (SP.ManagedPtr IPTosMessage)
    deriving (Eq)

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

foreign import ccall "g_ip_tos_message_get_type"
    c_g_ip_tos_message_get_type :: IO B.Types.GType

instance B.Types.TypedObject IPTosMessage where
    glibType = c_g_ip_tos_message_get_type

instance B.Types.GObject IPTosMessage

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

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

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

-- | Convert t'IPTosMessage' 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 IPTosMessage) where
    gvalueGType_ = c_g_ip_tos_message_get_type
    gvalueSet_ gv P.Nothing = B.GValue.set_object gv (FP.nullPtr :: FP.Ptr IPTosMessage)
    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 IPTosMessage)
        if ptr /= FP.nullPtr
        then P.Just <$> B.ManagedPtr.newObject IPTosMessage ptr
        else return P.Nothing
        
    

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

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

#endif

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

#endif

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

#if defined(ENABLE_OVERLOADING)
#endif

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

#endif

-- method IPTosMessage::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 = "IPTosMessage" })
-- throws : False
-- Skip return : False

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

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

#if defined(ENABLE_OVERLOADING)
#endif

-- method IPTosMessage::get_dscp
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "message"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "IPTosMessage" }
--           , argCType = Just "GIPTosMessage*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a type-of-service 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_ip_tos_message_get_dscp" g_ip_tos_message_get_dscp :: 
    Ptr IPTosMessage ->                     -- message : TInterface (Name {namespace = "Gio", name = "IPTosMessage"})
    IO Word8

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

#if defined(ENABLE_OVERLOADING)
data IPTosMessageGetDscpMethodInfo
instance (signature ~ (m Word8), MonadIO m, IsIPTosMessage a) => O.OverloadedMethod IPTosMessageGetDscpMethodInfo a signature where
    overloadedMethod = iPTosMessageGetDscp

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


#endif

-- method IPTosMessage::get_ecn
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "message"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "IPTosMessage" }
--           , argCType = Just "GIPTosMessage*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a type-of-service 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_ip_tos_message_get_ecn" g_ip_tos_message_get_ecn :: 
    Ptr IPTosMessage ->                     -- message : TInterface (Name {namespace = "Gio", name = "IPTosMessage"})
    IO CUInt

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

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

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


#endif


