| Iris Manual | ||||
|---|---|---|---|---|
| Top | Description | Object Hierarchy | ||||
#define IRIS_TASK_CONST (obj) #define IRIS_TASK_THROW_NEW (t,q,c,f,...) #define IRIS_TASK_THROW (t,e) #define IRIS_TASK_CATCH (t,e) #define IRIS_TASK_RETURN_VALUE (t,gt,v) #define IRIS_TASK_RETURN_TASK (t,t2) #define IRIS_TASK_RETURN_TASK_NEW (t,f,p,n) IrisTaskPrivate; void (*IrisTaskFunc) (IrisTask *task, gpointer user_data); IrisTask; IrisTask* iris_task_new (void); IrisTask* iris_task_new_full (IrisTaskFunc func, gpointer user_data, GDestroyNotify notify, gboolean async, IrisScheduler *scheduler, GMainContext *context); void iris_task_run (IrisTask *task); void iris_task_cancel (IrisTask *task); void iris_task_complete (IrisTask *task); void iris_task_add_callback (IrisTask *task, IrisTaskFunc callback, gpointer user_data, GDestroyNotify notify); void iris_task_add_errback (IrisTask *task, IrisTaskFunc errback, gpointer user_data, GDestroyNotify notify); void iris_task_add_callback_closure (IrisTask *task, GClosure *closure); void iris_task_add_errback_closure (IrisTask *task, GClosure *closure); void iris_task_add_dependency (IrisTask *task, IrisTask *dependency); void iris_task_remove_dependency (IrisTask *task, IrisTask *dependency); gboolean iris_task_is_async (IrisTask *task); gboolean iris_task_is_executing (IrisTask *task); gboolean iris_task_is_canceled (IrisTask *task); gboolean iris_task_is_finished (IrisTask *task); void iris_task_set_main_context (IrisTask *task, GMainContext *context); GMainContext* iris_task_get_main_context (IrisTask *task); void iris_task_set_scheduler (IrisTask *task, IrisScheduler *scheduler); gboolean iris_task_get_error (IrisTask *task, GError **error); void iris_task_set_error (IrisTask *task, const GError *error); void iris_task_take_error (IrisTask *task, GError *error); void iris_task_get_result (IrisTask *task, GValue *value); void iris_task_set_result (IrisTask *task, const GValue *value); void iris_task_set_result_gtype (IrisTask *task, GType type, ...); IrisTask* iris_task_all_of (GList *tasks); IrisTask* iris_task_any_of (GList *tasks);
IrisTask is a single-shot work-item that performs an atomic piece of work. An example of this could be retrieving the contents of a web-page, removing a file from disk, or even generating a thumbnail of an image. Iris will do the work of compositing your work items onto the resources of the target system in such a way that will be efficient.
Upon completion of tasks, a series of callbacks or errbacks can be executed. This is called the post-processing phase. Callbacks and errbacks can alter the current result of the task or even yield new tasks that must be completed before further callbacks or errbacks can be executed.
#define IRIS_TASK_THROW_NEW(t,q,c,f,...)
Creates a new GError and attaches it to the task.
#define IRIS_TASK_THROW(t,e)
Steals ownership of e and attaches the GError to the task.
#define IRIS_TASK_CATCH(t,e)
Catches the currently set error on the task and stores it into e.
The ownership of e is that of the caller so it should be freed
with g_error_free() if non-NULL.
#define IRIS_TASK_RETURN_VALUE(t,gt,v)
This macro simplifies how you can store the current result for the task.
It can transparently store the value of v no matter the type as long as
your GType is accurate.
For example, to store an int you could
gint myint = 0; IRIS_TASK_RETURN_VALUE (t, G_TYPE_INT, myint);
#define IRIS_TASK_RETURN_TASK(t,t2)
Sets the result of a task to another task. This will prevent the task from
any further work in the callback/errback phase until t2 has completed.
#define IRIS_TASK_RETURN_TASK_NEW(t,f,p,n)
Helper macro to create and return a new task as the result in one step.
|
An IrisTask |
|
An IrisTaskFunc |
|
user data for the newly created IrisTask |
|
A GDestroyNotify to be called when the new task is destroyed |
void (*IrisTaskFunc) (IrisTask *task, gpointer user_data);
Callback for tasks, callbacks, and errbacks.
See iris_task_add_callback(), iris_task_add_errback().
|
An IrisTask |
|
user specified data |
IrisTask* iris_task_new (void);
Creates a new instance of IrisTask.
Returns : |
the newly created instance of IrisTask |
IrisTask* iris_task_new_full (IrisTaskFunc func, gpointer user_data, GDestroyNotify notify, gboolean async, IrisScheduler *scheduler, GMainContext *context);
Creates a new instance of IrisTask. This method allows for setting
if the task is asynchronous with async. An asynchronous task has the
ability to not complete during the execution of the task's execution
method (in this case func). To mark the task's execution as completed,
g_task_complete() must be called for the task.
If you want errbacks and callbacks to complete within a GMainContext,
you may specify context or NULL for the callbacks to happen within
the worker thread.
scheduler allows you to set a specific IrisScheduler to perform
execution of the task within. Note that all message passing associated
with the tasks internal IrisPort's will also happen on this
scheduler.
|
An IrisTaskFunc |
|
data for func
|
|
A destroy notify after execution of the task |
|
Will the task complete during the execution of func
|
|
An IrisScheduler or NULL
|
|
A GMainContext or NULL
|
Returns : |
The newly created IrisTask instance. |
void iris_task_run (IrisTask *task);
Asynchronously schedules the task for execution.
|
An IrisTask |
void iris_task_cancel (IrisTask *task);
Cancels a task. If the task is already executing, it is up to the executing
task to periodically check the canceled state with iris_task_is_canceled()
and quit execution.
|
An IrisTask |
void iris_task_complete (IrisTask *task);
Marks the task as completing the execution phase. This can be used by asynchronous tasks to denote that they have completed.
Completion of the task will result in the callbacks phase being performed.
|
An IrisTask |
void iris_task_add_callback (IrisTask *task, IrisTaskFunc callback, gpointer user_data, GDestroyNotify notify);
Adds a callback to the callbacks phase. The callback will be executed in the order it was added. If the task has an error when the callback is reached, it will not be executed at all.
|
An IrisTask |
|
An IrisTaskFunc |
|
user data for callback
|
|
notify when the closure has executed |
void iris_task_add_errback (IrisTask *task, IrisTaskFunc errback, gpointer user_data, GDestroyNotify notify);
Adds an errback to the callbacks phase. The errback will be executed in the order it was added. If errback will only execute if the task has an error when the errback is reached.
|
An IrisTask |
|
An IrisTaskFunc |
|
user data for callback
|
|
notify when the closure has executed |
void iris_task_add_callback_closure (IrisTask *task, GClosure *closure);
Adds a callback closure to be executed in the callbacks phase.
void iris_task_add_errback_closure (IrisTask *task, GClosure *closure);
Adds an errback closure to be executed in the callbacks phase.
void iris_task_add_dependency (IrisTask *task, IrisTask *dependency);
Prevents further execution of the task or callbacks phase until
the dependency task has completed.
void iris_task_remove_dependency (IrisTask *task, IrisTask *dependency);
Removes dependency from preventing the tasks execution. If the task is
ready to execute it will be scheduled for execution.
gboolean iris_task_is_async (IrisTask *task);
Checks if the task is an asynchronous task, meaning it will not complete when the tasks execute method returns.
gboolean iris_task_is_executing (IrisTask *task);
Checks if the task is currently executing.
gboolean iris_task_is_canceled (IrisTask *task);
Checks if a task has been canceled. Note that if the task handles
the cancel and chooses to ignore it, FALSE will be returned.
gboolean iris_task_is_finished (IrisTask *task);
Checks to see if the task has executed and the callbacks phase has completed.
void iris_task_set_main_context (IrisTask *task, GMainContext *context);
Sets a GMainContext to use to perform the errbacks and callbacks from. All future callbacks and errbacks will be executed from within the context.
|
An IrisTask |
|
A GMainContext |
GMainContext* iris_task_get_main_context (IrisTask *task);
Retrieves the GMainContext associated with the task or NULL.
|
An IrisTask |
Returns : |
The GMainContext or NULL
|
void iris_task_set_scheduler (IrisTask *task, IrisScheduler *scheduler);
Sets the scheduler used to execute future work items.
|
An IrisTask |
|
An IrisScheduler |
gboolean iris_task_get_error (IrisTask *task, GError **error);
Stores a copy of the current error for the task into the location
error. If no error currently exists, the value stored will be NULL.
The error must be freed by the caller using g_error_free().
void iris_task_set_error (IrisTask *task, const GError *error);
Sets the error for the task. If in the callback phase, the next iteration will execute the errback instead of the callback.
void iris_task_take_error (IrisTask *task, GError *error);
Steals the ownership of error and attaches it to the task.
void iris_task_get_result (IrisTask *task, GValue *value);
Retreives the current value for the task and stores it to the
GValue value.
void iris_task_set_result (IrisTask *task, const GValue *value);
Sets the current result for the task.
void iris_task_set_result_gtype (IrisTask *task, GType type, ...);
Sets the current value for the task without needing to use a GValue
container. You can pass a single value after type.
IrisTask* iris_task_all_of (GList *tasks);
Creates a new task that will complete when each of the passed IrisTask's complete.
|
|
Returns : |
the newly created IrisTask instance. |