1/* GIO - GLib Input, Output and Streaming Library
2 *
3 * Copyright 2011 Red Hat, Inc.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef __G_TASK_H__
20#define __G_TASK_H__
21
22#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
23#error "Only <gio/gio.h> can be included directly."
24#endif
25
26#include <gio/giotypes.h>
27
28G_BEGIN_DECLS
29
30#define G_TYPE_TASK (g_task_get_type ())
31#define G_TASK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_TASK, GTask))
32#define G_TASK_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_TASK, GTaskClass))
33#define G_IS_TASK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_TASK))
34#define G_IS_TASK_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_TASK))
35#define G_TASK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_TASK, GTaskClass))
36
37typedef struct _GTaskClass GTaskClass;
38
39GLIB_AVAILABLE_IN_2_36
40GType g_task_get_type (void) G_GNUC_CONST;
41
42GLIB_AVAILABLE_IN_2_36
43GTask *g_task_new (gpointer source_object,
44 GCancellable *cancellable,
45 GAsyncReadyCallback callback,
46 gpointer callback_data);
47
48GLIB_AVAILABLE_IN_2_36
49void g_task_report_error (gpointer source_object,
50 GAsyncReadyCallback callback,
51 gpointer callback_data,
52 gpointer source_tag,
53 GError *error);
54GLIB_AVAILABLE_IN_2_36
55void g_task_report_new_error (gpointer source_object,
56 GAsyncReadyCallback callback,
57 gpointer callback_data,
58 gpointer source_tag,
59 GQuark domain,
60 gint code,
61 const char *format,
62 ...) G_GNUC_PRINTF(7, 8);
63
64GLIB_AVAILABLE_IN_2_36
65void g_task_set_task_data (GTask *task,
66 gpointer task_data,
67 GDestroyNotify task_data_destroy);
68GLIB_AVAILABLE_IN_2_36
69void g_task_set_priority (GTask *task,
70 gint priority);
71GLIB_AVAILABLE_IN_2_36
72void g_task_set_check_cancellable (GTask *task,
73 gboolean check_cancellable);
74GLIB_AVAILABLE_IN_2_36
75void g_task_set_source_tag (GTask *task,
76 gpointer source_tag);
77GLIB_AVAILABLE_IN_2_60
78void g_task_set_name (GTask *task,
79 const gchar *name);
80
81/* Macro wrapper to set the task name when setting the source tag. */
82#if GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_60
83#define g_task_set_source_tag(task, tag) G_STMT_START { \
84 GTask *_task = (task); \
85 (g_task_set_source_tag) (_task, tag); \
86 if (g_task_get_name (_task) == NULL) \
87 g_task_set_name (_task, G_STRINGIFY (tag)); \
88} G_STMT_END
89#endif
90
91GLIB_AVAILABLE_IN_2_36
92gpointer g_task_get_source_object (GTask *task);
93GLIB_AVAILABLE_IN_2_36
94gpointer g_task_get_task_data (GTask *task);
95GLIB_AVAILABLE_IN_2_36
96gint g_task_get_priority (GTask *task);
97GLIB_AVAILABLE_IN_2_36
98GMainContext *g_task_get_context (GTask *task);
99GLIB_AVAILABLE_IN_2_36
100GCancellable *g_task_get_cancellable (GTask *task);
101GLIB_AVAILABLE_IN_2_36
102gboolean g_task_get_check_cancellable (GTask *task);
103GLIB_AVAILABLE_IN_2_36
104gpointer g_task_get_source_tag (GTask *task);
105GLIB_AVAILABLE_IN_2_60
106const gchar *g_task_get_name (GTask *task);
107
108GLIB_AVAILABLE_IN_2_36
109gboolean g_task_is_valid (gpointer result,
110 gpointer source_object);
111
112
113typedef void (*GTaskThreadFunc) (GTask *task,
114 gpointer source_object,
115 gpointer task_data,
116 GCancellable *cancellable);
117GLIB_AVAILABLE_IN_2_36
118void g_task_run_in_thread (GTask *task,
119 GTaskThreadFunc task_func);
120GLIB_AVAILABLE_IN_2_36
121void g_task_run_in_thread_sync (GTask *task,
122 GTaskThreadFunc task_func);
123GLIB_AVAILABLE_IN_2_36
124gboolean g_task_set_return_on_cancel (GTask *task,
125 gboolean return_on_cancel);
126GLIB_AVAILABLE_IN_2_36
127gboolean g_task_get_return_on_cancel (GTask *task);
128
129GLIB_AVAILABLE_IN_2_36
130void g_task_attach_source (GTask *task,
131 GSource *source,
132 GSourceFunc callback);
133
134
135GLIB_AVAILABLE_IN_2_36
136void g_task_return_pointer (GTask *task,
137 gpointer result,
138 GDestroyNotify result_destroy);
139GLIB_AVAILABLE_IN_2_36
140void g_task_return_boolean (GTask *task,
141 gboolean result);
142GLIB_AVAILABLE_IN_2_36
143void g_task_return_int (GTask *task,
144 gssize result);
145
146GLIB_AVAILABLE_IN_2_36
147void g_task_return_error (GTask *task,
148 GError *error);
149GLIB_AVAILABLE_IN_2_36
150void g_task_return_new_error (GTask *task,
151 GQuark domain,
152 gint code,
153 const char *format,
154 ...) G_GNUC_PRINTF (4, 5);
155GLIB_AVAILABLE_IN_2_64
156void g_task_return_value (GTask *task,
157 GValue *result);
158
159GLIB_AVAILABLE_IN_2_36
160gboolean g_task_return_error_if_cancelled (GTask *task);
161
162GLIB_AVAILABLE_IN_2_36
163gpointer g_task_propagate_pointer (GTask *task,
164 GError **error);
165GLIB_AVAILABLE_IN_2_36
166gboolean g_task_propagate_boolean (GTask *task,
167 GError **error);
168GLIB_AVAILABLE_IN_2_36
169gssize g_task_propagate_int (GTask *task,
170 GError **error);
171GLIB_AVAILABLE_IN_2_64
172gboolean g_task_propagate_value (GTask *task,
173 GValue *value,
174 GError **error);
175GLIB_AVAILABLE_IN_2_36
176gboolean g_task_had_error (GTask *task);
177GLIB_AVAILABLE_IN_2_44
178gboolean g_task_get_completed (GTask *task);
179
180G_END_DECLS
181
182#endif /* __G_TASK_H__ */
183

source code of include/glib-2.0/gio/gtask.h