Package ch.bailu.gtk.glib
Klasse Source
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.type.Record
ch.bailu.gtk.glib.Source
- Alle implementierten Schnittstellen:
PointerInterface
The `GSource` struct is an opaque data type
representing an event source.
representing an event source.
-
Verschachtelte Klassen - Übersicht
Verschachtelte KlassenModifizierer und TypKlasseBeschreibungstatic interface
static interface
static interface
-
Feldübersicht
Felder -
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungSource()
Source
(SourceFuncs source_funcs, int struct_size) Creates a new [struct@GLib.Source] structure.Source
(PointerContainer pointer) -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoid
addChildSource
(Source child_source) Adds @child_source to @source as a "polled" source; when @source is
added to a [struct@GLib.MainContext], @child_source will be automatically
added with the same priority, when @child_source is triggered, it will
cause @source to dispatch (in addition to calling its own
callback), and when @source is destroyed, it will destroy
@child_source as wellvoid
Adds a file descriptor to the set of file descriptors polled for
this source.addUnixFd
(int fd, int events) Monitors @fd for the IO events in @events.int
attach
(MainContext context) Adds a [struct@GLib.Source] to a @context so that it will be executed within
that context.void
destroy()
Removes a source from its [struct@GLib.MainContext], if any, and mark it as
destroyed.boolean
Checks whether a source is allowed to be called recursively.static ClassHandler
Gets the [struct@GLib.MainContext] with which the source is associated.void
getCurrentTime
(TimeVal timeval) Veraltet.int
int
ch.bailu.gtk.glib.SourcePrivate
int
int
int
getId()
Returns the numeric ID for a particular source.static int
getName()
Gets a name for the source, used in debugging and profiling.static long
static TypeSystem.TypeSize
int
Gets the priority of a source.long
Gets the "ready time" of @source, as set by
[method@GLib.Source.set_ready_time].long
getTime()
Gets the time to be used when checking this source.static long
static TypeSystem.TypeSize
boolean
Returns whether @source has been destroyed.void
modifyUnixFd
(Pointer tag, int new_events) Updates the event mask to watch for the fd identified by @tag.int
queryUnixFd
(Pointer tag) Queries the events reported for the fd corresponding to @tag on
@source during the last poll.ref()
Increases the reference count on a source by one.static boolean
remove
(int tag) Removes the source with the given ID from the default main context.static boolean
removeByFuncsUserData
(SourceFuncs funcs, Pointer user_data) Removes a source from the default main loop context given the
source functions and user data.static boolean
removeByUserData
(Pointer user_data) Removes a source from the default main loop context given the user
data for the callback.void
removeChildSource
(Source child_source) Detaches @child_source from @source and destroys it.void
removePoll
(PollFD fd) Removes a file descriptor from the set of file descriptors polled for
this source.void
removeUnixFd
(Pointer tag) Reverses the effect of a previous call to [method@GLib.Source.add_unix_fd].void
setCallback
(Source.OnSourceFunc func, Pointer data, Source.OnDestroyNotify notify) Sets the callback function for a source.void
setCallbackIndirect
(Pointer callback_data, SourceCallbackFuncs callback_funcs) Sets the callback function storing the data as a refcounted callback
"object".void
setCanRecurse
(boolean can_recurse) Sets whether a source can be called recursively.void
Set @dispose as dispose function on @source.void
setFuncs
(SourceFuncs funcs) Sets the source functions (can be used to override
default implementations) of an unattached source.void
Sets a name for the source, used in debugging and profiling.void
Sets a name for the source, used in debugging and profiling.static void
setNameById
(int tag, Str name) Sets the name of a source using its ID.void
setPriority
(int priority) Sets the priority of a source.void
setReadyTime
(long ready_time) Sets a #GSource to be dispatched when the given monotonic time is
reached (or passed).void
setStaticName
(Str name) A variant of [method@GLib.Source.set_name] that does not
duplicate the @name, and can only be used with
string literals.void
setStaticName
(String name) A variant of [method@GLib.Source.set_name] that does not
duplicate the @name, and can only be used with
string literals.void
unref()
Decreases the reference count of a source by one.Von Klasse geerbte Methoden ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Von Klasse geerbte Methoden ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Von Klasse geerbte Methoden java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Von Schnittstelle geerbte Methoden ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Felddetails
-
CALLBACK_DATA
- Siehe auch:
-
CALLBACK_FUNCS
- Siehe auch:
-
SOURCE_FUNCS
- Siehe auch:
-
REF_COUNT
- Siehe auch:
-
CONTEXT
- Siehe auch:
-
PRIORITY
- Siehe auch:
-
FLAGS
- Siehe auch:
-
SOURCE_ID
- Siehe auch:
-
POLL_FDS
- Siehe auch:
-
PREV
- Siehe auch:
-
NEXT
- Siehe auch:
-
NAME
- Siehe auch:
-
PRIV
- Siehe auch:
-
-
Konstruktordetails
-
Source
-
Source
public Source() -
Source
Creates a new [struct@GLib.Source] structure. The size is specified to
allow creating structures derived from [struct@GLib.Source] that contain
additional data. The size passed in must be at least
`sizeof (GSource)`.
The source will not initially be associated with any #GMainContext
and must be added to one with [method@GLib.Source.attach] before it will be
executed.- Parameter:
source_funcs
- structure containing functions that implement the sources behavior.struct_size
- size of the [struct@GLib.Source] structure to create.
-
-
Methodendetails
-
getClassHandler
-
getFieldCallbackData
-
getFieldCallbackFuncs
-
getFieldSourceFuncs
-
getFieldRefCount
public int getFieldRefCount() -
getFieldContext
-
getFieldPriority
public int getFieldPriority() -
getFieldFlags
public int getFieldFlags() -
getFieldSourceId
public int getFieldSourceId() -
getFieldPollFds
-
getFieldPrev
-
getFieldNext
-
getFieldName
-
getFieldPriv
public ch.bailu.gtk.glib.SourcePrivate getFieldPriv() -
addChildSource
Adds @child_source to @source as a "polled" source; when @source is
added to a [struct@GLib.MainContext], @child_source will be automatically
added with the same priority, when @child_source is triggered, it will
cause @source to dispatch (in addition to calling its own
callback), and when @source is destroyed, it will destroy
@child_source as well. (@source will also still be dispatched if
its own prepare/check functions indicate that it is ready.)
If you don't need @child_source to do anything on its own when it
triggers, you can call g_source_set_dummy_callback() on it to set a
callback that does nothing (except return %TRUE if appropriate).
@source will hold a reference on @child_source while @child_source
is attached to it.
This API is only intended to be used by implementations of
[struct@GLib.Source]. Do not call this API on a [struct@GLib.Source] that
you did not create.- Parameter:
child_source
- a second #GSource that @source should "poll"
-
addPoll
Adds a file descriptor to the set of file descriptors polled for
this source. This is usually combined with [ctor@GLib.Source.new] to add an
event source. The event source's check function will typically test
the @revents field in the #GPollFD struct and return %TRUE if events need
to be processed.
This API is only intended to be used by implementations of [struct@GLib.Source].
Do not call this API on a [struct@GLib.Source] that you did not create.
Using this API forces the linear scanning of event sources on each
main loop iteration. Newly-written event sources should try to use
`g_source_add_unix_fd` instead of this API.- Parameter:
fd
- a #GPollFD structure holding information about a file descriptor to watch.
-
addUnixFd
Monitors @fd for the IO events in @events.
The tag returned by this function can be used to remove or modify the
monitoring of the fd using [method@GLib.Source.remove_unix_fd] or
[method@GLib.Source.modify_unix_fd].
It is not necessary to remove the fd before destroying the source; it
will be cleaned up automatically.
This API is only intended to be used by implementations of #GSource.
Do not call this API on a #GSource that you did not create.
As the name suggests, this function is not available on Windows.- Parameter:
fd
- the fd to monitorevents
- an event mask- Gibt zurück:
- an opaque tag
-
attach
Adds a [struct@GLib.Source] to a @context so that it will be executed within
that context. Remove it by calling [method@GLib.Source.destroy].
This function is safe to call from any thread, regardless of which thread
the @context is running in.- Parameter:
context
- a #GMainContext (if %NULL, the global-default main context will be used)- Gibt zurück:
- the ID (greater than 0) for the source within the #GMainContext.
-
destroy
public void destroy()Removes a source from its [struct@GLib.MainContext], if any, and mark it as
destroyed. The source cannot be subsequently added to another
context. It is safe to call this on sources which have already been
removed from their context.
This does not unref the [struct@GLib.Source]: if you still hold a reference,
use [method@GLib.Source.unref] to drop it.
This function is safe to call from any thread, regardless of which thread
the [struct@GLib.MainContext] is running in.
If the source is currently attached to a [struct@GLib.MainContext],
destroying it will effectively unset the callback similar to calling
[method@GLib.Source.set_callback]. This can mean, that the data's
#GDestroyNotify gets called right away. -
getCanRecurse
public boolean getCanRecurse()Checks whether a source is allowed to be called recursively.
see [method@GLib.Source.set_can_recurse].- Gibt zurück:
- whether recursion is allowed.
-
getContext
Gets the [struct@GLib.MainContext] with which the source is associated.
You can call this on a source that has been destroyed, provided
that the [struct@GLib.MainContext] it was attached to still exists (in which
case it will return that [struct@GLib.MainContext]). In particular, you can
always call this function on the source returned from
[func@GLib.main_current_source]. But calling this function on a source
whose [struct@GLib.MainContext] has been destroyed is an error.- Gibt zurück:
- the #GMainContext with which the source is associated, or %NULL if the context has not yet been added to a source.
-
getCurrentTime
Veraltet.This function ignores @source and is otherwise the same as
[func@GLib.get_current_time].- Parameter:
timeval
- #GTimeVal structure in which to store current time.
-
getId
public int getId()Returns the numeric ID for a particular source. The ID of a source
is a positive integer which is unique within a particular main loop
context. The reverse mapping from ID to source is done by
[method@GLib.MainContext.find_source_by_id].
You can only call this function while the source is associated to a
[struct@GLib.MainContext] instance; calling this function before
[method@GLib.Source.attach] or after [method@GLib.Source.destroy] yields
undefined behavior. The ID returned is unique within the
[struct@GLib.MainContext] instance passed to [method@GLib.Source.attach].- Gibt zurück:
- the ID (greater than 0) for the source
-
getName
Gets a name for the source, used in debugging and profiling. The
name may be #NULL if it has never been set with [method@GLib.Source.set_name].- Gibt zurück:
- the name of the source
-
getPriority
public int getPriority()Gets the priority of a source.- Gibt zurück:
- the priority of the source
-
getReadyTime
public long getReadyTime()Gets the "ready time" of @source, as set by
[method@GLib.Source.set_ready_time].
Any time before or equal to the current monotonic time (including 0)
is an indication that the source will fire immediately.- Gibt zurück:
- the monotonic ready time, -1 for "never"
-
getTime
public long getTime()Gets the time to be used when checking this source. The advantage of
calling this function over calling [func@GLib.get_monotonic_time] directly is
that when checking multiple sources, GLib can cache a single value
instead of having to repeatedly get the system monotonic time.
The time here is the system monotonic time, if available, or some
other reasonable alternative otherwise. See [func@GLib.get_monotonic_time].- Gibt zurück:
- the monotonic time in microseconds
-
isDestroyed
public boolean isDestroyed()Returns whether @source has been destroyed.
This is important when you operate upon your objects
from within idle handlers, but may have freed the object
before the dispatch of your idle handler.
<!-- language="C" --> static gboolean idle_callback (gpointer data) { SomeWidget *self = data; g_mutex_lock (&self->idle_id_mutex); // do stuff with self self->idle_id = 0; g_mutex_unlock (&self->idle_id_mutex); return G_SOURCE_REMOVE; } static void some_widget_do_stuff_later (SomeWidget *self) { g_mutex_lock (&self->idle_id_mutex); self->idle_id = g_idle_add (idle_callback, self); g_mutex_unlock (&self->idle_id_mutex); } static void some_widget_init (SomeWidget *self) { g_mutex_init (&self->idle_id_mutex); // ... } static void some_widget_finalize (GObject *object) { SomeWidget *self = SOME_WIDGET (object); if (self->idle_id) g_source_remove (self->idle_id); g_mutex_clear (&self->idle_id_mutex); G_OBJECT_CLASS (parent_class)->finalize (object); }
This will fail in a multi-threaded application if the
widget is destroyed before the idle handler fires due
to the use after free in the callback. A solution, to
this particular problem, is to check to if the source
has already been destroy within the callback.
<!-- language="C" --> static gboolean idle_callback (gpointer data) { SomeWidget *self = data; g_mutex_lock (&self->idle_id_mutex); if (!g_source_is_destroyed (g_main_current_source ())) { // do stuff with self } g_mutex_unlock (&self->idle_id_mutex); return FALSE; }
Calls to this function from a thread other than the one acquired by the
[struct@GLib.MainContext] the #GSource is attached to are typically
redundant, as the source could be destroyed immediately after this function
returns. However, once a source is destroyed it cannot be un-destroyed, so
this function can be used for opportunistic checks from any thread.- Gibt zurück:
- %TRUE if the source has been destroyed
-
modifyUnixFd
Updates the event mask to watch for the fd identified by @tag.
@tag is the tag returned from [method@GLib.Source.add_unix_fd].
If you want to remove a fd, don't set its event mask to zero.
Instead, call [method@GLib.Source.remove_unix_fd].
This API is only intended to be used by implementations of #GSource.
Do not call this API on a #GSource that you did not create.
As the name suggests, this function is not available on Windows.- Parameter:
tag
- the tag from [method@GLib.Source.add_unix_fd]new_events
- the new event mask to watch
-
queryUnixFd
Queries the events reported for the fd corresponding to @tag on
@source during the last poll.
The return value of this function is only defined when the function
is called from the check or dispatch functions for @source.
This API is only intended to be used by implementations of #GSource.
Do not call this API on a #GSource that you did not create.
As the name suggests, this function is not available on Windows.- Parameter:
tag
- the tag from [method@GLib.Source.add_unix_fd]- Gibt zurück:
- the conditions reported on the fd
-
ref
Increases the reference count on a source by one.- Gibt zurück:
- @source
-
removeChildSource
Detaches @child_source from @source and destroys it.
This API is only intended to be used by implementations of #GSource.
Do not call this API on a #GSource that you did not create.- Parameter:
child_source
- a #GSource previously passed to [method@GLib.Source.add_child_source].
-
removePoll
Removes a file descriptor from the set of file descriptors polled for
this source.
This API is only intended to be used by implementations of [struct@GLib.Source].
Do not call this API on a [struct@GLib.Source] that you did not create.- Parameter:
fd
- a #GPollFD structure previously passed to [method@GLib.Source.add_poll].
-
removeUnixFd
Reverses the effect of a previous call to [method@GLib.Source.add_unix_fd].
You only need to call this if you want to remove an fd from being
watched while keeping the same source around. In the normal case you
will just want to destroy the source.
This API is only intended to be used by implementations of #GSource.
Do not call this API on a #GSource that you did not create.
As the name suggests, this function is not available on Windows.- Parameter:
tag
- the tag from [method@GLib.Source.add_unix_fd]
-
setCallback
public void setCallback(Source.OnSourceFunc func, @Nullable Pointer data, Source.OnDestroyNotify notify) Sets the callback function for a source. The callback for a source is
called from the source's dispatch function.
The exact type of @func depends on the type of source; ie. you
should not count on @func being called with @data as its first
parameter. Cast @func with [func@GLib.SOURCE_FUNC] to avoid warnings about
incompatible function types.
See [mainloop memory management](main-loop.html#memory-management-of-sources) for details
on how to handle memory management of @data.
Typically, you won't use this function. Instead use functions specific
to the type of source you are using, such as [func@GLib.idle_add] or
[func@GLib.timeout_add].
It is safe to call this function multiple times on a source which has already
been attached to a context. The changes will take effect for the next time
the source is dispatched after this call returns.
Note that [method@GLib.Source.destroy] for a currently attached source has the effect
of also unsetting the callback.- Parameter:
func
- a callback functiondata
- the data to pass to callback functionnotify
- a function to call when @data is no longer in use, or %NULL.
-
setCallbackIndirect
public void setCallbackIndirect(@Nullable Pointer callback_data, @Nonnull SourceCallbackFuncs callback_funcs) Sets the callback function storing the data as a refcounted callback
"object". This is used internally. Note that calling
[method@GLib.Source.set_callback_indirect] assumes
an initial reference count on @callback_data, and thus
@callback_funcs->unref will eventually be called once more
than @callback_funcs->ref.
It is safe to call this function multiple times on a source which has already
been attached to a context. The changes will take effect for the next time
the source is dispatched after this call returns.- Parameter:
callback_data
- pointer to callback data "object"callback_funcs
- functions for reference counting @callback_data and getting the callback and data
-
setCanRecurse
public void setCanRecurse(boolean can_recurse) Sets whether a source can be called recursively. If @can_recurse is
%TRUE, then while the source is being dispatched then this source
will be processed normally. Otherwise, all processing of this
source is blocked until the dispatch function returns.- Parameter:
can_recurse
- whether recursion is allowed for this source
-
setDisposeFunction
Set @dispose as dispose function on @source. @dispose will be called once
the reference count of @source reaches 0 but before any of the state of the
source is freed, especially before the finalize function is called.
This means that at this point @source is still a valid [struct@GLib.Source]
and it is allow for the reference count to increase again until @dispose
returns.
The dispose function can be used to clear any "weak" references to the
@source in other data structures in a thread-safe way where it is possible
for another thread to increase the reference count of @source again while
it is being freed.
The finalize function can not be used for this purpose as at that point
@source is already partially freed and not valid anymore.
This should only ever be called from #GSource implementations.- Parameter:
dispose
- #GSourceDisposeFunc to set on the source
-
setFuncs
Sets the source functions (can be used to override
default implementations) of an unattached source.- Parameter:
funcs
- the new #GSourceFuncs
-
setName
Sets a name for the source, used in debugging and profiling.
The name defaults to #NULL.
The source name should describe in a human-readable way
what the source does. For example, "X11 event queue"
or "GTK repaint idle handler" or whatever it is.
It is permitted to call this function multiple times, but is not
recommended due to the potential performance impact. For example,
one could change the name in the "check" function of a #GSourceFuncs
to include details like the event type in the source name.
Use caution if changing the name while another thread may be
accessing it with [method@GLib.Source.get_name]; that function does not copy
the value, and changing the value will free it while the other thread
may be attempting to use it.
Also see [method@GLib.Source.set_static_name].- Parameter:
name
- debug name for the source
-
setName
Sets a name for the source, used in debugging and profiling.
The name defaults to #NULL.
The source name should describe in a human-readable way
what the source does. For example, "X11 event queue"
or "GTK repaint idle handler" or whatever it is.
It is permitted to call this function multiple times, but is not
recommended due to the potential performance impact. For example,
one could change the name in the "check" function of a #GSourceFuncs
to include details like the event type in the source name.
Use caution if changing the name while another thread may be
accessing it with [method@GLib.Source.get_name]; that function does not copy
the value, and changing the value will free it while the other thread
may be attempting to use it.
Also see [method@GLib.Source.set_static_name].- Parameter:
name
- debug name for the source
-
setPriority
public void setPriority(int priority) Sets the priority of a source. While the main loop is being run, a
source will be dispatched if it is ready to be dispatched and no
sources at a higher (numerically smaller) priority are ready to be
dispatched.
A child source always has the same priority as its parent. It is not
permitted to change the priority of a source once it has been added
as a child of another source.- Parameter:
priority
- the new priority.
-
setReadyTime
public void setReadyTime(long ready_time) Sets a #GSource to be dispatched when the given monotonic time is
reached (or passed). If the monotonic time is in the past (as it
always will be if @ready_time is 0) then the source will be
dispatched immediately.
If @ready_time is -1 then the source is never woken up on the basis
of the passage of time.
Dispatching the source does not reset the ready time. You should do
so yourself, from the source dispatch function.
Note that if you have a pair of sources where the ready time of one
suggests that it will be delivered first but the priority for the
other suggests that it would be delivered first, and the ready time
for both sources is reached during the same main context iteration,
then the order of dispatch is undefined.
It is a no-op to call this function on a #GSource which has already been
destroyed with [method@GLib.Source.destroy].
This API is only intended to be used by implementations of #GSource.
Do not call this API on a #GSource that you did not create.- Parameter:
ready_time
- the monotonic time at which the source will be ready, 0 for "immediately", -1 for "never"
-
setStaticName
A variant of [method@GLib.Source.set_name] that does not
duplicate the @name, and can only be used with
string literals.- Parameter:
name
- debug name for the source
-
setStaticName
A variant of [method@GLib.Source.set_name] that does not
duplicate the @name, and can only be used with
string literals.- Parameter:
name
- debug name for the source
-
unref
public void unref()Decreases the reference count of a source by one. If the
resulting reference count is zero the source and associated
memory will be destroyed. -
remove
public static boolean remove(int tag) Removes the source with the given ID from the default main context. You must
use [method@GLib.Source.destroy] for sources added to a non-default main context.
The ID of a #GSource is given by [method@GLib.Source.get_id], or will be
returned by the functions [method@GLib.Source.attach], [func@GLib.idle_add],
[func@GLib.idle_add_full], [func@GLib.timeout_add],
[func@GLib.timeout_add_full], [func@GLib.child_watch_add],
[func@GLib.child_watch_add_full], [func@GLib.io_add_watch], and
[func@GLib.io_add_watch_full].
It is a programmer error to attempt to remove a non-existent source.
More specifically: source IDs can be reissued after a source has been
destroyed and therefore it is never valid to use this function with a
source ID which may have already been removed. An example is when
scheduling an idle to run in another thread with [func@GLib.idle_add]: the
idle may already have run and been removed by the time this function
is called on its (now invalid) source ID. This source ID may have
been reissued, leading to the operation being performed against the
wrong source.- Parameter:
tag
- the ID of the source to remove.- Gibt zurück:
- %TRUE if the source was found and removed.
-
removeByFuncsUserData
public static boolean removeByFuncsUserData(@Nonnull SourceFuncs funcs, @Nullable Pointer user_data) Removes a source from the default main loop context given the
source functions and user data. If multiple sources exist with the
same source functions and user data, only one will be destroyed.- Parameter:
funcs
- The @source_funcs passed to [ctor@GLib.Source.new]user_data
- the user data for the callback- Gibt zurück:
- %TRUE if a source was found and removed.
-
removeByUserData
Removes a source from the default main loop context given the user
data for the callback. If multiple sources exist with the same user
data, only one will be destroyed.- Parameter:
user_data
- the user_data for the callback.- Gibt zurück:
- %TRUE if a source was found and removed.
-
setNameById
Sets the name of a source using its ID.
This is a convenience utility to set source names from the return
value of [func@GLib.idle_add], [func@GLib.timeout_add], etc.
It is a programmer error to attempt to set the name of a non-existent
source.
More specifically: source IDs can be reissued after a source has been
destroyed and therefore it is never valid to use this function with a
source ID which may have already been removed. An example is when
scheduling an idle to run in another thread with [func@GLib.idle_add]: the
idle may already have run and been removed by the time this function
is called on its (now invalid) source ID. This source ID may have
been reissued, leading to the operation being performed against the
wrong source.- Parameter:
tag
- a #GSource IDname
- debug name for the source
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-