{-# LANGUAGE TypeApplications #-}
#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif
module GI.Gio.Interfaces.Initable
(
Initable(..) ,
IsInitable ,
toInitable ,
#if defined(ENABLE_OVERLOADING)
ResolveInitableMethod ,
#endif
#if defined(ENABLE_OVERLOADING)
InitableInitMethodInfo ,
#endif
initableInit ,
initableNewv ,
) 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
#if MIN_VERSION_base(4,18,0)
import qualified GI.GLib.Callbacks as GLib.Callbacks
import qualified GI.GLib.Structs.PollFD as GLib.PollFD
import qualified GI.GLib.Structs.Source as GLib.Source
import qualified GI.GObject.Callbacks as GObject.Callbacks
import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.GObject.Structs.Parameter as GObject.Parameter
import {-# SOURCE #-} qualified GI.Gio.Objects.Cancellable as Gio.Cancellable
#else
import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.GObject.Structs.Parameter as GObject.Parameter
import {-# SOURCE #-} qualified GI.Gio.Objects.Cancellable as Gio.Cancellable
#endif
newtype Initable = Initable (SP.ManagedPtr Initable)
deriving (Initable -> Initable -> Bool
(Initable -> Initable -> Bool)
-> (Initable -> Initable -> Bool) -> Eq Initable
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Initable -> Initable -> Bool
== :: Initable -> Initable -> Bool
$c/= :: Initable -> Initable -> Bool
/= :: Initable -> Initable -> Bool
Eq)
instance SP.ManagedPtrNewtype Initable where
toManagedPtr :: Initable -> ManagedPtr Initable
toManagedPtr (Initable ManagedPtr Initable
p) = ManagedPtr Initable
p
foreign import ccall "g_initable_get_type"
c_g_initable_get_type :: IO B.Types.GType
instance B.Types.TypedObject Initable where
glibType :: IO GType
glibType = IO GType
c_g_initable_get_type
instance B.Types.GObject Initable
class (SP.GObject o, O.IsDescendantOf Initable o) => IsInitable o
instance (SP.GObject o, O.IsDescendantOf Initable o) => IsInitable o
instance O.HasParentTypes Initable
type instance O.ParentTypes Initable = '[GObject.Object.Object]
toInitable :: (MIO.MonadIO m, IsInitable o) => o -> m Initable
toInitable :: forall (m :: * -> *) o.
(MonadIO m, IsInitable o) =>
o -> m Initable
toInitable = IO Initable -> m Initable
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
MIO.liftIO (IO Initable -> m Initable)
-> (o -> IO Initable) -> o -> m Initable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr Initable -> Initable) -> o -> IO Initable
forall o o'.
(HasCallStack, ManagedPtrNewtype o, TypedObject o,
ManagedPtrNewtype o', TypedObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
B.ManagedPtr.unsafeCastTo ManagedPtr Initable -> Initable
Initable
instance B.GValue.IsGValue (Maybe Initable) where
gvalueGType_ :: IO GType
gvalueGType_ = IO GType
c_g_initable_get_type
gvalueSet_ :: Ptr GValue -> Maybe Initable -> IO ()
gvalueSet_ Ptr GValue
gv Maybe Initable
P.Nothing = Ptr GValue -> Ptr Initable -> IO ()
forall a. GObject a => Ptr GValue -> Ptr a -> IO ()
B.GValue.set_object Ptr GValue
gv (Ptr Initable
forall a. Ptr a
FP.nullPtr :: FP.Ptr Initable)
gvalueSet_ Ptr GValue
gv (P.Just Initable
obj) = Initable -> (Ptr Initable -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Initable
obj (Ptr GValue -> Ptr Initable -> IO ()
forall a. GObject a => Ptr GValue -> Ptr a -> IO ()
B.GValue.set_object Ptr GValue
gv)
gvalueGet_ :: Ptr GValue -> IO (Maybe Initable)
gvalueGet_ Ptr GValue
gv = do
ptr <- Ptr GValue -> IO (Ptr Initable)
forall a. GObject a => Ptr GValue -> IO (Ptr a)
B.GValue.get_object Ptr GValue
gv :: IO (FP.Ptr Initable)
if ptr /= FP.nullPtr
then P.Just <$> B.ManagedPtr.newObject Initable ptr
else return P.Nothing
#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Initable
type instance O.AttributeList Initable = InitableAttributeList
type InitableAttributeList = ('[ ] :: [(Symbol, DK.Type)])
#endif
#if defined(ENABLE_OVERLOADING)
#endif
#if defined(ENABLE_OVERLOADING)
type family ResolveInitableMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
ResolveInitableMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
ResolveInitableMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
ResolveInitableMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
ResolveInitableMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
ResolveInitableMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
ResolveInitableMethod "init" o = InitableInitMethodInfo
ResolveInitableMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
ResolveInitableMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
ResolveInitableMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
ResolveInitableMethod "ref" o = GObject.Object.ObjectRefMethodInfo
ResolveInitableMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
ResolveInitableMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
ResolveInitableMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
ResolveInitableMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
ResolveInitableMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
ResolveInitableMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
ResolveInitableMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
ResolveInitableMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
ResolveInitableMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
ResolveInitableMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
ResolveInitableMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
ResolveInitableMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
ResolveInitableMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
ResolveInitableMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveInitableMethod t Initable, O.OverloadedMethod info Initable p) => OL.IsLabel t (Initable -> 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 ~ ResolveInitableMethod t Initable, O.OverloadedMethod info Initable p, R.HasField t Initable p) => R.HasField t Initable p where
getField = O.overloadedMethod @info
#endif
instance (info ~ ResolveInitableMethod t Initable, O.OverloadedMethodInfo info Initable) => OL.IsLabel t (O.MethodProxy info Initable) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.MethodProxy
#else
fromLabel _ = O.MethodProxy
#endif
#endif
foreign import ccall "g_initable_init" g_initable_init ::
Ptr Initable ->
Ptr Gio.Cancellable.Cancellable ->
Ptr (Ptr GError) ->
IO CInt
initableInit ::
(B.CallStack.HasCallStack, MonadIO m, IsInitable a, Gio.Cancellable.IsCancellable b) =>
a
-> Maybe (b)
-> m ()
initableInit :: forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsInitable a, IsCancellable b) =>
a -> Maybe b -> m ()
initableInit a
initable Maybe b
cancellable = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
initable' <- a -> IO (Ptr Initable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
initable
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
_ <- propagateGError $ g_initable_init initable' maybeCancellable
touchManagedPtr initable
whenJust cancellable touchManagedPtr
return ()
) (do
return ()
)
#if defined(ENABLE_OVERLOADING)
data InitableInitMethodInfo
instance (signature ~ (Maybe (b) -> m ()), MonadIO m, IsInitable a, Gio.Cancellable.IsCancellable b) => O.OverloadedMethod InitableInitMethodInfo a signature where
overloadedMethod = initableInit
instance O.OverloadedMethodInfo InitableInitMethodInfo a where
overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
O.resolvedSymbolName = "GI.Gio.Interfaces.Initable.initableInit",
O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gio-2.0.35/docs/GI-Gio-Interfaces-Initable.html#v:initableInit"
})
#endif
foreign import ccall "g_initable_newv" g_initable_newv ::
CGType ->
Word32 ->
Ptr GObject.Parameter.Parameter ->
Ptr Gio.Cancellable.Cancellable ->
Ptr (Ptr GError) ->
IO (Ptr GObject.Object.Object)
{-# DEPRECATED initableNewv ["(Since version 2.54)","Use @/g_object_new_with_properties()/@ and","'GI.Gio.Interfaces.Initable.initableInit' instead. See t'GI.GObject.Structs.Parameter.Parameter' for more information."] #-}
initableNewv ::
(B.CallStack.HasCallStack, MonadIO m, Gio.Cancellable.IsCancellable a) =>
GType
-> [GObject.Parameter.Parameter]
-> Maybe (a)
-> m GObject.Object.Object
initableNewv :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsCancellable a) =>
GType -> [Parameter] -> Maybe a -> m Object
initableNewv GType
objectType [Parameter]
parameters Maybe a
cancellable = IO Object -> m Object
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Object -> m Object) -> IO Object -> m Object
forall a b. (a -> b) -> a -> b
$ do
let nParameters :: Word32
nParameters = Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word32) -> Int -> Word32
forall a b. (a -> b) -> a -> b
$ [Parameter] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
P.length [Parameter]
parameters
let objectType' :: CGType
objectType' = GType -> CGType
gtypeToCGType GType
objectType
parameters' <- (Parameter -> IO (Ptr Parameter))
-> [Parameter] -> IO [Ptr Parameter]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Parameter -> IO (Ptr Parameter)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr [Parameter]
parameters
parameters'' <- packBlockArray 32 parameters'
maybeCancellable <- case cancellable of
Maybe a
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 a
jCancellable -> do
jCancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
jCancellable
return jCancellable'
onException (do
result <- propagateGError $ g_initable_newv objectType' nParameters parameters'' maybeCancellable
checkUnexpectedReturnNULL "initableNewv" result
result' <- (wrapObject GObject.Object.Object) result
mapM_ touchManagedPtr parameters
whenJust cancellable touchManagedPtr
freeMem parameters''
return result'
) (do
freeMem parameters''
)
#if defined(ENABLE_OVERLOADING)
#endif
#if defined(ENABLE_OVERLOADING)
type instance O.SignalList Initable = InitableSignalList
type InitableSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, DK.Type)])
#endif