Copyright | Will Thompson, Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (garetxe@gmail.com) |
Safe Haskell | None |
Language | Haskell2010 |
Initable
is implemented by objects that can fail during
initialization. If an object implements this interface then
it must be initialized as the first thing after construction,
either via initableInit
or asyncInitableInitAsync
(the latter is only available if it also implements AsyncInitable
).
If the object is not initialized, or initialization returns with an
error, then all operations on the object except objectRef
and
objectUnref
are considered to be invalid, and have undefined
behaviour. They will often fail with g_critical()
or g_warning()
, but
this must not be relied on.
Users of objects implementing this are not intended to use
the interface method directly, instead it will be used automatically
in various ways. For C applications you generally just call
g_initable_new()
directly, or indirectly via a foo_thing_new()
wrapper.
This will call initableInit
under the cover, returning Nothing
and
setting a GError
on failure (at which point the instance is
unreferenced).
For bindings in languages where the native constructor supports
exceptions the binding could check for objects implemention GInitable
during normal construction and automatically initialize them, throwing
an exception on failure.
- newtype Initable = Initable (ManagedPtr Initable)
- noInitable :: Maybe Initable
- class GObject o => IsInitable o
- toInitable :: IsInitable o => o -> IO Initable
- data InitableInitMethodInfo
- initableInit :: (HasCallStack, MonadIO m, IsInitable a, IsCancellable b) => a -> Maybe b -> m ()
- initableNewv :: (HasCallStack, MonadIO m, IsCancellable a) => GType -> [Parameter] -> Maybe a -> m Object
Exported types
GObject Initable Source # | |
IsObject Initable Source # | |
IsInitable Initable Source # | |
((~) * info (ResolveInitableMethod t Initable), MethodInfo * info Initable p) => IsLabel t (Initable -> p) Source # | |
((~) * info (ResolveInitableMethod t Initable), MethodInfo * info Initable p) => IsLabelProxy t (Initable -> p) Source # | |
HasAttributeList * Initable Source # | |
type AttributeList Initable Source # | |
type SignalList Initable Source # | |
class GObject o => IsInitable o Source #
toInitable :: IsInitable o => o -> IO Initable Source #
Methods
init
data InitableInitMethodInfo Source #
((~) * signature (Maybe b -> m ()), MonadIO m, IsInitable a, IsCancellable b) => MethodInfo * InitableInitMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsInitable a, IsCancellable b) | |
=> a |
|
-> Maybe b |
|
-> m () | (Can throw |
Initializes the object implementing the interface.
The object must be initialized before any real use after initial
construction, either with this function or asyncInitableInitAsync
.
Implementations may also support cancellation. If cancellable
is not Nothing
,
then initialization can be cancelled by triggering the cancellable object
from another thread. If the operation was cancelled, the error
IOErrorEnumCancelled
will be returned. If cancellable
is not Nothing
and
the object doesn't support cancellable initialization the error
IOErrorEnumNotSupported
will be returned.
If the object is not initialized, or initialization returns with an
error, then all operations on the object except objectRef
and
objectUnref
are considered to be invalid, and have undefined
behaviour. See the [introduction][ginitable] for more details.
Implementations of this method must be idempotent, i.e. multiple calls to this function with the same argument should return the same results. Only the first call initializes the object, further calls return the result of the first call. This is so that it's safe to implement the singleton pattern in the GObject constructor function.
Since: 2.22
newv
:: (HasCallStack, MonadIO m, IsCancellable a) | |
=> GType | |
-> [Parameter] |
|
-> Maybe a |
|
-> m Object | Returns: a newly allocated
|