{- |
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.TlsServerConnection.TlsServerConnection' is the server-side subclass of 'GI.Gio.Objects.TlsConnection.TlsConnection',
representing a server-side TLS connection.
-}

module GI.Gio.Interfaces.TlsServerConnection
    ( 

-- * Exported types
    TlsServerConnection(..)                 ,
    noTlsServerConnection                   ,
    IsTlsServerConnection                   ,
    toTlsServerConnection                   ,


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




 -- * Properties
-- ** authenticationMode #attr:authenticationMode#
    TlsServerConnectionAuthenticationModePropertyInfo,
    constructTlsServerConnectionAuthenticationMode,
    getTlsServerConnectionAuthenticationMode,
    setTlsServerConnectionAuthenticationMode,
    tlsServerConnectionAuthenticationMode   ,




    ) 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.Objects.IOStream as Gio.IOStream
import {-# SOURCE #-} qualified GI.Gio.Objects.TlsCertificate as Gio.TlsCertificate
import {-# SOURCE #-} qualified GI.Gio.Objects.TlsConnection as Gio.TlsConnection

-- interface TlsServerConnection 
newtype TlsServerConnection = TlsServerConnection (ManagedPtr TlsServerConnection)
noTlsServerConnection :: Maybe TlsServerConnection
noTlsServerConnection = Nothing

type instance O.SignalList TlsServerConnection = TlsServerConnectionSignalList
type TlsServerConnectionSignalList = ('[ '("acceptCertificate", Gio.TlsConnection.TlsConnectionAcceptCertificateSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

foreign import ccall "g_tls_server_connection_get_type"
    c_g_tls_server_connection_get_type :: IO GType

instance GObject TlsServerConnection where
    gobjectType _ = c_g_tls_server_connection_get_type
    

class GObject o => IsTlsServerConnection o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError TlsServerConnection a) =>
    IsTlsServerConnection a
#endif
instance IsTlsServerConnection TlsServerConnection
instance GObject.Object.IsObject TlsServerConnection
instance Gio.TlsConnection.IsTlsConnection TlsServerConnection
instance Gio.IOStream.IsIOStream TlsServerConnection

toTlsServerConnection :: IsTlsServerConnection o => o -> IO TlsServerConnection
toTlsServerConnection = unsafeCastTo TlsServerConnection

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

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

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

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

data TlsServerConnectionAuthenticationModePropertyInfo
instance AttrInfo TlsServerConnectionAuthenticationModePropertyInfo where
    type AttrAllowedOps TlsServerConnectionAuthenticationModePropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint TlsServerConnectionAuthenticationModePropertyInfo = (~) Gio.Enums.TlsAuthenticationMode
    type AttrBaseTypeConstraint TlsServerConnectionAuthenticationModePropertyInfo = IsTlsServerConnection
    type AttrGetType TlsServerConnectionAuthenticationModePropertyInfo = Gio.Enums.TlsAuthenticationMode
    type AttrLabel TlsServerConnectionAuthenticationModePropertyInfo = "authentication-mode"
    type AttrOrigin TlsServerConnectionAuthenticationModePropertyInfo = TlsServerConnection
    attrGet _ = getTlsServerConnectionAuthenticationMode
    attrSet _ = setTlsServerConnectionAuthenticationMode
    attrConstruct _ = constructTlsServerConnectionAuthenticationMode
    attrClear _ = undefined

instance O.HasAttributeList TlsServerConnection
type instance O.AttributeList TlsServerConnection = TlsServerConnectionAttributeList
type TlsServerConnectionAttributeList = ('[ '("authenticationMode", TlsServerConnectionAuthenticationModePropertyInfo), '("baseIoStream", Gio.TlsConnection.TlsConnectionBaseIoStreamPropertyInfo), '("certificate", Gio.TlsConnection.TlsConnectionCertificatePropertyInfo), '("closed", Gio.IOStream.IOStreamClosedPropertyInfo), '("database", Gio.TlsConnection.TlsConnectionDatabasePropertyInfo), '("inputStream", Gio.IOStream.IOStreamInputStreamPropertyInfo), '("interaction", Gio.TlsConnection.TlsConnectionInteractionPropertyInfo), '("outputStream", Gio.IOStream.IOStreamOutputStreamPropertyInfo), '("peerCertificate", Gio.TlsConnection.TlsConnectionPeerCertificatePropertyInfo), '("peerCertificateErrors", Gio.TlsConnection.TlsConnectionPeerCertificateErrorsPropertyInfo), '("rehandshakeMode", Gio.TlsConnection.TlsConnectionRehandshakeModePropertyInfo), '("requireCloseNotify", Gio.TlsConnection.TlsConnectionRequireCloseNotifyPropertyInfo), '("useSystemCertdb", Gio.TlsConnection.TlsConnectionUseSystemCertdbPropertyInfo)] :: [(Symbol, *)])

tlsServerConnectionAuthenticationMode :: AttrLabelProxy "authenticationMode"
tlsServerConnectionAuthenticationMode = AttrLabelProxy

type family ResolveTlsServerConnectionMethod (t :: Symbol) (o :: *) :: * where
    ResolveTlsServerConnectionMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveTlsServerConnectionMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveTlsServerConnectionMethod "clearPending" o = Gio.IOStream.IOStreamClearPendingMethodInfo
    ResolveTlsServerConnectionMethod "close" o = Gio.IOStream.IOStreamCloseMethodInfo
    ResolveTlsServerConnectionMethod "closeAsync" o = Gio.IOStream.IOStreamCloseAsyncMethodInfo
    ResolveTlsServerConnectionMethod "closeFinish" o = Gio.IOStream.IOStreamCloseFinishMethodInfo
    ResolveTlsServerConnectionMethod "emitAcceptCertificate" o = Gio.TlsConnection.TlsConnectionEmitAcceptCertificateMethodInfo
    ResolveTlsServerConnectionMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveTlsServerConnectionMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveTlsServerConnectionMethod "handshake" o = Gio.TlsConnection.TlsConnectionHandshakeMethodInfo
    ResolveTlsServerConnectionMethod "handshakeAsync" o = Gio.TlsConnection.TlsConnectionHandshakeAsyncMethodInfo
    ResolveTlsServerConnectionMethod "handshakeFinish" o = Gio.TlsConnection.TlsConnectionHandshakeFinishMethodInfo
    ResolveTlsServerConnectionMethod "hasPending" o = Gio.IOStream.IOStreamHasPendingMethodInfo
    ResolveTlsServerConnectionMethod "isClosed" o = Gio.IOStream.IOStreamIsClosedMethodInfo
    ResolveTlsServerConnectionMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveTlsServerConnectionMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveTlsServerConnectionMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveTlsServerConnectionMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveTlsServerConnectionMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveTlsServerConnectionMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveTlsServerConnectionMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveTlsServerConnectionMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveTlsServerConnectionMethod "spliceAsync" o = Gio.IOStream.IOStreamSpliceAsyncMethodInfo
    ResolveTlsServerConnectionMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveTlsServerConnectionMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveTlsServerConnectionMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveTlsServerConnectionMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveTlsServerConnectionMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveTlsServerConnectionMethod "getCertificate" o = Gio.TlsConnection.TlsConnectionGetCertificateMethodInfo
    ResolveTlsServerConnectionMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveTlsServerConnectionMethod "getDatabase" o = Gio.TlsConnection.TlsConnectionGetDatabaseMethodInfo
    ResolveTlsServerConnectionMethod "getInputStream" o = Gio.IOStream.IOStreamGetInputStreamMethodInfo
    ResolveTlsServerConnectionMethod "getInteraction" o = Gio.TlsConnection.TlsConnectionGetInteractionMethodInfo
    ResolveTlsServerConnectionMethod "getOutputStream" o = Gio.IOStream.IOStreamGetOutputStreamMethodInfo
    ResolveTlsServerConnectionMethod "getPeerCertificate" o = Gio.TlsConnection.TlsConnectionGetPeerCertificateMethodInfo
    ResolveTlsServerConnectionMethod "getPeerCertificateErrors" o = Gio.TlsConnection.TlsConnectionGetPeerCertificateErrorsMethodInfo
    ResolveTlsServerConnectionMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveTlsServerConnectionMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveTlsServerConnectionMethod "getRehandshakeMode" o = Gio.TlsConnection.TlsConnectionGetRehandshakeModeMethodInfo
    ResolveTlsServerConnectionMethod "getRequireCloseNotify" o = Gio.TlsConnection.TlsConnectionGetRequireCloseNotifyMethodInfo
    ResolveTlsServerConnectionMethod "getUseSystemCertdb" o = Gio.TlsConnection.TlsConnectionGetUseSystemCertdbMethodInfo
    ResolveTlsServerConnectionMethod "setCertificate" o = Gio.TlsConnection.TlsConnectionSetCertificateMethodInfo
    ResolveTlsServerConnectionMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveTlsServerConnectionMethod "setDatabase" o = Gio.TlsConnection.TlsConnectionSetDatabaseMethodInfo
    ResolveTlsServerConnectionMethod "setInteraction" o = Gio.TlsConnection.TlsConnectionSetInteractionMethodInfo
    ResolveTlsServerConnectionMethod "setPending" o = Gio.IOStream.IOStreamSetPendingMethodInfo
    ResolveTlsServerConnectionMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveTlsServerConnectionMethod "setRehandshakeMode" o = Gio.TlsConnection.TlsConnectionSetRehandshakeModeMethodInfo
    ResolveTlsServerConnectionMethod "setRequireCloseNotify" o = Gio.TlsConnection.TlsConnectionSetRequireCloseNotifyMethodInfo
    ResolveTlsServerConnectionMethod "setUseSystemCertdb" o = Gio.TlsConnection.TlsConnectionSetUseSystemCertdbMethodInfo
    ResolveTlsServerConnectionMethod l o = O.MethodResolutionFailed l o

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

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

-- method TlsServerConnection::new
-- method type : MemberFunction
-- Args : [Arg {argCName = "base_io_stream", argType = TInterface (Name {namespace = "Gio", name = "IOStream"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GIOStream 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 = "TlsServerConnection"}))
-- throws : True
-- Skip return : False

foreign import ccall "g_tls_server_connection_new" g_tls_server_connection_new :: 
    Ptr Gio.IOStream.IOStream ->            -- base_io_stream : TInterface (Name {namespace = "Gio", name = "IOStream"})
    Ptr Gio.TlsCertificate.TlsCertificate -> -- certificate : TInterface (Name {namespace = "Gio", name = "TlsCertificate"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr TlsServerConnection)

{- |
Creates a new 'GI.Gio.Interfaces.TlsServerConnection.TlsServerConnection' wrapping /@baseIoStream@/ (which
must have pollable input and output streams).

See the documentation for 'GI.Gio.Objects.TlsConnection.TlsConnection':@/base-io-stream/@ for restrictions
on when application code can run operations on the /@baseIoStream@/ after
this function has returned.

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