Class Source
- All Implemented Interfaces:
Proxy
GSource struct is an opaque data type
representing an event source.-
Constructor Summary
ConstructorsConstructorDescriptionSource(MemorySegment address) Create a Source proxy instance for the provided memory address.Source(SourceFuncs sourceFuncs, int structSize) Creates a newGLib.Sourcestructure. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChildSource(Source childSource) AddschildSourceto this Source as a ‘polled’ source.voidAdds a file descriptor to the set of file descriptors polled for this source.addUnixFd(int fd, Set<IOCondition> events) Monitorsfdfor the IO events inevents.addUnixFd(int fd, IOCondition... events) Monitorsfdfor the IO events inevents.intattach(@Nullable MainContext context) Adds aGLib.Sourceto acontextso that it will be executed within that context.voiddestroy()Removes a source from itsGLib.MainContext, if any, and marks it as destroyed.@Nullable MainContextGets a reference to theGLib.MainContextwith which the source is associated.booleanChecks whether a source is allowed to be called recursively.@Nullable MainContextGets theGLib.MainContextwith which the source is associated.voidgetCurrentTime(TimeVal timeval) Deprecated.intgetId()Returns the numeric ID for a particular source.static MemoryLayoutThe memory layout of the native struct.@Nullable StringgetName()Gets a name for the source, used in debugging and profiling.intGets the priority of a source.longGets the ‘ready time’ ofsource,as set bysetReadyTime(long).longgetTime()Gets the time to be used when checking this source.static @Nullable TypegetType()Get the GType of the Source classbooleanReturns whether this Source has been destroyed.voidmodifyUnixFd(MemorySegment tag, Set<IOCondition> newEvents) Updates the event mask to watch for the file descriptor identified bytag.voidmodifyUnixFd(MemorySegment tag, IOCondition... newEvents) Updates the event mask to watch for the file descriptor identified bytag.queryUnixFd(MemorySegment tag) Queries the events reported for the file descriptor corresponding totagon this Source during the last poll.Read the value of the fieldcallback_data.Read the value of the fieldcallback_funcs.Read the value of the fieldcontext.intRead the value of the fieldflags.readName()Read the value of the fieldname.readNext()Read the value of the fieldnext.Read the value of the fieldpoll_fds.readPrev()Read the value of the fieldprev.intRead the value of the fieldpriority.intRead the value of the fieldref_count.Read the value of the fieldsource_funcs.intRead the value of the fieldsource_id.ref()Increases the reference count on a source by one.static booleanremove(int tag) Removes the source with the given ID from the default main context.static booleanremoveByFuncsUserData(SourceFuncs funcs, @Nullable MemorySegment userData) Removes a source from the default main loop context given the source functions and user data.static booleanremoveByUserData(@Nullable MemorySegment userData) Removes a source from the default main loop context given the user data for the callback.voidremoveChildSource(Source childSource) DetacheschildSourcefrom this Source and destroys it.voidremovePoll(PollFD fd) Removes a file descriptor from the set of file descriptors polled for this source.voidReverses the effect of a previous call toaddUnixFd(int, java.util.Set<org.gnome.glib.IOCondition>).voidsetCallback(@Nullable SourceFunc func) Sets the callback function for a source.voidsetCallbackIndirect(@Nullable MemorySegment callbackData, SourceCallbackFuncs callbackFuncs) Sets the callback function storing the data as a reference counted callback ‘object’.voidsetCanRecurse(boolean canRecurse) Sets whether a source can be called recursively.voidsetDisposeFunction(@Nullable SourceDisposeFunc dispose) Setdisposeas dispose function onsource.voidsetFuncs(SourceFuncs funcs) Sets the source functions of an unattached source.voidSets a name for the source, used in debugging and profiling.static voidsetNameById(int tag, String name) Sets the name of a source using its ID.voidsetPriority(int priority) Sets the priority of a source.voidsetReadyTime(long readyTime) Sets a source to be dispatched when the given monotonic time is reached (or passed).voidsetStaticName(String name) A variant ofsetName(java.lang.String)that does not duplicate thename,and can only be used with string literals.voidunref()Decreases the reference count of a source by one.voidwriteCallbackData(MemorySegment callbackData) Write a value in the fieldcallback_data.voidwriteCallbackFuncs(SourceCallbackFuncs callbackFuncs) Write a value in the fieldcallback_funcs.voidwriteContext(MainContext context) Write a value in the fieldcontext.voidwriteFlags(int flags) Write a value in the fieldflags.voidWrite a value in the fieldname.voidWrite a value in the fieldnext.voidwritePollFds(SList<MemorySegment> pollFds) Write a value in the fieldpoll_fds.voidWrite a value in the fieldprev.voidwritePriority(int priority) Write a value in the fieldpriority.voidwriteRefCount(int refCount) Write a value in the fieldref_count.voidwriteSourceFuncs(SourceFuncs sourceFuncs) Write a value in the fieldsource_funcs.voidwriteSourceId(int sourceId) Write a value in the fieldsource_id.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Source
Create a Source proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Source
Creates a newGLib.Sourcestructure.The size is specified to allow creating structures derived from
GLib.Sourcethat contain additional data. The size passed in must be at leastsizeof (GSource).The source will not initially be associated with any
GLib.MainContextand must be added to one withattach(org.gnome.glib.MainContext)before it will be executed.- Parameters:
sourceFuncs- structure containing functions that implement the source‘s behaviorstructSize- size of theGLib.Sourcestructure to create, in bytes
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readCallbackData
Read the value of the fieldcallback_data.- Returns:
- The value of the field
callback_data
-
writeCallbackData
Write a value in the fieldcallback_data.- Parameters:
callbackData- The new value for the fieldcallback_data
-
readCallbackFuncs
Read the value of the fieldcallback_funcs.- Returns:
- The value of the field
callback_funcs
-
writeCallbackFuncs
Write a value in the fieldcallback_funcs.- Parameters:
callbackFuncs- The new value for the fieldcallback_funcs
-
readSourceFuncs
Read the value of the fieldsource_funcs.- Returns:
- The value of the field
source_funcs
-
writeSourceFuncs
Write a value in the fieldsource_funcs.- Parameters:
sourceFuncs- The new value for the fieldsource_funcs
-
readRefCount
public int readRefCount()Read the value of the fieldref_count.- Returns:
- The value of the field
ref_count
-
writeRefCount
public void writeRefCount(int refCount) Write a value in the fieldref_count.- Parameters:
refCount- The new value for the fieldref_count
-
readContext
Read the value of the fieldcontext.- Returns:
- The value of the field
context
-
writeContext
Write a value in the fieldcontext.- Parameters:
context- The new value for the fieldcontext
-
readPriority
public int readPriority()Read the value of the fieldpriority.- Returns:
- The value of the field
priority
-
writePriority
public void writePriority(int priority) Write a value in the fieldpriority.- Parameters:
priority- The new value for the fieldpriority
-
readFlags
public int readFlags()Read the value of the fieldflags.- Returns:
- The value of the field
flags
-
writeFlags
public void writeFlags(int flags) Write a value in the fieldflags.- Parameters:
flags- The new value for the fieldflags
-
readSourceId
public int readSourceId()Read the value of the fieldsource_id.- Returns:
- The value of the field
source_id
-
writeSourceId
public void writeSourceId(int sourceId) Write a value in the fieldsource_id.- Parameters:
sourceId- The new value for the fieldsource_id
-
readPollFds
Read the value of the fieldpoll_fds.- Returns:
- The value of the field
poll_fds
-
writePollFds
Write a value in the fieldpoll_fds.- Parameters:
pollFds- The new value for the fieldpoll_fds
-
readPrev
-
writePrev
Write a value in the fieldprev.- Parameters:
prev- The new value for the fieldprev
-
readNext
-
writeNext
Write a value in the fieldnext.- Parameters:
next- The new value for the fieldnext
-
readName
-
writeName
-
remove
public static boolean remove(int tag) Removes the source with the given ID from the default main context.You must use
destroy()for sources added to a non-default main context.The ID of a
GLib.Sourceis given bygetId(), or will be returned by the functionsattach(org.gnome.glib.MainContext),GLib.idleAdd(int, org.gnome.glib.SourceFunc),GLib#idleAddFull,GLib.timeoutAdd(int, int, org.gnome.glib.SourceFunc),GLib#timeoutAddFull,GLib.childWatchAdd(int, org.gnome.glib.Pid, org.gnome.glib.ChildWatchFunc),GLib#childWatchAddFull,GLib.ioAddWatch(org.gnome.glib.IOChannel, int, java.util.Set<org.gnome.glib.IOCondition>, org.gnome.glib.IOFunc), andGLib#ioAddWatchFull.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
GLib.idleAdd(int, org.gnome.glib.SourceFunc): 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.- Parameters:
tag- the ID of the source to remove.- Returns:
- true if the source was found and removed, false otherwise
-
removeByFuncsUserData
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.
- Parameters:
funcs- thesourceFuncspassed toSource(org.gnome.glib.SourceFuncs, int)userData- the user data for the callback- Returns:
- true if a source was found and removed, false otherwise
-
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.
- Parameters:
userData- the user_data for the callback- Returns:
- true if a source was found and removed, false otherwise
-
setNameById
Sets the name of a source using its ID.This is a convenience utility to set source names from the return value of
GLib.idleAdd(int, org.gnome.glib.SourceFunc),GLib.timeoutAdd(int, int, org.gnome.glib.SourceFunc), 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
GLib.idleAdd(int, org.gnome.glib.SourceFunc): 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.- Parameters:
tag- a source IDname- debug name for the source- Since:
- 2.26
-
addChildSource
AddschildSourceto this Source as a ‘polled’ source.When this Source is added to a
GLib.MainContext,childSourcewill be automatically added with the same priority. WhenchildSourceis triggered, it will cause this Source to dispatch (in addition to calling its own callback), and when this Source is destroyed, it will destroychildSourceas well.The this Source will also still be dispatched if its own prepare/check functions indicate that it is ready.
If you don’t need
childSourceto do anything on its own when it triggers, you can callg_source_set_dummy_callback()on it to set a callback that does nothing (except return true if appropriate).The this Source will hold a reference on
childSourcewhilechildSourceis attached to it.This API is only intended to be used by implementations of
GLib.Source. Do not call this API on aGLib.Sourcethat you did not create.- Parameters:
childSource- a second source that this Source should ‘poll’- Since:
- 2.28
-
addPoll
Adds a file descriptor to the set of file descriptors polled for this source.This is usually combined with
Source(org.gnome.glib.SourceFuncs, int)to add an event source. The event source’s check function will typically test thereventsfield in theGLib.PollFDstruct and return true if events need to be processed.This API is only intended to be used by implementations of
GLib.Source. Do not call this API on aGLib.Sourcethat 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.- Parameters:
fd- aGLib.PollFDstructure holding information about a file descriptor to watch
-
addUnixFd
Monitorsfdfor the IO events inevents.The tag returned by this function can be used to remove or modify the monitoring of the
fdusingremoveUnixFd(java.lang.foreign.MemorySegment)ormodifyUnixFd(java.lang.foreign.MemorySegment, java.util.Set<org.gnome.glib.IOCondition>).It is not necessary to remove the file descriptor before destroying the source; it will be cleaned up automatically.
This API is only intended to be used by implementations of
GLib.Source. Do not call this API on aGLib.Sourcethat you did not create.As the name suggests, this function is not available on Windows.
- Parameters:
fd- the file descriptor to monitorevents- an event mask- Returns:
- an opaque tag
- Since:
- 2.36
-
addUnixFd
Monitorsfdfor the IO events inevents.The tag returned by this function can be used to remove or modify the monitoring of the
fdusingremoveUnixFd(java.lang.foreign.MemorySegment)ormodifyUnixFd(java.lang.foreign.MemorySegment, java.util.Set<org.gnome.glib.IOCondition>).It is not necessary to remove the file descriptor before destroying the source; it will be cleaned up automatically.
This API is only intended to be used by implementations of
GLib.Source. Do not call this API on aGLib.Sourcethat you did not create.As the name suggests, this function is not available on Windows.
- Parameters:
fd- the file descriptor to monitorevents- an event mask- Returns:
- an opaque tag
- Since:
- 2.36
-
attach
Adds aGLib.Sourceto acontextso that it will be executed within that context.Remove it by calling
destroy().This function is safe to call from any thread, regardless of which thread the
contextis running in.- Parameters:
context- a main context (ifNULL, the global-default main context will be used)- Returns:
- the ID (greater than 0) for the source within the
GLib.MainContext
-
destroy
public void destroy()Removes a source from itsGLib.MainContext, if any, and marks 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
GLib.Source: if you still hold a reference, useunref()to drop it.This function is safe to call from any thread, regardless of which thread the
GLib.MainContextis running in.If the source is currently attached to a
GLib.MainContext, destroying it will effectively unset the callback similar to callingsetCallback(org.gnome.glib.SourceFunc). This can mean, that the data’sGLib.DestroyNotifygets called right away. -
dupContext
Gets a reference to theGLib.MainContextwith which the source is associated.You can call this on a source that has been destroyed. You can always call this function on the source returned from
GLib.mainCurrentSource().- Returns:
- the
GLib.MainContextwith which the source is associated, orNULLif the context has not yet been added to a source - Since:
- 2.86
-
getCanRecurse
public boolean getCanRecurse()Checks whether a source is allowed to be called recursively.- Returns:
- whether recursion is allowed
-
getContext
Gets theGLib.MainContextwith which the source is associated.You can call this on a source that has been destroyed, provided that the
GLib.MainContextit was attached to still exists (in which case it will return thatGLib.MainContext). In particular, you can always call this function on the source returned fromGLib.mainCurrentSource(). But calling this function on a source whoseGLib.MainContexthas been destroyed is an error.If the associated
GLib.MainContextcould be destroy concurrently from a different thread, then this function is not safe to call anddupContext()should be used instead.- Returns:
- the main context with which the
source is associated, or
NULLif the context has not yet been added to a source
-
getCurrentTime
Deprecated.usegetTime()insteadThis function ignores this Source and is otherwise the same asGLib.getCurrentTime(org.gnome.glib.TimeVal).- Parameters:
timeval-GLib.TimeValstructure 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
MainContext.findSourceById(int).You can only call this function while the source is associated to a
GLib.MainContextinstance; calling this function beforeattach(org.gnome.glib.MainContext)or afterdestroy()yields undefined behavior. The ID returned is unique within theGLib.MainContextinstance passed toattach(org.gnome.glib.MainContext).- Returns:
- the ID (greater than 0) for the source
-
getName
Gets a name for the source, used in debugging and profiling.The name may be
NULLif it has never been set withsetName(java.lang.String).- Returns:
- the name of the source
- Since:
- 2.26
-
getPriority
public int getPriority()Gets the priority of a source.- Returns:
- the priority of the source
-
getReadyTime
public long getReadyTime()Gets the ‘ready time’ ofsource,as set bysetReadyTime(long).Any time before or equal to the current monotonic time (including zero) is an indication that the source will fire immediately.
- Returns:
- the monotonic ready time,
-1for ‘never’
-
getTime
public long getTime()Gets the time to be used when checking this source.The advantage of calling this function over calling
GLib.getMonotonicTime()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
GLib.getMonotonicTime().- Returns:
- the monotonic time in microseconds
- Since:
- 2.28
-
isDestroyed
public boolean isDestroyed()Returns whether this 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.
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.
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
GLib.MainContexttheGLib.Sourceis 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.- Returns:
- true if the source has been destroyed, false otherwise
- Since:
- 2.12
-
modifyUnixFd
Updates the event mask to watch for the file descriptor identified bytag.The
tagis the tag returned fromaddUnixFd(int, java.util.Set<org.gnome.glib.IOCondition>).If you want to remove a file descriptor, don’t set its event mask to zero. Instead, call
removeUnixFd(java.lang.foreign.MemorySegment).This API is only intended to be used by implementations of
GLib.Source. Do not call this API on aGLib.Sourcethat you did not create.As the name suggests, this function is not available on Windows.
- Parameters:
tag- the tag fromaddUnixFd(int, java.util.Set<org.gnome.glib.IOCondition>)newEvents- the new event mask to watch- Since:
- 2.36
-
modifyUnixFd
Updates the event mask to watch for the file descriptor identified bytag.The
tagis the tag returned fromaddUnixFd(int, java.util.Set<org.gnome.glib.IOCondition>).If you want to remove a file descriptor, don’t set its event mask to zero. Instead, call
removeUnixFd(java.lang.foreign.MemorySegment).This API is only intended to be used by implementations of
GLib.Source. Do not call this API on aGLib.Sourcethat you did not create.As the name suggests, this function is not available on Windows.
- Parameters:
tag- the tag fromaddUnixFd(int, java.util.Set<org.gnome.glib.IOCondition>)newEvents- the new event mask to watch- Since:
- 2.36
-
queryUnixFd
Queries the events reported for the file descriptor corresponding totagon this 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
GLib.Source. Do not call this API on aGLib.Sourcethat you did not create.As the name suggests, this function is not available on Windows.
- Parameters:
tag- the tag fromaddUnixFd(int, java.util.Set<org.gnome.glib.IOCondition>)- Returns:
- the conditions reported on the file descriptor
- Since:
- 2.36
-
ref
-
removeChildSource
DetacheschildSourcefrom this Source and destroys it.This API is only intended to be used by implementations of
GLib.Source. Do not call this API on aGLib.Sourcethat you did not create.- Parameters:
childSource- a source previously passed toaddChildSource(org.gnome.glib.Source)- Since:
- 2.28
-
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
GLib.Source. Do not call this API on aGLib.Sourcethat you did not create.- Parameters:
fd- aGLib.PollFDstructure previously passed toaddPoll(org.gnome.glib.PollFD)
-
removeUnixFd
Reverses the effect of a previous call toaddUnixFd(int, java.util.Set<org.gnome.glib.IOCondition>).You only need to call this if you want to remove a file descriptor 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
GLib.Source. Do not call this API on aGLib.Sourcethat you did not create.As the name suggests, this function is not available on Windows.
- Parameters:
tag- the tag fromaddUnixFd(int, java.util.Set<org.gnome.glib.IOCondition>)- Since:
- 2.36
-
setCallback
Sets the callback function for a source. The callback for a source is called from the source’s dispatch function.The exact type of
funcdepends on the type of source; ie. you should not count onfuncbeing called withdataas its first parameter. CastfuncwithGLib#SOURCEFUNCto avoid warnings about incompatible function types.See main loop memory management 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
GLib.idleAdd(int, org.gnome.glib.SourceFunc)orGLib.timeoutAdd(int, int, org.gnome.glib.SourceFunc).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
destroy()for a currently attached source has the effect of also unsetting the callback.- Parameters:
func- a callback function
-
setCallbackIndirect
public void setCallbackIndirect(@Nullable MemorySegment callbackData, SourceCallbackFuncs callbackFuncs) Sets the callback function storing the data as a reference counted callback ‘object’.This is used internally. Note that calling
setCallbackIndirect(java.lang.foreign.MemorySegment, org.gnome.glib.SourceCallbackFuncs)assumes an initial reference count oncallbackData,and thuscallback_funcs->unrefwill eventually be called once more thancallback_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.
- Parameters:
callbackData- pointer to callback data ‘object’callbackFuncs- functions for reference countingcallbackDataand getting the callback and data
-
setCanRecurse
public void setCanRecurse(boolean canRecurse) Sets whether a source can be called recursively.If
canRecurseis 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.- Parameters:
canRecurse- whether recursion is allowed for this source
-
setDisposeFunction
Setdisposeas dispose function onsource.The
disposefunction will be called once the reference count of this Source reaches zero but before any of the state of the source is freed, especially before the finalize function (set as part of theGLib.SourceFuncs) is called.This means that at this point this Source is still a valid
GLib.Sourceand it is allow for the reference count to increase again untildisposereturns.The dispose function can be used to clear any ‘weak’ references to the this Source in other data structures in a thread-safe way where it is possible for another thread to increase the reference count of this Source again while it is being freed.
The finalize function can not be used for this purpose as at that point this Source is already partially freed and not valid any more.
This should only ever be called from
GLib.Sourceimplementations.- Parameters:
dispose- dispose function to set on the source- Since:
- 2.64
-
setFuncs
Sets the source functions of an unattached source.These can be used to override the default implementations for the type of
source.- Parameters:
funcs- the new source functions- Since:
- 2.12
-
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’.
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
checkfunction of aGLib.SourceFuncsto include details like the event type in the source name.Use caution if changing the name while another thread may be accessing it with
getName(); 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
setStaticName(java.lang.String).- Parameters:
name- debug name for the source- Since:
- 2.26
-
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.
- Parameters:
priority- the new priority
-
setReadyTime
public void setReadyTime(long readyTime) Sets a source 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
readyTimeis0) then the source will be dispatched immediately.If
readyTimeis-1then 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
GLib.Sourcewhich has already been destroyed withdestroy().This API is only intended to be used by implementations of
GLib.Source. Do not call this API on aGLib.Sourcethat you did not create.- Parameters:
readyTime- the monotonic time at which the source will be ready;0for ‘immediately’,-1for ‘never’- Since:
- 2.36
-
setStaticName
A variant ofsetName(java.lang.String)that does not duplicate thename,and can only be used with string literals.- Parameters:
name- debug name for the source- Since:
- 2.70
-
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.
-
getTime()instead