{-# 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.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.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
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 qualified GI.GObject.Structs.Parameter as GObject.Parameter
import {-# SOURCE #-} qualified GI.Gio.Objects.Cancellable as Gio.Cancellable
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
/= :: Initable -> Initable -> Bool
$c/= :: Initable -> Initable -> Bool
== :: Initable -> Initable -> Bool
$c== :: 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
instance B.GValue.IsGValue Initable where
toGValue :: Initable -> IO GValue
toGValue Initable
o = do
GType
gtype <- IO GType
c_g_initable_get_type
Initable -> (Ptr Initable -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Initable
o (GType
-> (GValue -> Ptr Initable -> IO ()) -> Ptr Initable -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr Initable -> IO ()
forall a. GObject a => GValue -> Ptr a -> IO ()
B.GValue.set_object)
fromGValue :: GValue -> IO Initable
fromGValue GValue
gv = do
Ptr Initable
ptr <- GValue -> IO (Ptr Initable)
forall b. GObject b => GValue -> IO (Ptr b)
B.GValue.get_object GValue
gv :: IO (Ptr Initable)
(ManagedPtr Initable -> Initable) -> Ptr Initable -> IO Initable
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
B.ManagedPtr.newObject ManagedPtr Initable -> Initable
Initable Ptr Initable
ptr
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 :: (MonadIO m, IsInitable o) => o -> m Initable
toInitable :: o -> m Initable
toInitable = IO Initable -> m Initable
forall (m :: * -> *) a. MonadIO m => IO a -> m a
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'
unsafeCastTo ManagedPtr Initable -> Initable
Initable
#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Initable
type instance O.AttributeList Initable = InitableAttributeList
type InitableAttributeList = ('[ ] :: [(Symbol, *)])
#endif
#if defined(ENABLE_OVERLOADING)
#endif
#if defined(ENABLE_OVERLOADING)
type family ResolveInitableMethod (t :: Symbol) (o :: *) :: * 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.MethodInfo 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
#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 :: a -> Maybe b -> m ()
initableInit a
initable Maybe b
cancellable = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Ptr Initable
initable' <- a -> IO (Ptr Initable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
initable
Ptr Cancellable
maybeCancellable <- case Maybe b
cancellable of
Maybe b
Nothing -> Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
forall a. Ptr a
nullPtr
Just b
jCancellable -> do
Ptr Cancellable
jCancellable' <- b -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
jCancellable
Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
jCancellable'
IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
onException (do
CInt
_ <- (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CInt) -> IO CInt)
-> (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Ptr Initable -> Ptr Cancellable -> Ptr (Ptr GError) -> IO CInt
g_initable_init Ptr Initable
initable' Ptr Cancellable
maybeCancellable
a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
initable
Maybe b -> (b -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe b
cancellable b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
) (do
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
)
#if defined(ENABLE_OVERLOADING)
data InitableInitMethodInfo
instance (signature ~ (Maybe (b) -> m ()), MonadIO m, IsInitable a, Gio.Cancellable.IsCancellable b) => O.MethodInfo InitableInitMethodInfo a signature where
overloadedMethod = 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 :: GType -> [Parameter] -> Maybe a -> m Object
initableNewv GType
objectType [Parameter]
parameters Maybe a
cancellable = IO Object -> m Object
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 (t :: * -> *) a. Foldable t => t a -> Int
P.length [Parameter]
parameters
let objectType' :: CGType
objectType' = GType -> CGType
gtypeToCGType GType
objectType
[Ptr Parameter]
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)
mapM Parameter -> IO (Ptr Parameter)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr [Parameter]
parameters
Ptr Parameter
parameters'' <- Int -> [Ptr Parameter] -> IO (Ptr Parameter)
forall a. Int -> [Ptr a] -> IO (Ptr a)
packBlockArray Int
32 [Ptr Parameter]
parameters'
Ptr Cancellable
maybeCancellable <- case Maybe a
cancellable of
Maybe a
Nothing -> Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
forall a. Ptr a
nullPtr
Just a
jCancellable -> do
Ptr Cancellable
jCancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
jCancellable
Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
jCancellable'
IO Object -> IO () -> IO Object
forall a b. IO a -> IO b -> IO a
onException (do
Ptr Object
result <- (Ptr (Ptr GError) -> IO (Ptr Object)) -> IO (Ptr Object)
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr Object)) -> IO (Ptr Object))
-> (Ptr (Ptr GError) -> IO (Ptr Object)) -> IO (Ptr Object)
forall a b. (a -> b) -> a -> b
$ CGType
-> Word32
-> Ptr Parameter
-> Ptr Cancellable
-> Ptr (Ptr GError)
-> IO (Ptr Object)
g_initable_newv CGType
objectType' Word32
nParameters Ptr Parameter
parameters'' Ptr Cancellable
maybeCancellable
Text -> Ptr Object -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"initableNewv" Ptr Object
result
Object
result' <- ((ManagedPtr Object -> Object) -> Ptr Object -> IO Object
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr Object -> Object
GObject.Object.Object) Ptr Object
result
(Parameter -> IO ()) -> [Parameter] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Parameter -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr [Parameter]
parameters
Maybe a -> (a -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe a
cancellable a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
Ptr Parameter -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Parameter
parameters''
Object -> IO Object
forall (m :: * -> *) a. Monad m => a -> m a
return Object
result'
) (do
Ptr Parameter -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Parameter
parameters''
)
#if defined(ENABLE_OVERLOADING)
#endif
#if defined(ENABLE_OVERLOADING)
type instance O.SignalList Initable = InitableSignalList
type InitableSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])
#endif