ftp://ftp.redhat.com/pub/redhat/linux/rawhide/SRPMS/SRPMS/gnome-vfs2-2.3.8-1.src.rpm
[gnome-vfs-httpcaptive.git] / libgnomevfs / gnome-vfs-job.h
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
3 /* gnome-vfs-job.h - Jobs for asynchronous operation of the GNOME
4    Virtual File System (version for POSIX threads).
5
6    Copyright (C) 1999 Free Software Foundation
7
8    The Gnome Library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Library General Public License as
10    published by the Free Software Foundation; either version 2 of the
11    License, or (at your option) any later version.
12
13    The Gnome Library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Library General Public License for more details.
17
18    You should have received a copy of the GNU Library General Public
19    License along with the Gnome Library; see the file COPYING.LIB.  If not,
20    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21    Boston, MA 02111-1307, USA.
22
23    Author: Ettore Perazzoli <ettore@gnu.org>
24 */
25
26 #ifndef GNOME_VFS_JOB_PTHREAD_H
27 #define GNOME_VFS_JOB_PTHREAD_H
28
29 /*
30  * The following includes help Solaris copy with its own headers.  (With 64-
31  * bit stuff enabled they like to #define open open64, etc.)
32  * See http://bugzilla.gnome.org/show_bug.cgi?id=71184 for details.
33  */
34 #include <unistd.h>
35 #include <fcntl.h>
36
37 #include <libgnomevfs/gnome-vfs-async-ops.h>
38 #include <libgnomevfs/gnome-vfs-module-callback.h>
39 #include <libgnomevfs/gnome-vfs-module-callback-private.h>
40
41 typedef struct GnomeVFSJob GnomeVFSJob;
42
43 #define GNOME_VFS_JOB_DEBUG 0
44
45 #if GNOME_VFS_JOB_DEBUG
46
47 #include <stdio.h>
48
49 extern GStaticMutex debug_mutex;
50
51 #define JOB_DEBUG_PRINT(x)                      \
52 G_STMT_START{                                   \
53         struct timeval _tt;                     \
54         gettimeofday(&_tt, NULL);               \
55         printf ("%ld:%6.ld ", _tt.tv_sec, _tt.tv_usec); \
56         g_static_mutex_lock (&debug_mutex);     \
57         fputs (__FUNCTION__, stdout);           \
58         printf (": %d ", __LINE__);             \
59         printf x;                               \
60         fputc ('\n', stdout);                   \
61         fflush (stdout);                        \
62         g_static_mutex_unlock (&debug_mutex);   \
63 }G_STMT_END
64
65 #endif
66
67 #if GNOME_VFS_JOB_DEBUG
68 #include <sys/time.h>
69
70 extern char *job_debug_types[];
71
72 #define JOB_DEBUG(x) JOB_DEBUG_PRINT(x)
73 #define JOB_DEBUG_ONLY(x) x
74 #define JOB_DEBUG_TYPE(x) (job_debug_types[(x)])
75
76 #else
77 #define JOB_DEBUG(x)
78 #define JOB_DEBUG_ONLY(x)
79 #define JOB_DEBUG_TYPE(x)
80
81 #endif
82
83 /* GNOME_VFS_OP_MODULE_CALLBACK: is not a real OpType; 
84  * its intended to mark GnomeVFSAsyncModuleCallback's in the 
85  * job_callback queue
86  */
87
88 enum GnomeVFSOpType {
89         GNOME_VFS_OP_OPEN,
90         GNOME_VFS_OP_OPEN_AS_CHANNEL,
91         GNOME_VFS_OP_CREATE,
92         GNOME_VFS_OP_CREATE_SYMBOLIC_LINK,
93         GNOME_VFS_OP_CREATE_AS_CHANNEL,
94         GNOME_VFS_OP_CLOSE,
95         GNOME_VFS_OP_READ,
96         GNOME_VFS_OP_WRITE,
97         GNOME_VFS_OP_READ_WRITE_DONE,
98         GNOME_VFS_OP_LOAD_DIRECTORY,
99         GNOME_VFS_OP_FIND_DIRECTORY,
100         GNOME_VFS_OP_XFER,
101         GNOME_VFS_OP_GET_FILE_INFO,
102         GNOME_VFS_OP_SET_FILE_INFO,
103         GNOME_VFS_OP_MODULE_CALLBACK,
104         GNOME_VFS_OP_FILE_CONTROL
105 };
106
107 typedef enum GnomeVFSOpType GnomeVFSOpType;
108
109 typedef struct {
110         GnomeVFSURI *uri;
111         GnomeVFSOpenMode open_mode;
112 } GnomeVFSOpenOp;
113
114 typedef struct {
115         GnomeVFSAsyncOpenCallback callback;
116         void *callback_data;
117         GnomeVFSResult result;
118 } GnomeVFSOpenOpResult;
119
120 typedef struct {
121         GnomeVFSURI *uri;
122         GnomeVFSOpenMode open_mode;
123         guint advised_block_size;
124 } GnomeVFSOpenAsChannelOp;
125
126 typedef struct {
127         GnomeVFSAsyncOpenAsChannelCallback callback;
128         void *callback_data;
129         GnomeVFSResult result;
130         GIOChannel *channel;
131 } GnomeVFSOpenAsChannelOpResult;
132
133 typedef struct {
134         GnomeVFSURI *uri;
135         GnomeVFSOpenMode open_mode;
136         gboolean exclusive;
137         guint perm;
138 } GnomeVFSCreateOp;
139
140 typedef struct {
141         GnomeVFSAsyncCreateCallback callback;
142         void *callback_data;
143         GnomeVFSResult result;
144 } GnomeVFSCreateOpResult;
145
146 typedef struct {
147         GnomeVFSURI *uri;
148         char *uri_reference;
149 } GnomeVFSCreateLinkOp;
150
151 typedef struct {
152         GnomeVFSURI *uri;
153         GnomeVFSOpenMode open_mode;
154         gboolean exclusive;
155         guint perm;
156 } GnomeVFSCreateAsChannelOp;
157
158 typedef struct {
159         GnomeVFSAsyncCreateAsChannelCallback callback;
160         void *callback_data;
161         GnomeVFSResult result;
162         GIOChannel *channel;
163 } GnomeVFSCreateAsChannelOpResult;
164
165 typedef struct {
166         char dummy; /* ANSI C does not allow empty structs */
167 } GnomeVFSCloseOp;
168
169 typedef struct {
170         GnomeVFSAsyncCloseCallback callback;
171         void *callback_data;
172         GnomeVFSResult result;
173 } GnomeVFSCloseOpResult;
174
175 typedef struct {
176         GnomeVFSFileSize num_bytes;
177         gpointer buffer;
178 } GnomeVFSReadOp;
179
180 typedef struct {
181         GnomeVFSAsyncReadCallback callback;
182         void *callback_data;
183         GnomeVFSFileSize num_bytes;
184         gpointer buffer;
185         GnomeVFSResult result;
186         GnomeVFSFileSize bytes_read;
187 } GnomeVFSReadOpResult;
188
189 typedef struct {
190         GnomeVFSFileSize num_bytes;
191         gconstpointer buffer;
192 } GnomeVFSWriteOp;
193
194 typedef struct {
195         GnomeVFSAsyncWriteCallback callback;
196         void *callback_data;
197         GnomeVFSFileSize num_bytes;
198         gconstpointer buffer;
199         GnomeVFSResult result;
200         GnomeVFSFileSize bytes_written;
201 } GnomeVFSWriteOpResult;
202
203 typedef struct {
204         GList *uris; /* GnomeVFSURI* */
205         GnomeVFSFileInfoOptions options;
206 } GnomeVFSGetFileInfoOp;
207
208 typedef struct {
209         GnomeVFSAsyncGetFileInfoCallback callback;
210         void *callback_data;
211         GList *result_list; /* GnomeVFSGetFileInfoResult* */
212 } GnomeVFSGetFileInfoOpResult;
213
214 typedef struct {
215         GnomeVFSURI *uri;
216         GnomeVFSFileInfo *info;
217         GnomeVFSSetFileInfoMask mask;
218         GnomeVFSFileInfoOptions options;
219 } GnomeVFSSetFileInfoOp;
220
221 typedef struct {
222         GnomeVFSAsyncSetFileInfoCallback callback;
223         void *callback_data;
224         GnomeVFSResult set_file_info_result;
225         GnomeVFSResult get_file_info_result;
226         GnomeVFSFileInfo *info;
227 } GnomeVFSSetFileInfoOpResult;
228
229 typedef struct {
230         GList *uris; /* GnomeVFSURI* */
231         GnomeVFSFindDirectoryKind kind;
232         gboolean create_if_needed;
233         gboolean find_if_needed;
234         guint permissions;
235 } GnomeVFSFindDirectoryOp;
236
237 typedef struct {
238         GnomeVFSAsyncFindDirectoryCallback callback;
239         void *callback_data;
240         GList *result_list; /* GnomeVFSFindDirectoryResult */
241 } GnomeVFSFindDirectoryOpResult;
242
243 typedef struct {
244         GnomeVFSURI *uri;
245         GnomeVFSFileInfoOptions options;
246         guint items_per_notification;
247 } GnomeVFSLoadDirectoryOp;
248
249 typedef struct {
250         GnomeVFSAsyncDirectoryLoadCallback callback;
251         void *callback_data;
252         GnomeVFSResult result;
253         GList *list;
254         guint entries_read;
255 } GnomeVFSLoadDirectoryOpResult;
256
257 typedef struct {
258         GList *source_uri_list;
259         GList *target_uri_list;
260         GnomeVFSXferOptions xfer_options;
261         GnomeVFSXferErrorMode error_mode;
262         GnomeVFSXferOverwriteMode overwrite_mode;
263         GnomeVFSXferProgressCallback progress_sync_callback;
264         gpointer sync_callback_data;
265 } GnomeVFSXferOp;
266
267 typedef struct {
268         GnomeVFSAsyncXferProgressCallback callback;
269         void *callback_data;
270         GnomeVFSXferProgressInfo *progress_info;
271         int reply;
272 } GnomeVFSXferOpResult;
273
274 typedef struct {
275         GnomeVFSAsyncModuleCallback    callback;
276         gpointer                       user_data;
277         gconstpointer                  in;
278         size_t                         in_size;
279         gpointer                       out;
280         size_t                         out_size;
281         GnomeVFSModuleCallbackResponse response;
282         gpointer                       response_data;
283 } GnomeVFSModuleCallbackOpResult;
284
285 typedef struct {
286         char *operation;
287         gpointer operation_data;
288         GDestroyNotify operation_data_destroy_func;
289 } GnomeVFSFileControlOp;
290
291 typedef struct {
292         GnomeVFSAsyncFileControlCallback callback;
293         gpointer callback_data;
294         GnomeVFSResult result;
295         gpointer operation_data;
296         GDestroyNotify operation_data_destroy_func;
297 } GnomeVFSFileControlOpResult;
298
299 typedef union {
300         GnomeVFSOpenOp open;
301         GnomeVFSOpenAsChannelOp open_as_channel;
302         GnomeVFSCreateOp create;
303         GnomeVFSCreateLinkOp create_symbolic_link;
304         GnomeVFSCreateAsChannelOp create_as_channel;
305         GnomeVFSCloseOp close;
306         GnomeVFSReadOp read;
307         GnomeVFSWriteOp write;
308         GnomeVFSLoadDirectoryOp load_directory;
309         GnomeVFSXferOp xfer;
310         GnomeVFSGetFileInfoOp get_file_info;
311         GnomeVFSSetFileInfoOp set_file_info;
312         GnomeVFSFindDirectoryOp find_directory;
313         GnomeVFSFileControlOp file_control;
314 } GnomeVFSSpecificOp;
315
316 typedef struct {
317         /* ID of the job (e.g. open, create, close...). */
318         GnomeVFSOpType type;
319
320         /* The callback for when the op is completed. */
321         GFunc callback;
322         gpointer callback_data;
323
324         /* Details of the op. */
325         GnomeVFSSpecificOp specifics;
326
327         /* The context for cancelling the operation. */
328         GnomeVFSContext *context;
329         GnomeVFSModuleCallbackStackInfo *stack_info;
330 } GnomeVFSOp;
331
332 typedef union {
333         GnomeVFSOpenOpResult open;
334         GnomeVFSOpenAsChannelOpResult open_as_channel;
335         GnomeVFSCreateOpResult create;
336         GnomeVFSCreateAsChannelOpResult create_as_channel;
337         GnomeVFSCloseOpResult close;
338         GnomeVFSReadOpResult read;
339         GnomeVFSWriteOpResult write;
340         GnomeVFSGetFileInfoOpResult get_file_info;
341         GnomeVFSSetFileInfoOpResult set_file_info;
342         GnomeVFSFindDirectoryOpResult find_directory;
343         GnomeVFSLoadDirectoryOpResult load_directory;
344         GnomeVFSXferOpResult xfer;
345         GnomeVFSModuleCallbackOpResult callback;
346         GnomeVFSFileControlOpResult file_control;
347 } GnomeVFSSpecificNotifyResult;
348
349 typedef struct {
350         GnomeVFSAsyncHandle *job_handle;
351
352         guint callback_id;
353
354         /* By the time the callback got reached the job might have been cancelled.
355          * We find out by checking this flag.
356          */
357         gboolean cancelled;
358         
359         /* ID of the job (e.g. open, create, close...). */
360         GnomeVFSOpType type;
361
362         GnomeVFSSpecificNotifyResult specifics;
363 } GnomeVFSNotifyResult;
364
365 /* FIXME bugzilla.eazel.com 1135: Move private stuff out of the header.  */
366 struct GnomeVFSJob {
367         /* Handle being used for file access.  */
368         GnomeVFSHandle *handle;
369
370         /* By the time the entry routine for the job got reached
371          * the job might have been cancelled. We find out by checking
372          * this flag.
373          */
374         gboolean cancelled;
375
376         /* Read or create returned with an error - helps
377          * flagging that we do not expect a cancel
378          */
379         gboolean failed;
380
381         /* Global lock for accessing job's 'op' and 'handle' */
382         GMutex *job_lock;
383
384         /* This condition is signalled when the master thread gets a
385            notification and wants to acknowledge it.  */
386         GCond *notify_ack_condition;
387
388         /* Operations that are being done and those that are completed and
389          * ready for notification to take place.
390          */
391         GnomeVFSOp *op;
392         
393         /* Unique identifier of this job (a uint, really) */
394         GnomeVFSAsyncHandle *job_handle;
395
396         /* The priority of this job */
397         int priority;
398 };
399
400 GnomeVFSJob     *_gnome_vfs_job_new               (GnomeVFSOpType        type,
401                                                    int                   priority,
402                                                    GFunc                 callback,
403                                                    gpointer              callback_data);
404 void             _gnome_vfs_job_destroy           (GnomeVFSJob          *job);
405 void             _gnome_vfs_job_set               (GnomeVFSJob          *job,
406                                                    GnomeVFSOpType        type,
407                                                    GFunc                 callback,
408                                                    gpointer              callback_data);
409 void             _gnome_vfs_job_go                (GnomeVFSJob          *job);
410 void             _gnome_vfs_job_execute           (GnomeVFSJob          *job);
411 void             _gnome_vfs_job_module_cancel             (GnomeVFSJob          *job);
412 int              gnome_vfs_job_get_count          (void);
413
414 gboolean         _gnome_vfs_job_complete                  (GnomeVFSJob          *job);
415
416 #endif /* GNOME_VFS_JOB_PTHREAD_H */