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

GSimpleIOStream creates a 'GI.Gio.Objects.IOStream.IOStream' from an arbitrary 'GI.Gio.Objects.InputStream.InputStream' and
'GI.Gio.Objects.OutputStream.OutputStream'. This allows any pair of input and output streams to be used
with 'GI.Gio.Objects.IOStream.IOStream' methods.

This is useful when you obtained a 'GI.Gio.Objects.InputStream.InputStream' and a 'GI.Gio.Objects.OutputStream.OutputStream'
by other means, for instance creating them with platform specific methods as
'GI.Gio.Objects.UnixInputStream.unixInputStreamNew' or @/g_win32_input_stream_new()/@, and you want
to take advantage of the methods provided by 'GI.Gio.Objects.IOStream.IOStream'.
-}

module GI.Gio.Objects.SimpleIOStream
    ( 

-- * Exported types
    SimpleIOStream(..)                      ,
    IsSimpleIOStream                        ,
    toSimpleIOStream                        ,
    noSimpleIOStream                        ,


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




 -- * Properties
-- ** inputStream #attr:inputStream#
    SimpleIOStreamInputStreamPropertyInfo   ,
    constructSimpleIOStreamInputStream      ,
    getSimpleIOStreamInputStream            ,
    simpleIOStreamInputStream               ,


-- ** outputStream #attr:outputStream#
    SimpleIOStreamOutputStreamPropertyInfo  ,
    constructSimpleIOStreamOutputStream     ,
    getSimpleIOStreamOutputStream           ,
    simpleIOStreamOutputStream              ,




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

newtype SimpleIOStream = SimpleIOStream (ManagedPtr SimpleIOStream)
foreign import ccall "g_simple_io_stream_get_type"
    c_g_simple_io_stream_get_type :: IO GType

instance GObject SimpleIOStream where
    gobjectType _ = c_g_simple_io_stream_get_type
    

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

toSimpleIOStream :: IsSimpleIOStream o => o -> IO SimpleIOStream
toSimpleIOStream = unsafeCastTo SimpleIOStream

noSimpleIOStream :: Maybe SimpleIOStream
noSimpleIOStream = Nothing

type family ResolveSimpleIOStreamMethod (t :: Symbol) (o :: *) :: * where
    ResolveSimpleIOStreamMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveSimpleIOStreamMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveSimpleIOStreamMethod "clearPending" o = Gio.IOStream.IOStreamClearPendingMethodInfo
    ResolveSimpleIOStreamMethod "close" o = Gio.IOStream.IOStreamCloseMethodInfo
    ResolveSimpleIOStreamMethod "closeAsync" o = Gio.IOStream.IOStreamCloseAsyncMethodInfo
    ResolveSimpleIOStreamMethod "closeFinish" o = Gio.IOStream.IOStreamCloseFinishMethodInfo
    ResolveSimpleIOStreamMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveSimpleIOStreamMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveSimpleIOStreamMethod "hasPending" o = Gio.IOStream.IOStreamHasPendingMethodInfo
    ResolveSimpleIOStreamMethod "isClosed" o = Gio.IOStream.IOStreamIsClosedMethodInfo
    ResolveSimpleIOStreamMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveSimpleIOStreamMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveSimpleIOStreamMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveSimpleIOStreamMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveSimpleIOStreamMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveSimpleIOStreamMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveSimpleIOStreamMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveSimpleIOStreamMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveSimpleIOStreamMethod "spliceAsync" o = Gio.IOStream.IOStreamSpliceAsyncMethodInfo
    ResolveSimpleIOStreamMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveSimpleIOStreamMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveSimpleIOStreamMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveSimpleIOStreamMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveSimpleIOStreamMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveSimpleIOStreamMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveSimpleIOStreamMethod "getInputStream" o = Gio.IOStream.IOStreamGetInputStreamMethodInfo
    ResolveSimpleIOStreamMethod "getOutputStream" o = Gio.IOStream.IOStreamGetOutputStreamMethodInfo
    ResolveSimpleIOStreamMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveSimpleIOStreamMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveSimpleIOStreamMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveSimpleIOStreamMethod "setPending" o = Gio.IOStream.IOStreamSetPendingMethodInfo
    ResolveSimpleIOStreamMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveSimpleIOStreamMethod l o = O.MethodResolutionFailed l o

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

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

--- XXX Duplicated object with different types:
  --- Name {namespace = "Gio", name = "SimpleIOStream"} -> Property {propName = "input-stream", propType = TInterface (Name {namespace = "Gio", name = "InputStream"}), propFlags = [PropertyReadable,PropertyWritable,PropertyConstructOnly], propReadNullable = Nothing, propWriteNullable = Nothing, propTransfer = TransferNothing, propDeprecated = Nothing}
  --- Name {namespace = "Gio", name = "IOStream"} -> Property {propName = "input-stream", propType = TInterface (Name {namespace = "Gio", name = "InputStream"}), propFlags = [PropertyReadable], propReadNullable = Nothing, propWriteNullable = Nothing, propTransfer = TransferNothing, propDeprecated = Nothing}
--- XXX Duplicated object with different types:
  --- Name {namespace = "Gio", name = "SimpleIOStream"} -> Property {propName = "output-stream", propType = TInterface (Name {namespace = "Gio", name = "OutputStream"}), propFlags = [PropertyReadable,PropertyWritable,PropertyConstructOnly], propReadNullable = Nothing, propWriteNullable = Nothing, propTransfer = TransferNothing, propDeprecated = Nothing}
  --- Name {namespace = "Gio", name = "IOStream"} -> Property {propName = "output-stream", propType = TInterface (Name {namespace = "Gio", name = "OutputStream"}), propFlags = [PropertyReadable], propReadNullable = Nothing, propWriteNullable = Nothing, propTransfer = TransferNothing, propDeprecated = Nothing}
-- VVV Prop "input-stream"
   -- Type: TInterface (Name {namespace = "Gio", name = "InputStream"})
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Nothing,Nothing)

getSimpleIOStreamInputStream :: (MonadIO m, IsSimpleIOStream o) => o -> m (Maybe Gio.InputStream.InputStream)
getSimpleIOStreamInputStream obj = liftIO $ getObjectPropertyObject obj "input-stream" Gio.InputStream.InputStream

constructSimpleIOStreamInputStream :: (IsSimpleIOStream o, Gio.InputStream.IsInputStream a) => a -> IO (GValueConstruct o)
constructSimpleIOStreamInputStream val = constructObjectPropertyObject "input-stream" (Just val)

data SimpleIOStreamInputStreamPropertyInfo
instance AttrInfo SimpleIOStreamInputStreamPropertyInfo where
    type AttrAllowedOps SimpleIOStreamInputStreamPropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint SimpleIOStreamInputStreamPropertyInfo = Gio.InputStream.IsInputStream
    type AttrBaseTypeConstraint SimpleIOStreamInputStreamPropertyInfo = IsSimpleIOStream
    type AttrGetType SimpleIOStreamInputStreamPropertyInfo = (Maybe Gio.InputStream.InputStream)
    type AttrLabel SimpleIOStreamInputStreamPropertyInfo = "input-stream"
    type AttrOrigin SimpleIOStreamInputStreamPropertyInfo = SimpleIOStream
    attrGet _ = getSimpleIOStreamInputStream
    attrSet _ = undefined
    attrConstruct _ = constructSimpleIOStreamInputStream
    attrClear _ = undefined

-- VVV Prop "output-stream"
   -- Type: TInterface (Name {namespace = "Gio", name = "OutputStream"})
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Nothing,Nothing)

getSimpleIOStreamOutputStream :: (MonadIO m, IsSimpleIOStream o) => o -> m (Maybe Gio.OutputStream.OutputStream)
getSimpleIOStreamOutputStream obj = liftIO $ getObjectPropertyObject obj "output-stream" Gio.OutputStream.OutputStream

constructSimpleIOStreamOutputStream :: (IsSimpleIOStream o, Gio.OutputStream.IsOutputStream a) => a -> IO (GValueConstruct o)
constructSimpleIOStreamOutputStream val = constructObjectPropertyObject "output-stream" (Just val)

data SimpleIOStreamOutputStreamPropertyInfo
instance AttrInfo SimpleIOStreamOutputStreamPropertyInfo where
    type AttrAllowedOps SimpleIOStreamOutputStreamPropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint SimpleIOStreamOutputStreamPropertyInfo = Gio.OutputStream.IsOutputStream
    type AttrBaseTypeConstraint SimpleIOStreamOutputStreamPropertyInfo = IsSimpleIOStream
    type AttrGetType SimpleIOStreamOutputStreamPropertyInfo = (Maybe Gio.OutputStream.OutputStream)
    type AttrLabel SimpleIOStreamOutputStreamPropertyInfo = "output-stream"
    type AttrOrigin SimpleIOStreamOutputStreamPropertyInfo = SimpleIOStream
    attrGet _ = getSimpleIOStreamOutputStream
    attrSet _ = undefined
    attrConstruct _ = constructSimpleIOStreamOutputStream
    attrClear _ = undefined

instance O.HasAttributeList SimpleIOStream
type instance O.AttributeList SimpleIOStream = SimpleIOStreamAttributeList
type SimpleIOStreamAttributeList = ('[ '("closed", Gio.IOStream.IOStreamClosedPropertyInfo), '("inputStream", SimpleIOStreamInputStreamPropertyInfo), '("outputStream", SimpleIOStreamOutputStreamPropertyInfo)] :: [(Symbol, *)])

simpleIOStreamInputStream :: AttrLabelProxy "inputStream"
simpleIOStreamInputStream = AttrLabelProxy

simpleIOStreamOutputStream :: AttrLabelProxy "outputStream"
simpleIOStreamOutputStream = AttrLabelProxy

type instance O.SignalList SimpleIOStream = SimpleIOStreamSignalList
type SimpleIOStreamSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method SimpleIOStream::new
-- method type : Constructor
-- Args : [Arg {argCName = "input_stream", argType = TInterface (Name {namespace = "Gio", name = "InputStream"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GInputStream.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "output_stream", argType = TInterface (Name {namespace = "Gio", name = "OutputStream"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GOutputStream.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "SimpleIOStream"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_simple_io_stream_new" g_simple_io_stream_new :: 
    Ptr Gio.InputStream.InputStream ->      -- input_stream : TInterface (Name {namespace = "Gio", name = "InputStream"})
    Ptr Gio.OutputStream.OutputStream ->    -- output_stream : TInterface (Name {namespace = "Gio", name = "OutputStream"})
    IO (Ptr SimpleIOStream)

{- |
Creates a new 'GI.Gio.Objects.SimpleIOStream.SimpleIOStream' wrapping /@inputStream@/ and /@outputStream@/.
See also 'GI.Gio.Objects.IOStream.IOStream'.

@since 2.44
-}
simpleIOStreamNew ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.InputStream.IsInputStream a, Gio.OutputStream.IsOutputStream b) =>
    a
    {- ^ /@inputStream@/: a 'GI.Gio.Objects.InputStream.InputStream'. -}
    -> b
    {- ^ /@outputStream@/: a 'GI.Gio.Objects.OutputStream.OutputStream'. -}
    -> m SimpleIOStream
    {- ^ __Returns:__ a new 'GI.Gio.Objects.SimpleIOStream.SimpleIOStream' instance. -}
simpleIOStreamNew inputStream outputStream = liftIO $ do
    inputStream' <- unsafeManagedPtrCastPtr inputStream
    outputStream' <- unsafeManagedPtrCastPtr outputStream
    result <- g_simple_io_stream_new inputStream' outputStream'
    checkUnexpectedReturnNULL "simpleIOStreamNew" result
    result' <- (wrapObject SimpleIOStream) result
    touchManagedPtr inputStream
    touchManagedPtr outputStream
    return result'