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

'GI.Gio.Interfaces.DtlsServerConnection.DtlsServerConnection' is the server-side subclass of 'GI.Gio.Interfaces.DtlsConnection.DtlsConnection',
representing a server-side DTLS connection.
-}

module GI.Gio.Interfaces.DtlsServerConnection
    ( 

-- * Exported types
    DtlsServerConnection(..)                ,
    noDtlsServerConnection                  ,
    IsDtlsServerConnection                  ,
    toDtlsServerConnection                  ,


 -- * Methods
-- ** new #method:new#
    dtlsServerConnectionNew                 ,




 -- * Properties
-- ** authenticationMode #attr:authenticationMode#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    DtlsServerConnectionAuthenticationModePropertyInfo,
#endif
    constructDtlsServerConnectionAuthenticationMode,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    dtlsServerConnectionAuthenticationMode  ,
#endif
    getDtlsServerConnectionAuthenticationMode,
    setDtlsServerConnectionAuthenticationMode,




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

-- interface DtlsServerConnection 
newtype DtlsServerConnection = DtlsServerConnection (ManagedPtr DtlsServerConnection)
noDtlsServerConnection :: Maybe DtlsServerConnection
noDtlsServerConnection = Nothing

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type instance O.SignalList DtlsServerConnection = DtlsServerConnectionSignalList
type DtlsServerConnectionSignalList = ('[ '("acceptCertificate", Gio.DtlsConnection.DtlsConnectionAcceptCertificateSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

foreign import ccall "g_dtls_server_connection_get_type"
    c_g_dtls_server_connection_get_type :: IO GType

instance GObject DtlsServerConnection where
    gobjectType _ = c_g_dtls_server_connection_get_type
    

class GObject o => IsDtlsServerConnection o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError DtlsServerConnection a) =>
    IsDtlsServerConnection a
#endif
instance IsDtlsServerConnection DtlsServerConnection
instance Gio.DtlsConnection.IsDtlsConnection DtlsServerConnection
instance Gio.DatagramBased.IsDatagramBased DtlsServerConnection
instance GObject.Object.IsObject DtlsServerConnection

toDtlsServerConnection :: (MonadIO m, IsDtlsServerConnection o) => o -> m DtlsServerConnection
toDtlsServerConnection = liftIO . unsafeCastTo DtlsServerConnection

-- VVV Prop "authentication-mode"
   -- Type: TInterface (Name {namespace = "Gio", name = "TlsAuthenticationMode"})
   -- Flags: [PropertyReadable,PropertyWritable]
   -- Nullable: (Nothing,Nothing)

getDtlsServerConnectionAuthenticationMode :: (MonadIO m, IsDtlsServerConnection o) => o -> m Gio.Enums.TlsAuthenticationMode
getDtlsServerConnectionAuthenticationMode obj = liftIO $ getObjectPropertyEnum obj "authentication-mode"

setDtlsServerConnectionAuthenticationMode :: (MonadIO m, IsDtlsServerConnection o) => o -> Gio.Enums.TlsAuthenticationMode -> m ()
setDtlsServerConnectionAuthenticationMode obj val = liftIO $ setObjectPropertyEnum obj "authentication-mode" val

constructDtlsServerConnectionAuthenticationMode :: (IsDtlsServerConnection o) => Gio.Enums.TlsAuthenticationMode -> IO (GValueConstruct o)
constructDtlsServerConnectionAuthenticationMode val = constructObjectPropertyEnum "authentication-mode" val

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data DtlsServerConnectionAuthenticationModePropertyInfo
instance AttrInfo DtlsServerConnectionAuthenticationModePropertyInfo where
    type AttrAllowedOps DtlsServerConnectionAuthenticationModePropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint DtlsServerConnectionAuthenticationModePropertyInfo = (~) Gio.Enums.TlsAuthenticationMode
    type AttrBaseTypeConstraint DtlsServerConnectionAuthenticationModePropertyInfo = IsDtlsServerConnection
    type AttrGetType DtlsServerConnectionAuthenticationModePropertyInfo = Gio.Enums.TlsAuthenticationMode
    type AttrLabel DtlsServerConnectionAuthenticationModePropertyInfo = "authentication-mode"
    type AttrOrigin DtlsServerConnectionAuthenticationModePropertyInfo = DtlsServerConnection
    attrGet _ = getDtlsServerConnectionAuthenticationMode
    attrSet _ = setDtlsServerConnectionAuthenticationMode
    attrConstruct _ = constructDtlsServerConnectionAuthenticationMode
    attrClear _ = undefined
#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
instance O.HasAttributeList DtlsServerConnection
type instance O.AttributeList DtlsServerConnection = DtlsServerConnectionAttributeList
type DtlsServerConnectionAttributeList = ('[ '("authenticationMode", DtlsServerConnectionAuthenticationModePropertyInfo), '("baseSocket", Gio.DtlsConnection.DtlsConnectionBaseSocketPropertyInfo), '("certificate", Gio.DtlsConnection.DtlsConnectionCertificatePropertyInfo), '("database", Gio.DtlsConnection.DtlsConnectionDatabasePropertyInfo), '("interaction", Gio.DtlsConnection.DtlsConnectionInteractionPropertyInfo), '("peerCertificate", Gio.DtlsConnection.DtlsConnectionPeerCertificatePropertyInfo), '("peerCertificateErrors", Gio.DtlsConnection.DtlsConnectionPeerCertificateErrorsPropertyInfo), '("rehandshakeMode", Gio.DtlsConnection.DtlsConnectionRehandshakeModePropertyInfo), '("requireCloseNotify", Gio.DtlsConnection.DtlsConnectionRequireCloseNotifyPropertyInfo)] :: [(Symbol, *)])
#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
dtlsServerConnectionAuthenticationMode :: AttrLabelProxy "authenticationMode"
dtlsServerConnectionAuthenticationMode = AttrLabelProxy

#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type family ResolveDtlsServerConnectionMethod (t :: Symbol) (o :: *) :: * where
    ResolveDtlsServerConnectionMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveDtlsServerConnectionMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveDtlsServerConnectionMethod "close" o = Gio.DtlsConnection.DtlsConnectionCloseMethodInfo
    ResolveDtlsServerConnectionMethod "closeAsync" o = Gio.DtlsConnection.DtlsConnectionCloseAsyncMethodInfo
    ResolveDtlsServerConnectionMethod "closeFinish" o = Gio.DtlsConnection.DtlsConnectionCloseFinishMethodInfo
    ResolveDtlsServerConnectionMethod "conditionCheck" o = Gio.DatagramBased.DatagramBasedConditionCheckMethodInfo
    ResolveDtlsServerConnectionMethod "conditionWait" o = Gio.DatagramBased.DatagramBasedConditionWaitMethodInfo
    ResolveDtlsServerConnectionMethod "createSource" o = Gio.DatagramBased.DatagramBasedCreateSourceMethodInfo
    ResolveDtlsServerConnectionMethod "emitAcceptCertificate" o = Gio.DtlsConnection.DtlsConnectionEmitAcceptCertificateMethodInfo
    ResolveDtlsServerConnectionMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveDtlsServerConnectionMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveDtlsServerConnectionMethod "handshake" o = Gio.DtlsConnection.DtlsConnectionHandshakeMethodInfo
    ResolveDtlsServerConnectionMethod "handshakeAsync" o = Gio.DtlsConnection.DtlsConnectionHandshakeAsyncMethodInfo
    ResolveDtlsServerConnectionMethod "handshakeFinish" o = Gio.DtlsConnection.DtlsConnectionHandshakeFinishMethodInfo
    ResolveDtlsServerConnectionMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveDtlsServerConnectionMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveDtlsServerConnectionMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveDtlsServerConnectionMethod "receiveMessages" o = Gio.DatagramBased.DatagramBasedReceiveMessagesMethodInfo
    ResolveDtlsServerConnectionMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveDtlsServerConnectionMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveDtlsServerConnectionMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveDtlsServerConnectionMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveDtlsServerConnectionMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveDtlsServerConnectionMethod "sendMessages" o = Gio.DatagramBased.DatagramBasedSendMessagesMethodInfo
    ResolveDtlsServerConnectionMethod "shutdown" o = Gio.DtlsConnection.DtlsConnectionShutdownMethodInfo
    ResolveDtlsServerConnectionMethod "shutdownAsync" o = Gio.DtlsConnection.DtlsConnectionShutdownAsyncMethodInfo
    ResolveDtlsServerConnectionMethod "shutdownFinish" o = Gio.DtlsConnection.DtlsConnectionShutdownFinishMethodInfo
    ResolveDtlsServerConnectionMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveDtlsServerConnectionMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveDtlsServerConnectionMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveDtlsServerConnectionMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveDtlsServerConnectionMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveDtlsServerConnectionMethod "getCertificate" o = Gio.DtlsConnection.DtlsConnectionGetCertificateMethodInfo
    ResolveDtlsServerConnectionMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveDtlsServerConnectionMethod "getDatabase" o = Gio.DtlsConnection.DtlsConnectionGetDatabaseMethodInfo
    ResolveDtlsServerConnectionMethod "getInteraction" o = Gio.DtlsConnection.DtlsConnectionGetInteractionMethodInfo
    ResolveDtlsServerConnectionMethod "getPeerCertificate" o = Gio.DtlsConnection.DtlsConnectionGetPeerCertificateMethodInfo
    ResolveDtlsServerConnectionMethod "getPeerCertificateErrors" o = Gio.DtlsConnection.DtlsConnectionGetPeerCertificateErrorsMethodInfo
    ResolveDtlsServerConnectionMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveDtlsServerConnectionMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveDtlsServerConnectionMethod "getRehandshakeMode" o = Gio.DtlsConnection.DtlsConnectionGetRehandshakeModeMethodInfo
    ResolveDtlsServerConnectionMethod "getRequireCloseNotify" o = Gio.DtlsConnection.DtlsConnectionGetRequireCloseNotifyMethodInfo
    ResolveDtlsServerConnectionMethod "setCertificate" o = Gio.DtlsConnection.DtlsConnectionSetCertificateMethodInfo
    ResolveDtlsServerConnectionMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveDtlsServerConnectionMethod "setDatabase" o = Gio.DtlsConnection.DtlsConnectionSetDatabaseMethodInfo
    ResolveDtlsServerConnectionMethod "setInteraction" o = Gio.DtlsConnection.DtlsConnectionSetInteractionMethodInfo
    ResolveDtlsServerConnectionMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveDtlsServerConnectionMethod "setRehandshakeMode" o = Gio.DtlsConnection.DtlsConnectionSetRehandshakeModeMethodInfo
    ResolveDtlsServerConnectionMethod "setRequireCloseNotify" o = Gio.DtlsConnection.DtlsConnectionSetRequireCloseNotifyMethodInfo
    ResolveDtlsServerConnectionMethod l o = O.MethodResolutionFailed l o

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

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

-- method DtlsServerConnection::new
-- method type : MemberFunction
-- Args : [Arg {argCName = "base_socket", argType = TInterface (Name {namespace = "Gio", name = "DatagramBased"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GDatagramBased to wrap", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "certificate", argType = TInterface (Name {namespace = "Gio", name = "TlsCertificate"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the default server certificate, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "DtlsServerConnection"}))
-- throws : True
-- Skip return : False

foreign import ccall "g_dtls_server_connection_new" g_dtls_server_connection_new :: 
    Ptr Gio.DatagramBased.DatagramBased ->  -- base_socket : TInterface (Name {namespace = "Gio", name = "DatagramBased"})
    Ptr Gio.TlsCertificate.TlsCertificate -> -- certificate : TInterface (Name {namespace = "Gio", name = "TlsCertificate"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr DtlsServerConnection)

{- |
Creates a new 'GI.Gio.Interfaces.DtlsServerConnection.DtlsServerConnection' wrapping /@baseSocket@/.

@since 2.48
-}
dtlsServerConnectionNew ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.DatagramBased.IsDatagramBased a, Gio.TlsCertificate.IsTlsCertificate b) =>
    a
    {- ^ /@baseSocket@/: the 'GI.Gio.Interfaces.DatagramBased.DatagramBased' to wrap -}
    -> Maybe (b)
    {- ^ /@certificate@/: the default server certificate, or 'Nothing' -}
    -> m DtlsServerConnection
    {- ^ __Returns:__ the new
  'GI.Gio.Interfaces.DtlsServerConnection.DtlsServerConnection', or 'Nothing' on error /(Can throw 'Data.GI.Base.GError.GError')/ -}
dtlsServerConnectionNew baseSocket certificate = liftIO $ do
    baseSocket' <- unsafeManagedPtrCastPtr baseSocket
    maybeCertificate <- case certificate of
        Nothing -> return nullPtr
        Just jCertificate -> do
            jCertificate' <- unsafeManagedPtrCastPtr jCertificate
            return jCertificate'
    onException (do
        result <- propagateGError $ g_dtls_server_connection_new baseSocket' maybeCertificate
        checkUnexpectedReturnNULL "dtlsServerConnectionNew" result
        result' <- (wrapObject DtlsServerConnection) result
        touchManagedPtr baseSocket
        whenJust certificate touchManagedPtr
        return result'
     ) (do
        return ()
     )

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
#endif