1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
3 /* gnome-vfs-job.h - Jobs for asynchronous operation of the GNOME
4 Virtual File System (version for POSIX threads).
6 Copyright (C) 1999 Free Software Foundation
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.
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.
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.
23 Author: Ettore Perazzoli <ettore@gnu.org>
26 #ifndef GNOME_VFS_JOB_PTHREAD_H
27 #define GNOME_VFS_JOB_PTHREAD_H
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.
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>
41 typedef struct GnomeVFSJob GnomeVFSJob;
43 #define GNOME_VFS_JOB_DEBUG 0
45 #if GNOME_VFS_JOB_DEBUG
49 extern GStaticMutex debug_mutex;
51 #define JOB_DEBUG_PRINT(x) \
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__); \
60 fputc ('\n', stdout); \
62 g_static_mutex_unlock (&debug_mutex); \
67 #if GNOME_VFS_JOB_DEBUG
70 extern char *job_debug_types[];
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)])
78 #define JOB_DEBUG_ONLY(x)
79 #define JOB_DEBUG_TYPE(x)
83 /* GNOME_VFS_OP_MODULE_CALLBACK: is not a real OpType;
84 * its intended to mark GnomeVFSAsyncModuleCallback's in the
90 GNOME_VFS_OP_OPEN_AS_CHANNEL,
92 GNOME_VFS_OP_CREATE_SYMBOLIC_LINK,
93 GNOME_VFS_OP_CREATE_AS_CHANNEL,
97 GNOME_VFS_OP_READ_WRITE_DONE,
98 GNOME_VFS_OP_LOAD_DIRECTORY,
99 GNOME_VFS_OP_FIND_DIRECTORY,
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
107 typedef enum GnomeVFSOpType GnomeVFSOpType;
111 GnomeVFSOpenMode open_mode;
115 GnomeVFSAsyncOpenCallback callback;
117 GnomeVFSResult result;
118 } GnomeVFSOpenOpResult;
122 GnomeVFSOpenMode open_mode;
123 guint advised_block_size;
124 } GnomeVFSOpenAsChannelOp;
127 GnomeVFSAsyncOpenAsChannelCallback callback;
129 GnomeVFSResult result;
131 } GnomeVFSOpenAsChannelOpResult;
135 GnomeVFSOpenMode open_mode;
141 GnomeVFSAsyncCreateCallback callback;
143 GnomeVFSResult result;
144 } GnomeVFSCreateOpResult;
149 } GnomeVFSCreateLinkOp;
153 GnomeVFSOpenMode open_mode;
156 } GnomeVFSCreateAsChannelOp;
159 GnomeVFSAsyncCreateAsChannelCallback callback;
161 GnomeVFSResult result;
163 } GnomeVFSCreateAsChannelOpResult;
166 char dummy; /* ANSI C does not allow empty structs */
170 GnomeVFSAsyncCloseCallback callback;
172 GnomeVFSResult result;
173 } GnomeVFSCloseOpResult;
176 GnomeVFSFileSize num_bytes;
181 GnomeVFSAsyncReadCallback callback;
183 GnomeVFSFileSize num_bytes;
185 GnomeVFSResult result;
186 GnomeVFSFileSize bytes_read;
187 } GnomeVFSReadOpResult;
190 GnomeVFSFileSize num_bytes;
191 gconstpointer buffer;
195 GnomeVFSAsyncWriteCallback callback;
197 GnomeVFSFileSize num_bytes;
198 gconstpointer buffer;
199 GnomeVFSResult result;
200 GnomeVFSFileSize bytes_written;
201 } GnomeVFSWriteOpResult;
204 GList *uris; /* GnomeVFSURI* */
205 GnomeVFSFileInfoOptions options;
206 } GnomeVFSGetFileInfoOp;
209 GnomeVFSAsyncGetFileInfoCallback callback;
211 GList *result_list; /* GnomeVFSGetFileInfoResult* */
212 } GnomeVFSGetFileInfoOpResult;
216 GnomeVFSFileInfo *info;
217 GnomeVFSSetFileInfoMask mask;
218 GnomeVFSFileInfoOptions options;
219 } GnomeVFSSetFileInfoOp;
222 GnomeVFSAsyncSetFileInfoCallback callback;
224 GnomeVFSResult set_file_info_result;
225 GnomeVFSResult get_file_info_result;
226 GnomeVFSFileInfo *info;
227 } GnomeVFSSetFileInfoOpResult;
230 GList *uris; /* GnomeVFSURI* */
231 GnomeVFSFindDirectoryKind kind;
232 gboolean create_if_needed;
233 gboolean find_if_needed;
235 } GnomeVFSFindDirectoryOp;
238 GnomeVFSAsyncFindDirectoryCallback callback;
240 GList *result_list; /* GnomeVFSFindDirectoryResult */
241 } GnomeVFSFindDirectoryOpResult;
245 GnomeVFSFileInfoOptions options;
246 guint items_per_notification;
247 } GnomeVFSLoadDirectoryOp;
250 GnomeVFSAsyncDirectoryLoadCallback callback;
252 GnomeVFSResult result;
255 } GnomeVFSLoadDirectoryOpResult;
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;
268 GnomeVFSAsyncXferProgressCallback callback;
270 GnomeVFSXferProgressInfo *progress_info;
272 } GnomeVFSXferOpResult;
275 GnomeVFSAsyncModuleCallback callback;
281 GnomeVFSModuleCallbackResponse response;
282 gpointer response_data;
283 } GnomeVFSModuleCallbackOpResult;
287 gpointer operation_data;
288 GDestroyNotify operation_data_destroy_func;
289 } GnomeVFSFileControlOp;
292 GnomeVFSAsyncFileControlCallback callback;
293 gpointer callback_data;
294 GnomeVFSResult result;
295 gpointer operation_data;
296 GDestroyNotify operation_data_destroy_func;
297 } GnomeVFSFileControlOpResult;
301 GnomeVFSOpenAsChannelOp open_as_channel;
302 GnomeVFSCreateOp create;
303 GnomeVFSCreateLinkOp create_symbolic_link;
304 GnomeVFSCreateAsChannelOp create_as_channel;
305 GnomeVFSCloseOp close;
307 GnomeVFSWriteOp write;
308 GnomeVFSLoadDirectoryOp load_directory;
310 GnomeVFSGetFileInfoOp get_file_info;
311 GnomeVFSSetFileInfoOp set_file_info;
312 GnomeVFSFindDirectoryOp find_directory;
313 GnomeVFSFileControlOp file_control;
314 } GnomeVFSSpecificOp;
317 /* ID of the job (e.g. open, create, close...). */
320 /* The callback for when the op is completed. */
322 gpointer callback_data;
324 /* Details of the op. */
325 GnomeVFSSpecificOp specifics;
327 /* The context for cancelling the operation. */
328 GnomeVFSContext *context;
329 GnomeVFSModuleCallbackStackInfo *stack_info;
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;
350 GnomeVFSAsyncHandle *job_handle;
354 /* By the time the callback got reached the job might have been cancelled.
355 * We find out by checking this flag.
359 /* ID of the job (e.g. open, create, close...). */
362 GnomeVFSSpecificNotifyResult specifics;
363 } GnomeVFSNotifyResult;
365 /* FIXME bugzilla.eazel.com 1135: Move private stuff out of the header. */
367 /* Handle being used for file access. */
368 GnomeVFSHandle *handle;
370 /* By the time the entry routine for the job got reached
371 * the job might have been cancelled. We find out by checking
376 /* Read or create returned with an error - helps
377 * flagging that we do not expect a cancel
381 /* Global lock for accessing job's 'op' and 'handle' */
384 /* This condition is signalled when the master thread gets a
385 notification and wants to acknowledge it. */
386 GCond *notify_ack_condition;
388 /* Operations that are being done and those that are completed and
389 * ready for notification to take place.
393 /* Unique identifier of this job (a uint, really) */
394 GnomeVFSAsyncHandle *job_handle;
396 /* The priority of this job */
400 GnomeVFSJob *_gnome_vfs_job_new (GnomeVFSOpType type,
403 gpointer callback_data);
404 void _gnome_vfs_job_destroy (GnomeVFSJob *job);
405 void _gnome_vfs_job_set (GnomeVFSJob *job,
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);
414 gboolean _gnome_vfs_job_complete (GnomeVFSJob *job);
416 #endif /* GNOME_VFS_JOB_PTHREAD_H */