{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- /No description available in the introspection data./

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

module GI.OSTree.Interfaces.BlobReader
    ( 

-- * Exported types
    BlobReader(..)                          ,
    IsBlobReader                            ,
    toBlobReader                            ,


 -- * 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"), [readBlob]("GI.OSTree.Interfaces.BlobReader#g:method:readBlob"), [ref]("GI.GObject.Objects.Object#g:method:ref"), [refSink]("GI.GObject.Objects.Object#g:method:refSink"), [runDispose]("GI.GObject.Objects.Object#g:method:runDispose"), [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"), [getProperty]("GI.GObject.Objects.Object#g:method:getProperty"), [getQdata]("GI.GObject.Objects.Object#g:method:getQdata").
-- 
-- ==== 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)
    ResolveBlobReaderMethod                 ,
#endif

-- ** readBlob #method:readBlob#

#if defined(ENABLE_OVERLOADING)
    BlobReaderReadBlobMethodInfo            ,
#endif
    blobReaderReadBlob                      ,




    ) 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.GLib.Structs.Bytes as GLib.Bytes
import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.Gio.Objects.Cancellable as Gio.Cancellable

#else
import qualified GI.GLib.Structs.Bytes as GLib.Bytes
import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.Gio.Objects.Cancellable as Gio.Cancellable

#endif

-- interface BlobReader 
-- | Memory-managed wrapper type.
newtype BlobReader = BlobReader (SP.ManagedPtr BlobReader)
    deriving (BlobReader -> BlobReader -> Bool
(BlobReader -> BlobReader -> Bool)
-> (BlobReader -> BlobReader -> Bool) -> Eq BlobReader
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BlobReader -> BlobReader -> Bool
== :: BlobReader -> BlobReader -> Bool
$c/= :: BlobReader -> BlobReader -> Bool
/= :: BlobReader -> BlobReader -> Bool
Eq)

instance SP.ManagedPtrNewtype BlobReader where
    toManagedPtr :: BlobReader -> ManagedPtr BlobReader
toManagedPtr (BlobReader ManagedPtr BlobReader
p) = ManagedPtr BlobReader
p

foreign import ccall "ostree_blob_reader_get_type"
    c_ostree_blob_reader_get_type :: IO B.Types.GType

instance B.Types.TypedObject BlobReader where
    glibType :: IO GType
glibType = IO GType
c_ostree_blob_reader_get_type

instance B.Types.GObject BlobReader

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

instance O.HasParentTypes BlobReader
type instance O.ParentTypes BlobReader = '[GObject.Object.Object]

-- | Cast to t'BlobReader', for types for which this is known to be safe. For general casts, use 'Data.GI.Base.ManagedPtr.castTo'.
toBlobReader :: (MIO.MonadIO m, IsBlobReader o) => o -> m BlobReader
toBlobReader :: forall (m :: * -> *) o.
(MonadIO m, IsBlobReader o) =>
o -> m BlobReader
toBlobReader = IO BlobReader -> m BlobReader
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
MIO.liftIO (IO BlobReader -> m BlobReader)
-> (o -> IO BlobReader) -> o -> m BlobReader
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr BlobReader -> BlobReader) -> o -> IO BlobReader
forall o o'.
(HasCallStack, ManagedPtrNewtype o, TypedObject o,
 ManagedPtrNewtype o', TypedObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
B.ManagedPtr.unsafeCastTo ManagedPtr BlobReader -> BlobReader
BlobReader

-- | Convert t'BlobReader' 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 BlobReader) where
    gvalueGType_ :: IO GType
gvalueGType_ = IO GType
c_ostree_blob_reader_get_type
    gvalueSet_ :: Ptr GValue -> Maybe BlobReader -> IO ()
gvalueSet_ Ptr GValue
gv Maybe BlobReader
P.Nothing = Ptr GValue -> Ptr BlobReader -> IO ()
forall a. GObject a => Ptr GValue -> Ptr a -> IO ()
B.GValue.set_object Ptr GValue
gv (Ptr BlobReader
forall a. Ptr a
FP.nullPtr :: FP.Ptr BlobReader)
    gvalueSet_ Ptr GValue
gv (P.Just BlobReader
obj) = BlobReader -> (Ptr BlobReader -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr BlobReader
obj (Ptr GValue -> Ptr BlobReader -> IO ()
forall a. GObject a => Ptr GValue -> Ptr a -> IO ()
B.GValue.set_object Ptr GValue
gv)
    gvalueGet_ :: Ptr GValue -> IO (Maybe BlobReader)
gvalueGet_ Ptr GValue
gv = do
        ptr <- Ptr GValue -> IO (Ptr BlobReader)
forall a. GObject a => Ptr GValue -> IO (Ptr a)
B.GValue.get_object Ptr GValue
gv :: IO (FP.Ptr BlobReader)
        if ptr /= FP.nullPtr
        then P.Just <$> B.ManagedPtr.newObject BlobReader ptr
        else return P.Nothing
        
    

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

#if defined(ENABLE_OVERLOADING)
#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveBlobReaderMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
    ResolveBlobReaderMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveBlobReaderMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveBlobReaderMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveBlobReaderMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveBlobReaderMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveBlobReaderMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveBlobReaderMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveBlobReaderMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveBlobReaderMethod "readBlob" o = BlobReaderReadBlobMethodInfo
    ResolveBlobReaderMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveBlobReaderMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveBlobReaderMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveBlobReaderMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveBlobReaderMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveBlobReaderMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveBlobReaderMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveBlobReaderMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveBlobReaderMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveBlobReaderMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveBlobReaderMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveBlobReaderMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveBlobReaderMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveBlobReaderMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveBlobReaderMethod l o = O.MethodResolutionFailed l o

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

#endif

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

#endif

-- method BlobReader::read_blob
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "self"
--           , argType =
--               TInterface Name { namespace = "OSTree" , name = "BlobReader" }
--           , argCType = Just "OstreeBlobReader*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "A OstreeBlobReader" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , argCType = Just "GCancellable*"
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GCancellable" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "GLib" , name = "Bytes" })
-- throws : True
-- Skip return : False

foreign import ccall "ostree_blob_reader_read_blob" ostree_blob_reader_read_blob :: 
    Ptr BlobReader ->                       -- self : TInterface (Name {namespace = "OSTree", name = "BlobReader"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr GLib.Bytes.Bytes)

-- | Read one blob from the reader, or 'P.Nothing' if there are no more.
-- On error, /@error@/ is set and 'P.Nothing' is returned.
-- 
-- /Since: 2016.5/
blobReaderReadBlob ::
    (B.CallStack.HasCallStack, MonadIO m, IsBlobReader a, Gio.Cancellable.IsCancellable b) =>
    a
    -- ^ /@self@/: A OstreeBlobReader
    -> Maybe (b)
    -- ^ /@cancellable@/: a t'GI.Gio.Objects.Cancellable.Cancellable'
    -> m (Maybe GLib.Bytes.Bytes)
    -- ^ __Returns:__ A t'GI.GLib.Structs.Bytes.Bytes' blob, or 'P.Nothing' if there are no more /(Can throw 'Data.GI.Base.GError.GError')/
blobReaderReadBlob :: forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsBlobReader a, IsCancellable b) =>
a -> Maybe b -> m (Maybe Bytes)
blobReaderReadBlob a
self Maybe b
cancellable = IO (Maybe Bytes) -> m (Maybe Bytes)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Bytes) -> m (Maybe Bytes))
-> IO (Maybe Bytes) -> m (Maybe Bytes)
forall a b. (a -> b) -> a -> b
$ do
    self' <- a -> IO (Ptr BlobReader)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
self
    maybeCancellable <- case cancellable of
        Maybe b
Nothing -> Ptr Cancellable -> IO (Ptr Cancellable)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
forall a. Ptr a
FP.nullPtr
        Just b
jCancellable -> do
            jCancellable' <- b -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
jCancellable
            return jCancellable'
    onException (do
        result <- propagateGError $ ostree_blob_reader_read_blob self' maybeCancellable
        maybeResult <- convertIfNonNull result $ \Ptr Bytes
result' -> do
            result'' <- ((ManagedPtr Bytes -> Bytes) -> Ptr Bytes -> IO Bytes
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Bytes -> Bytes
GLib.Bytes.Bytes) Ptr Bytes
result'
            return result''
        touchManagedPtr self
        whenJust cancellable touchManagedPtr
        return maybeResult
     ) (do
        return ()
     )

#if defined(ENABLE_OVERLOADING)
data BlobReaderReadBlobMethodInfo
instance (signature ~ (Maybe (b) -> m (Maybe GLib.Bytes.Bytes)), MonadIO m, IsBlobReader a, Gio.Cancellable.IsCancellable b) => O.OverloadedMethod BlobReaderReadBlobMethodInfo a signature where
    overloadedMethod = blobReaderReadBlob

instance O.OverloadedMethodInfo BlobReaderReadBlobMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.OSTree.Interfaces.BlobReader.blobReaderReadBlob",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-ostree-1.0.19/docs/GI-OSTree-Interfaces-BlobReader.html#v:blobReaderReadBlob"
        })


#endif

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

#endif