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

A 'GI.Gio.Objects.TcpWrapperConnection.TcpWrapperConnection' can be used to wrap a 'GI.Gio.Objects.IOStream.IOStream' that is
based on a 'GI.Gio.Objects.Socket.Socket', but which is not actually a
'GI.Gio.Objects.SocketConnection.SocketConnection'. This is used by 'GI.Gio.Objects.SocketClient.SocketClient' so that it can
always return a 'GI.Gio.Objects.SocketConnection.SocketConnection', even when the connection it has
actually created is not directly a 'GI.Gio.Objects.SocketConnection.SocketConnection'.

/Since: 2.28/
-}

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

module GI.Gio.Objects.TcpWrapperConnection
    (

-- * Exported types
    TcpWrapperConnection(..)                ,
    IsTcpWrapperConnection                  ,
    toTcpWrapperConnection                  ,
    noTcpWrapperConnection                  ,


 -- * Methods
-- ** getBaseIoStream #method:getBaseIoStream#

#if ENABLE_OVERLOADING
    TcpWrapperConnectionGetBaseIoStreamMethodInfo,
#endif
    tcpWrapperConnectionGetBaseIoStream     ,


-- ** new #method:new#

    tcpWrapperConnectionNew                 ,




 -- * Properties
-- ** baseIoStream #attr:baseIoStream#
{- | /No description available in the introspection data./
-}
#if ENABLE_OVERLOADING
    TcpWrapperConnectionBaseIoStreamPropertyInfo,
#endif
    constructTcpWrapperConnectionBaseIoStream,
    getTcpWrapperConnectionBaseIoStream     ,
#if ENABLE_OVERLOADING
    tcpWrapperConnectionBaseIoStream        ,
#endif




    ) 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.GClosure as B.GClosure
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.GI.Base.Properties as B.Properties
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 GHC.OverloadedLabels as OL

import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Gio.Objects.IOStream as Gio.IOStream
import {-# SOURCE #-} qualified GI.Gio.Objects.Socket as Gio.Socket
import {-# SOURCE #-} qualified GI.Gio.Objects.SocketConnection as Gio.SocketConnection
import {-# SOURCE #-} qualified GI.Gio.Objects.TcpConnection as Gio.TcpConnection

-- | Memory-managed wrapper type.
newtype TcpWrapperConnection = TcpWrapperConnection (ManagedPtr TcpWrapperConnection)
foreign import ccall "g_tcp_wrapper_connection_get_type"
    c_g_tcp_wrapper_connection_get_type :: IO GType

instance GObject TcpWrapperConnection where
    gobjectType = c_g_tcp_wrapper_connection_get_type


-- | Type class for types which can be safely cast to `TcpWrapperConnection`, for instance with `toTcpWrapperConnection`.
class (GObject o, O.IsDescendantOf TcpWrapperConnection o) => IsTcpWrapperConnection o
instance (GObject o, O.IsDescendantOf TcpWrapperConnection o) => IsTcpWrapperConnection o

instance O.HasParentTypes TcpWrapperConnection
type instance O.ParentTypes TcpWrapperConnection = '[Gio.TcpConnection.TcpConnection, Gio.SocketConnection.SocketConnection, Gio.IOStream.IOStream, GObject.Object.Object]

-- | Cast to `TcpWrapperConnection`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toTcpWrapperConnection :: (MonadIO m, IsTcpWrapperConnection o) => o -> m TcpWrapperConnection
toTcpWrapperConnection = liftIO . unsafeCastTo TcpWrapperConnection

-- | A convenience alias for `Nothing` :: `Maybe` `TcpWrapperConnection`.
noTcpWrapperConnection :: Maybe TcpWrapperConnection
noTcpWrapperConnection = Nothing

#if ENABLE_OVERLOADING
type family ResolveTcpWrapperConnectionMethod (t :: Symbol) (o :: *) :: * where
    ResolveTcpWrapperConnectionMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveTcpWrapperConnectionMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveTcpWrapperConnectionMethod "clearPending" o = Gio.IOStream.IOStreamClearPendingMethodInfo
    ResolveTcpWrapperConnectionMethod "close" o = Gio.IOStream.IOStreamCloseMethodInfo
    ResolveTcpWrapperConnectionMethod "closeAsync" o = Gio.IOStream.IOStreamCloseAsyncMethodInfo
    ResolveTcpWrapperConnectionMethod "closeFinish" o = Gio.IOStream.IOStreamCloseFinishMethodInfo
    ResolveTcpWrapperConnectionMethod "connect" o = Gio.SocketConnection.SocketConnectionConnectMethodInfo
    ResolveTcpWrapperConnectionMethod "connectAsync" o = Gio.SocketConnection.SocketConnectionConnectAsyncMethodInfo
    ResolveTcpWrapperConnectionMethod "connectFinish" o = Gio.SocketConnection.SocketConnectionConnectFinishMethodInfo
    ResolveTcpWrapperConnectionMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveTcpWrapperConnectionMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveTcpWrapperConnectionMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveTcpWrapperConnectionMethod "hasPending" o = Gio.IOStream.IOStreamHasPendingMethodInfo
    ResolveTcpWrapperConnectionMethod "isClosed" o = Gio.IOStream.IOStreamIsClosedMethodInfo
    ResolveTcpWrapperConnectionMethod "isConnected" o = Gio.SocketConnection.SocketConnectionIsConnectedMethodInfo
    ResolveTcpWrapperConnectionMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveTcpWrapperConnectionMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveTcpWrapperConnectionMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveTcpWrapperConnectionMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveTcpWrapperConnectionMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveTcpWrapperConnectionMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveTcpWrapperConnectionMethod "spliceAsync" o = Gio.IOStream.IOStreamSpliceAsyncMethodInfo
    ResolveTcpWrapperConnectionMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveTcpWrapperConnectionMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveTcpWrapperConnectionMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveTcpWrapperConnectionMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveTcpWrapperConnectionMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveTcpWrapperConnectionMethod "getBaseIoStream" o = TcpWrapperConnectionGetBaseIoStreamMethodInfo
    ResolveTcpWrapperConnectionMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveTcpWrapperConnectionMethod "getGracefulDisconnect" o = Gio.TcpConnection.TcpConnectionGetGracefulDisconnectMethodInfo
    ResolveTcpWrapperConnectionMethod "getInputStream" o = Gio.IOStream.IOStreamGetInputStreamMethodInfo
    ResolveTcpWrapperConnectionMethod "getLocalAddress" o = Gio.SocketConnection.SocketConnectionGetLocalAddressMethodInfo
    ResolveTcpWrapperConnectionMethod "getOutputStream" o = Gio.IOStream.IOStreamGetOutputStreamMethodInfo
    ResolveTcpWrapperConnectionMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveTcpWrapperConnectionMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveTcpWrapperConnectionMethod "getRemoteAddress" o = Gio.SocketConnection.SocketConnectionGetRemoteAddressMethodInfo
    ResolveTcpWrapperConnectionMethod "getSocket" o = Gio.SocketConnection.SocketConnectionGetSocketMethodInfo
    ResolveTcpWrapperConnectionMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveTcpWrapperConnectionMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveTcpWrapperConnectionMethod "setGracefulDisconnect" o = Gio.TcpConnection.TcpConnectionSetGracefulDisconnectMethodInfo
    ResolveTcpWrapperConnectionMethod "setPending" o = Gio.IOStream.IOStreamSetPendingMethodInfo
    ResolveTcpWrapperConnectionMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveTcpWrapperConnectionMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveTcpWrapperConnectionMethod t TcpWrapperConnection, O.MethodInfo info TcpWrapperConnection p) => OL.IsLabel t (TcpWrapperConnection -> 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

-- VVV Prop "base-io-stream"
   -- Type: TInterface (Name {namespace = "Gio", name = "IOStream"})
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Just False,Nothing)

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

@
'Data.GI.Base.Attributes.get' tcpWrapperConnection #baseIoStream
@
-}
getTcpWrapperConnectionBaseIoStream :: (MonadIO m, IsTcpWrapperConnection o) => o -> m Gio.IOStream.IOStream
getTcpWrapperConnectionBaseIoStream obj = liftIO $ checkUnexpectedNothing "getTcpWrapperConnectionBaseIoStream" $ B.Properties.getObjectPropertyObject obj "base-io-stream" Gio.IOStream.IOStream

{- |
Construct a `GValueConstruct` with valid value for the “@base-io-stream@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`.
-}
constructTcpWrapperConnectionBaseIoStream :: (IsTcpWrapperConnection o, Gio.IOStream.IsIOStream a) => a -> IO (GValueConstruct o)
constructTcpWrapperConnectionBaseIoStream val = B.Properties.constructObjectPropertyObject "base-io-stream" (Just val)

#if ENABLE_OVERLOADING
data TcpWrapperConnectionBaseIoStreamPropertyInfo
instance AttrInfo TcpWrapperConnectionBaseIoStreamPropertyInfo where
    type AttrAllowedOps TcpWrapperConnectionBaseIoStreamPropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint TcpWrapperConnectionBaseIoStreamPropertyInfo = Gio.IOStream.IsIOStream
    type AttrBaseTypeConstraint TcpWrapperConnectionBaseIoStreamPropertyInfo = IsTcpWrapperConnection
    type AttrGetType TcpWrapperConnectionBaseIoStreamPropertyInfo = Gio.IOStream.IOStream
    type AttrLabel TcpWrapperConnectionBaseIoStreamPropertyInfo = "base-io-stream"
    type AttrOrigin TcpWrapperConnectionBaseIoStreamPropertyInfo = TcpWrapperConnection
    attrGet _ = getTcpWrapperConnectionBaseIoStream
    attrSet _ = undefined
    attrConstruct _ = constructTcpWrapperConnectionBaseIoStream
    attrClear _ = undefined
#endif

#if ENABLE_OVERLOADING
instance O.HasAttributeList TcpWrapperConnection
type instance O.AttributeList TcpWrapperConnection = TcpWrapperConnectionAttributeList
type TcpWrapperConnectionAttributeList = ('[ '("baseIoStream", TcpWrapperConnectionBaseIoStreamPropertyInfo), '("closed", Gio.IOStream.IOStreamClosedPropertyInfo), '("gracefulDisconnect", Gio.TcpConnection.TcpConnectionGracefulDisconnectPropertyInfo), '("inputStream", Gio.IOStream.IOStreamInputStreamPropertyInfo), '("outputStream", Gio.IOStream.IOStreamOutputStreamPropertyInfo), '("socket", Gio.SocketConnection.SocketConnectionSocketPropertyInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
tcpWrapperConnectionBaseIoStream :: AttrLabelProxy "baseIoStream"
tcpWrapperConnectionBaseIoStream = AttrLabelProxy

#endif

#if ENABLE_OVERLOADING
type instance O.SignalList TcpWrapperConnection = TcpWrapperConnectionSignalList
type TcpWrapperConnectionSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method TcpWrapperConnection::new
-- method type : Constructor
-- 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 = "socket", argType = TInterface (Name {namespace = "Gio", name = "Socket"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GSocket associated with @base_io_stream", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "TcpWrapperConnection"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_tcp_wrapper_connection_new" g_tcp_wrapper_connection_new ::
    Ptr Gio.IOStream.IOStream ->            -- base_io_stream : TInterface (Name {namespace = "Gio", name = "IOStream"})
    Ptr Gio.Socket.Socket ->                -- socket : TInterface (Name {namespace = "Gio", name = "Socket"})
    IO (Ptr TcpWrapperConnection)

{- |
Wraps /@baseIoStream@/ and /@socket@/ together as a 'GI.Gio.Objects.SocketConnection.SocketConnection'.

/Since: 2.28/
-}
tcpWrapperConnectionNew ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.IOStream.IsIOStream a, Gio.Socket.IsSocket b) =>
    a
    {- ^ /@baseIoStream@/: the 'GI.Gio.Objects.IOStream.IOStream' to wrap -}
    -> b
    {- ^ /@socket@/: the 'GI.Gio.Objects.Socket.Socket' associated with /@baseIoStream@/ -}
    -> m TcpWrapperConnection
    {- ^ __Returns:__ the new 'GI.Gio.Objects.SocketConnection.SocketConnection'. -}
tcpWrapperConnectionNew baseIoStream socket = liftIO $ do
    baseIoStream' <- unsafeManagedPtrCastPtr baseIoStream
    socket' <- unsafeManagedPtrCastPtr socket
    result <- g_tcp_wrapper_connection_new baseIoStream' socket'
    checkUnexpectedReturnNULL "tcpWrapperConnectionNew" result
    result' <- (wrapObject TcpWrapperConnection) result
    touchManagedPtr baseIoStream
    touchManagedPtr socket
    return result'

#if ENABLE_OVERLOADING
#endif

-- method TcpWrapperConnection::get_base_io_stream
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "conn", argType = TInterface (Name {namespace = "Gio", name = "TcpWrapperConnection"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTcpWrapperConnection", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "IOStream"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_tcp_wrapper_connection_get_base_io_stream" g_tcp_wrapper_connection_get_base_io_stream ::
    Ptr TcpWrapperConnection ->             -- conn : TInterface (Name {namespace = "Gio", name = "TcpWrapperConnection"})
    IO (Ptr Gio.IOStream.IOStream)

{- |
Get\'s /@conn@/\'s base 'GI.Gio.Objects.IOStream.IOStream'
-}
tcpWrapperConnectionGetBaseIoStream ::
    (B.CallStack.HasCallStack, MonadIO m, IsTcpWrapperConnection a) =>
    a
    {- ^ /@conn@/: a 'GI.Gio.Objects.TcpWrapperConnection.TcpWrapperConnection' -}
    -> m Gio.IOStream.IOStream
    {- ^ __Returns:__ /@conn@/\'s base 'GI.Gio.Objects.IOStream.IOStream' -}
tcpWrapperConnectionGetBaseIoStream conn = liftIO $ do
    conn' <- unsafeManagedPtrCastPtr conn
    result <- g_tcp_wrapper_connection_get_base_io_stream conn'
    checkUnexpectedReturnNULL "tcpWrapperConnectionGetBaseIoStream" result
    result' <- (newObject Gio.IOStream.IOStream) result
    touchManagedPtr conn
    return result'

#if ENABLE_OVERLOADING
data TcpWrapperConnectionGetBaseIoStreamMethodInfo
instance (signature ~ (m Gio.IOStream.IOStream), MonadIO m, IsTcpWrapperConnection a) => O.MethodInfo TcpWrapperConnectionGetBaseIoStreamMethodInfo a signature where
    overloadedMethod _ = tcpWrapperConnectionGetBaseIoStream

#endif