1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* gnome-vfs-async-ops.c - Asynchronous operations supported by the
3 GNOME Virtual File System (version for POSIX threads).
5 Copyright (C) 1999 Free Software Foundation
7 The Gnome Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 The Gnome Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the Gnome Library; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 Author: Ettore Perazzoli <ettore@comm2000.it> */
26 #include "gnome-vfs-async-ops.h"
27 #include "gnome-vfs-async-job-map.h"
28 #include "gnome-vfs-job.h"
29 #include "gnome-vfs-job-queue.h"
30 #include "gnome-vfs-job-limit.h"
31 #include <glib/gmessages.h>
32 #include <glib/gstrfuncs.h>
36 * gnome_vfs_async_cancel:
37 * @handle: handle of the async operation to be cancelled
39 * Cancel an asynchronous operation and close all its callbacks.
40 * Its possible to still receive another call or two on the callback.
43 gnome_vfs_async_cancel (GnomeVFSAsyncHandle *handle)
47 _gnome_vfs_async_job_map_lock ();
49 job = _gnome_vfs_async_job_map_get_job (handle);
51 JOB_DEBUG (("job %u - job no longer exists", GPOINTER_TO_UINT (handle)));
52 /* have to cancel the callbacks because they still can be pending */
53 _gnome_vfs_async_job_cancel_job_and_callbacks (handle, NULL);
55 /* Cancel the job in progress. OK to do outside of job->job_lock,
56 * job lifetime is protected by _gnome_vfs_async_job_map_lock.
58 _gnome_vfs_job_module_cancel (job);
59 _gnome_vfs_async_job_cancel_job_and_callbacks (handle, job);
62 _gnome_vfs_async_job_map_unlock ();
65 static GnomeVFSAsyncHandle *
66 async_open (GnomeVFSURI *uri,
67 GnomeVFSOpenMode open_mode,
69 GnomeVFSAsyncOpenCallback callback,
70 gpointer callback_data)
73 GnomeVFSOpenOp *open_op;
74 GnomeVFSAsyncHandle *result;
76 job = _gnome_vfs_job_new (GNOME_VFS_OP_OPEN, priority, (GFunc) callback, callback_data);
78 open_op = &job->op->specifics.open;
80 open_op->uri = uri == NULL ? NULL : gnome_vfs_uri_ref (uri);
81 open_op->open_mode = open_mode;
83 result = job->job_handle;
84 _gnome_vfs_job_go (job);
90 * gnome_vfs_async_open_uri:
91 * @handle_return: A pointer to a pointer to a GnomeVFSHandle object
93 * @open_mode: Open mode
94 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
95 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign this job
96 * in allocating threads from the thread pool.
97 * @callback: function to be called when the operation is complete
98 * @callback_data: data to pass @callback
100 * Open @uri according to mode @open_mode. On return, @handle_return will
101 * contain a pointer to the operation. Once the file has been successfully opened,
102 * @callback will be called with the GnomeVFSResult.
106 gnome_vfs_async_open_uri (GnomeVFSAsyncHandle **handle_return,
108 GnomeVFSOpenMode open_mode,
110 GnomeVFSAsyncOpenCallback callback,
111 gpointer callback_data)
113 g_return_if_fail (handle_return != NULL);
114 g_return_if_fail (uri != NULL);
115 g_return_if_fail (callback != NULL);
116 g_return_if_fail (priority >= GNOME_VFS_PRIORITY_MIN);
117 g_return_if_fail (priority <= GNOME_VFS_PRIORITY_MAX);
119 *handle_return = async_open (uri, open_mode, priority,
120 callback, callback_data);
124 * gnome_vfs_async_open:
125 * @handle_return: A pointer to a pointer to a GnomeVFSHandle object
126 * @text_uri: string of the URI to open
127 * @open_mode: Open mode
128 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
129 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign this job
130 * in allocating threads from the thread pool.
131 * @callback: function to be called when the operation is complete
132 * @callback_data: data to pass @callback
134 * Open @text_uri according to mode @open_mode. On return, @handle_return will
135 * contain a pointer to the operation. Once the file has been successfully opened,
136 * @callback will be called with the GnomeVFSResult.
140 gnome_vfs_async_open (GnomeVFSAsyncHandle **handle_return,
141 const gchar *text_uri,
142 GnomeVFSOpenMode open_mode,
144 GnomeVFSAsyncOpenCallback callback,
145 gpointer callback_data)
149 g_return_if_fail (handle_return != NULL);
150 g_return_if_fail (text_uri != NULL);
151 g_return_if_fail (callback != NULL);
152 g_return_if_fail (priority >= GNOME_VFS_PRIORITY_MIN);
153 g_return_if_fail (priority <= GNOME_VFS_PRIORITY_MAX);
155 uri = gnome_vfs_uri_new (text_uri);
156 *handle_return = async_open (uri, open_mode, priority,
157 callback, callback_data);
159 gnome_vfs_uri_unref (uri);
163 static GnomeVFSAsyncHandle *
164 async_open_as_channel (GnomeVFSURI *uri,
165 GnomeVFSOpenMode open_mode,
166 guint advised_block_size,
168 GnomeVFSAsyncOpenAsChannelCallback callback,
169 gpointer callback_data)
172 GnomeVFSOpenAsChannelOp *open_as_channel_op;
173 GnomeVFSAsyncHandle *result;
175 job = _gnome_vfs_job_new (GNOME_VFS_OP_OPEN_AS_CHANNEL, priority, (GFunc) callback, callback_data);
177 open_as_channel_op = &job->op->specifics.open_as_channel;
178 open_as_channel_op->uri = uri == NULL ? NULL : gnome_vfs_uri_ref (uri);
179 open_as_channel_op->open_mode = open_mode;
180 open_as_channel_op->advised_block_size = advised_block_size;
182 result = job->job_handle;
183 _gnome_vfs_job_go (job);
189 * gnome_vfs_async_open_uri_as_channel:
190 * @handle_return: A pointer to a pointer to a GnomeVFSHandle object
191 * @uri: URI to open as a #GIOChannel
192 * @open_mode: open for reading, writing, random, etc
193 * @advised_block_size: the preferred block size for #GIOChannel to read
194 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
195 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign this job
196 * in allocating threads from the thread pool.
197 * @callback: function to be called when the operation is complete
198 * @callback_data: data to pass @callback
200 * Open @uri as a #GIOChannel. Once the channel has been established
201 * @callback will be called with @callback_data, the result of the operation,
202 * and if the result was %GNOME_VFS_OK, a reference to a #GIOChannel pointing
203 * at @uri in @open_mode.
206 gnome_vfs_async_open_uri_as_channel (GnomeVFSAsyncHandle **handle_return,
208 GnomeVFSOpenMode open_mode,
209 guint advised_block_size,
211 GnomeVFSAsyncOpenAsChannelCallback callback,
212 gpointer callback_data)
214 g_return_if_fail (handle_return != NULL);
215 g_return_if_fail (uri != NULL);
216 g_return_if_fail (callback != NULL);
217 g_return_if_fail (priority >= GNOME_VFS_PRIORITY_MIN);
218 g_return_if_fail (priority <= GNOME_VFS_PRIORITY_MAX);
220 *handle_return = async_open_as_channel (uri, open_mode, advised_block_size,
221 priority, callback, callback_data);
225 * gnome_vfs_async_open_as_channel:
226 * @handle_return: A pointer to a pointer to a GnomeVFSHandle object
227 * @text_uri: string of the URI to open as a #GIOChannel
228 * @open_mode: open for reading, writing, random, etc
229 * @advised_block_size: the preferred block size for #GIOChannel to read
230 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
231 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign this job
232 * in allocating threads from the thread pool.
233 * @callback: function to be called when the operation is complete
234 * @callback_data: data to pass @callback
236 * Open @text_uri as a #GIOChannel. Once the channel has been established
237 * @callback will be called with @callback_data, the result of the operation,
238 * and if the result was %GNOME_VFS_OK, a reference to a #GIOChannel pointing
239 * at @text_uri in @open_mode.
242 gnome_vfs_async_open_as_channel (GnomeVFSAsyncHandle **handle_return,
243 const gchar *text_uri,
244 GnomeVFSOpenMode open_mode,
245 guint advised_block_size,
247 GnomeVFSAsyncOpenAsChannelCallback callback,
248 gpointer callback_data)
252 g_return_if_fail (handle_return != NULL);
253 g_return_if_fail (text_uri != NULL);
254 g_return_if_fail (callback != NULL);
255 g_return_if_fail (priority >= GNOME_VFS_PRIORITY_MIN);
256 g_return_if_fail (priority <= GNOME_VFS_PRIORITY_MAX);
258 uri = gnome_vfs_uri_new (text_uri);
259 *handle_return = async_open_as_channel (uri, open_mode, advised_block_size,
260 priority, callback, callback_data);
262 gnome_vfs_uri_unref (uri);
266 static GnomeVFSAsyncHandle *
267 async_create (GnomeVFSURI *uri,
268 GnomeVFSOpenMode open_mode,
272 GnomeVFSAsyncOpenCallback callback,
273 gpointer callback_data)
276 GnomeVFSCreateOp *create_op;
277 GnomeVFSAsyncHandle *result;
279 job = _gnome_vfs_job_new (GNOME_VFS_OP_CREATE, priority, (GFunc) callback, callback_data);
281 create_op = &job->op->specifics.create;
282 create_op->uri = uri == NULL ? NULL : gnome_vfs_uri_ref (uri);
283 create_op->open_mode = open_mode;
284 create_op->exclusive = exclusive;
285 create_op->perm = perm;
287 result = job->job_handle;
288 _gnome_vfs_job_go (job);
294 * gnome_vfs_async_create_uri:
295 * @handle_return: A pointer to a pointer to a GnomeVFSHandle object
296 * @uri: the URI to create a file at
297 * @open_mode: mode to leave the file opened in after creation (or %GNOME_VFS_OPEN_MODE_NONE
298 * to leave the file closed after creation)
299 * @exclusive: Whether the file should be created in "exclusive" mode:
300 * i.e. if this flag is nonzero, operation will fail if a file with the
301 * same name already exists.
302 * @perm: Bitmap representing the permissions for the newly created file
304 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
305 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign this job
306 * in allocating threads from the thread pool.
307 * @callback: function to be called when the operation is complete
308 * @callback_data: data to pass @callback
310 * Create a file at @uri according to mode @open_mode, with permissions @perm (in
311 * the standard UNIX packed bit permissions format). When the create has been completed
312 * @callback will be called with the result code and @callback_data.
315 gnome_vfs_async_create_uri (GnomeVFSAsyncHandle **handle_return,
317 GnomeVFSOpenMode open_mode,
321 GnomeVFSAsyncOpenCallback callback,
322 gpointer callback_data)
324 g_return_if_fail (handle_return != NULL);
325 g_return_if_fail (uri != NULL);
326 g_return_if_fail (callback != NULL);
327 g_return_if_fail (priority >= GNOME_VFS_PRIORITY_MIN);
328 g_return_if_fail (priority <= GNOME_VFS_PRIORITY_MAX);
330 *handle_return = async_create (uri, open_mode, exclusive, perm,
331 priority, callback, callback_data);
335 * gnome_vfs_async_create:
336 * @handle_return: A pointer to a pointer to a GnomeVFSHandle object
337 * @text_uri: String representing the URI to create
338 * @open_mode: mode to leave the file opened in after creation (or %GNOME_VFS_OPEN_MODE_NONE
339 * to leave the file closed after creation)
340 * @exclusive: Whether the file should be created in "exclusive" mode:
341 * i.e. if this flag is nonzero, operation will fail if a file with the
342 * same name already exists.
343 * @perm: Bitmap representing the permissions for the newly created file
345 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
346 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign this job
347 * in allocating threads from the thread pool.
348 * @callback: function to be called when the operation is complete
349 * @callback_data: data to pass @callback
351 * Create a file at @uri according to mode @open_mode, with permissions @perm (in
352 * the standard UNIX packed bit permissions format). When the create has been completed
353 * @callback will be called with the result code and @callback_data.
356 gnome_vfs_async_create (GnomeVFSAsyncHandle **handle_return,
357 const gchar *text_uri,
358 GnomeVFSOpenMode open_mode,
362 GnomeVFSAsyncOpenCallback callback,
363 gpointer callback_data)
367 g_return_if_fail (handle_return != NULL);
368 g_return_if_fail (text_uri != NULL);
369 g_return_if_fail (callback != NULL);
370 g_return_if_fail (priority >= GNOME_VFS_PRIORITY_MIN);
371 g_return_if_fail (priority <= GNOME_VFS_PRIORITY_MAX);
373 uri = gnome_vfs_uri_new (text_uri);
374 *handle_return = async_create (uri, open_mode, exclusive, perm,
375 priority, callback, callback_data);
377 gnome_vfs_uri_unref (uri);
382 * gnome_vfs_async_create_as_channel:
383 * @handle_return: A pointer to a pointer to a GnomeVFSHandle object
384 * @text_uri: string of the URI to open as a #GIOChannel, creating it as necessary
385 * @open_mode: open for reading, writing, random, etc
386 * @exclusive: replace the file if it already exists
387 * @perm: standard POSIX-style permissions bitmask, permissions of created file
388 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
389 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign this job
390 * in allocating threads from the thread pool.
391 * @callback: function to be called when the operation is complete
392 * @callback_data: data to pass @callback
394 * Open @text_uri as a #GIOChannel, creating it as necessary. Once the channel has
395 * been established @callback will be called with @callback_data, the result of the
396 * operation, and if the result was %GNOME_VFS_OK, a reference to a #GIOChannel pointing
397 * at @text_uri in @open_mode.
400 gnome_vfs_async_create_as_channel (GnomeVFSAsyncHandle **handle_return,
401 const gchar *text_uri,
402 GnomeVFSOpenMode open_mode,
406 GnomeVFSAsyncOpenAsChannelCallback callback,
407 gpointer callback_data)
410 GnomeVFSCreateAsChannelOp *create_as_channel_op;
411 GnomeVFSAsyncHandle *result;
413 g_return_if_fail (handle_return != NULL);
414 g_return_if_fail (text_uri != NULL);
415 g_return_if_fail (callback != NULL);
416 g_return_if_fail (priority >= GNOME_VFS_PRIORITY_MIN);
417 g_return_if_fail (priority <= GNOME_VFS_PRIORITY_MAX);
419 job = _gnome_vfs_job_new (GNOME_VFS_OP_CREATE_AS_CHANNEL, priority, (GFunc) callback, callback_data);
422 create_as_channel_op = &job->op->specifics.create_as_channel;
423 create_as_channel_op->uri = gnome_vfs_uri_new (text_uri);
424 create_as_channel_op->open_mode = open_mode;
425 create_as_channel_op->exclusive = exclusive;
426 create_as_channel_op->perm = perm;
428 result = job->job_handle;
429 _gnome_vfs_job_go (job);
433 * gnome_vfs_async_close:
434 * @handle: async handle to close
435 * @callback: function to be called when the operation is complete
436 * @callback_data: data to pass @callback
438 * Close a handle opened with gnome_vfs_async_open(). When the close
439 * has completed, @callback will be called with @callback_data and
440 * the result of the operation.
443 gnome_vfs_async_close (GnomeVFSAsyncHandle *handle,
444 GnomeVFSAsyncCloseCallback callback,
445 gpointer callback_data)
449 g_return_if_fail (handle != NULL);
450 g_return_if_fail (callback != NULL);
453 _gnome_vfs_async_job_map_lock ();
454 job = _gnome_vfs_async_job_map_get_job (handle);
456 g_warning ("trying to read a non-existing handle");
457 _gnome_vfs_async_job_map_unlock ();
461 if (job->op->type != GNOME_VFS_OP_READ &&
462 job->op->type != GNOME_VFS_OP_WRITE) {
463 _gnome_vfs_job_set (job, GNOME_VFS_OP_CLOSE,
464 (GFunc) callback, callback_data);
465 _gnome_vfs_job_go (job);
466 _gnome_vfs_async_job_map_unlock ();
469 /* Still reading, wait a bit, cancel should be pending.
470 * This mostly handles a race condition that can happen
471 * on a dual CPU machine where a cancel stops a read before
472 * the read thread picks up and a close then gets scheduled
473 * on a new thread. Without this the job op type would be
474 * close for both threads and two closes would get executed
476 _gnome_vfs_async_job_map_unlock ();
482 * gnome_vfs_async_read:
483 * @handle: handle for the file to be read
484 * @buffer: allocated block of memory to read into
485 * @bytes: number of bytes to read
486 * @callback: function to be called when the operation is complete
487 * @callback_data: data to pass @callback
489 * Read @bytes bytes from the file pointed to be @handle into @buffer.
490 * When the operation is complete, @callback will be called with the
491 * result of the operation and @callback_data.
494 gnome_vfs_async_read (GnomeVFSAsyncHandle *handle,
497 GnomeVFSAsyncReadCallback callback,
498 gpointer callback_data)
501 GnomeVFSReadOp *read_op;
503 g_return_if_fail (handle != NULL);
504 g_return_if_fail (buffer != NULL);
505 g_return_if_fail (callback != NULL);
507 _gnome_vfs_async_job_map_lock ();
508 job = _gnome_vfs_async_job_map_get_job (handle);
510 g_warning ("trying to read from a non-existing handle");
511 _gnome_vfs_async_job_map_unlock ();
515 _gnome_vfs_job_set (job, GNOME_VFS_OP_READ,
516 (GFunc) callback, callback_data);
518 read_op = &job->op->specifics.read;
519 read_op->buffer = buffer;
520 read_op->num_bytes = bytes;
522 _gnome_vfs_job_go (job);
523 _gnome_vfs_async_job_map_unlock ();
527 * gnome_vfs_async_write:
528 * @handle: handle for the file to be written
529 * @buffer: block of memory containing data to be written
530 * @bytes: number of bytes to write
531 * @callback: function to be called when the operation is complete
532 * @callback_data: data to pass @callback
534 * Write @bytes bytes from @buffer into the file pointed to be @handle.
535 * When the operation is complete, @callback will be called with the
536 * result of the operation and @callback_data.
539 gnome_vfs_async_write (GnomeVFSAsyncHandle *handle,
540 gconstpointer buffer,
542 GnomeVFSAsyncWriteCallback callback,
543 gpointer callback_data)
546 GnomeVFSWriteOp *write_op;
548 g_return_if_fail (handle != NULL);
549 g_return_if_fail (buffer != NULL);
550 g_return_if_fail (callback != NULL);
552 _gnome_vfs_async_job_map_lock ();
553 job = _gnome_vfs_async_job_map_get_job (handle);
555 g_warning ("trying to write to a non-existing handle");
556 _gnome_vfs_async_job_map_unlock ();
560 _gnome_vfs_job_set (job, GNOME_VFS_OP_WRITE,
561 (GFunc) callback, callback_data);
563 write_op = &job->op->specifics.write;
564 write_op->buffer = buffer;
565 write_op->num_bytes = bytes;
567 _gnome_vfs_job_go (job);
568 _gnome_vfs_async_job_map_unlock ();
572 * gnome_vfs_async_create_symbolic_link:
573 * @handle_return: when the function returns will point to a handle for
574 * the async operation.
575 * @uri: location to create the link at
576 * @uri_reference: location to point @uri to (can be a URI fragment, i.e. relative)
577 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
578 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign this job
579 * in allocating threads from the thread pool.
580 * @callback: function to be called when the operation is complete
581 * @callback_data: data to pass @callback
583 * Create a symbolic link at @uri pointing to @uri_reference. When the operation
584 * has complete @callback will be called with the result of the operation and
588 gnome_vfs_async_create_symbolic_link (GnomeVFSAsyncHandle **handle_return,
590 const gchar *uri_reference,
592 GnomeVFSAsyncOpenCallback callback,
593 gpointer callback_data)
596 GnomeVFSCreateLinkOp *create_op;
598 g_return_if_fail (handle_return != NULL);
599 g_return_if_fail (uri != NULL);
600 g_return_if_fail (callback != NULL);
601 g_return_if_fail (priority >= GNOME_VFS_PRIORITY_MIN);
602 g_return_if_fail (priority <= GNOME_VFS_PRIORITY_MAX);
604 job = _gnome_vfs_job_new (GNOME_VFS_OP_CREATE_SYMBOLIC_LINK, priority, (GFunc) callback, callback_data);
606 create_op = &job->op->specifics.create_symbolic_link;
607 create_op->uri = gnome_vfs_uri_ref (uri);
608 create_op->uri_reference = g_strdup (uri_reference);
610 *handle_return = job->job_handle;
611 _gnome_vfs_job_go (job);
615 * gnome_vfs_async_get_file_info:
616 * @handle_return: when the function returns will point to a handle for
617 * the async operation.
618 * @uri_list: a GList of GnomeVFSURIs to fetch information about
619 * @options: packed boolean type providing control over various details
620 * of the get_file_info operation.
621 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
622 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign this job
623 * in allocating threads from the thread pool.
624 * @callback: function to be called when the operation is complete
625 * @callback_data: data to pass @callback
627 * Fetch information about the files indicated in @uris and return the
628 * information progressively to @callback.
631 gnome_vfs_async_get_file_info (GnomeVFSAsyncHandle **handle_return,
633 GnomeVFSFileInfoOptions options,
635 GnomeVFSAsyncGetFileInfoCallback callback,
636 gpointer callback_data)
639 GnomeVFSGetFileInfoOp *get_info_op;
641 g_return_if_fail (handle_return != NULL);
642 g_return_if_fail (callback != NULL);
643 g_return_if_fail (priority >= GNOME_VFS_PRIORITY_MIN);
644 g_return_if_fail (priority <= GNOME_VFS_PRIORITY_MAX);
646 job = _gnome_vfs_job_new (GNOME_VFS_OP_GET_FILE_INFO, priority, (GFunc) callback, callback_data);
648 get_info_op = &job->op->specifics.get_file_info;
650 get_info_op->uris = gnome_vfs_uri_list_copy (uri_list);
651 get_info_op->options = options;
653 *handle_return = job->job_handle;
654 _gnome_vfs_job_go (job);
658 * gnome_vfs_async_set_file_info:
659 * @handle_return: when the function returns will point to a handle for
660 * the async operation.
661 * @uri: the URI to set the file info of
662 * @info: the struct containing new information about the file
663 * @mask: control which fields of @info are changed about the file at @uri
664 * @options: packed boolean type providing control over various details
665 * of the set_file_info operation.
666 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
667 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign this job
668 * in allocating threads from the thread pool.
669 * @callback: function to be called when the operation is complete
670 * @callback_data: data to pass @callback
672 * Set "file info" details about the file at @uri, such as permissions, name,
673 * owner, and modification time.
676 gnome_vfs_async_set_file_info (GnomeVFSAsyncHandle **handle_return,
678 GnomeVFSFileInfo *info,
679 GnomeVFSSetFileInfoMask mask,
680 GnomeVFSFileInfoOptions options,
682 GnomeVFSAsyncSetFileInfoCallback callback,
683 gpointer callback_data)
686 GnomeVFSSetFileInfoOp *op;
688 g_return_if_fail (handle_return != NULL);
689 g_return_if_fail (uri != NULL);
690 g_return_if_fail (info != NULL);
691 g_return_if_fail (callback != NULL);
692 g_return_if_fail (priority >= GNOME_VFS_PRIORITY_MIN);
693 g_return_if_fail (priority <= GNOME_VFS_PRIORITY_MAX);
695 job = _gnome_vfs_job_new (GNOME_VFS_OP_SET_FILE_INFO, priority, (GFunc) callback, callback_data);
697 op = &job->op->specifics.set_file_info;
699 op->uri = gnome_vfs_uri_ref (uri);
700 op->info = gnome_vfs_file_info_new ();
701 gnome_vfs_file_info_copy (op->info, info);
703 op->options = options;
705 *handle_return = job->job_handle;
706 _gnome_vfs_job_go (job);
710 * gnome_vfs_async_find_directory:
711 * @handle_return: when the function returns will point to a handle for
712 * @near_uri_list: a GList of GnomeVFSURIs, find a special directory on the same
714 * @kind: kind of special directory
715 * @create_if_needed: If directory we are looking for does not exist, try to create it
716 * @find_if_needed: If we don't know where the directory is yet, look for it.
717 * @permissions: If creating, use these permissions
718 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
719 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign this job
720 * in allocating threads from the thread pool.
721 * @callback: function to be called when the operation is complete
722 * @user_data: data to pass @callback *
723 * Used to return special directories such as Trash and Desktop from different
726 * There is quite a complicated logic behind finding/creating a Trash directory
727 * and you need to be aware of some implications:
728 * Finding the Trash the first time when using the file method may be pretty
729 * expensive. A cache file is used to store the location of that Trash file
731 * If @ceate_if_needed is specified without @find_if_needed, you may end up
732 * creating a Trash file when there already is one. Your app should start out
733 * by doing a gnome_vfs_find_directory with the @find_if_needed to avoid this
734 * and then use the @create_if_needed flag to create Trash lazily when it is
735 * needed for throwing away an item on a given disk.
737 * When the operation has completed, @callback will be called with the result
738 * of the operation and @user_data.
741 gnome_vfs_async_find_directory (GnomeVFSAsyncHandle **handle_return,
742 GList *near_uri_list,
743 GnomeVFSFindDirectoryKind kind,
744 gboolean create_if_needed,
745 gboolean find_if_needed,
748 GnomeVFSAsyncFindDirectoryCallback callback,
752 GnomeVFSFindDirectoryOp *get_info_op;
754 g_return_if_fail (handle_return != NULL);
755 g_return_if_fail (callback != NULL);
756 g_return_if_fail (priority >= GNOME_VFS_PRIORITY_MIN);
757 g_return_if_fail (priority <= GNOME_VFS_PRIORITY_MAX);
759 job = _gnome_vfs_job_new (GNOME_VFS_OP_FIND_DIRECTORY, priority, (GFunc) callback, user_data);
761 get_info_op = &job->op->specifics.find_directory;
763 get_info_op->uris = gnome_vfs_uri_list_copy (near_uri_list);
764 get_info_op->kind = kind;
765 get_info_op->create_if_needed = create_if_needed;
766 get_info_op->find_if_needed = find_if_needed;
767 get_info_op->permissions = permissions;
769 *handle_return = job->job_handle;
770 _gnome_vfs_job_go (job);
773 static GnomeVFSAsyncHandle *
774 async_load_directory (GnomeVFSURI *uri,
775 GnomeVFSFileInfoOptions options,
776 guint items_per_notification,
778 GnomeVFSAsyncDirectoryLoadCallback callback,
779 gpointer callback_data)
782 GnomeVFSLoadDirectoryOp *load_directory_op;
783 GnomeVFSAsyncHandle *result;
785 job = _gnome_vfs_job_new (GNOME_VFS_OP_LOAD_DIRECTORY, priority, (GFunc) callback, callback_data);
787 load_directory_op = &job->op->specifics.load_directory;
788 load_directory_op->uri = uri == NULL ? NULL : gnome_vfs_uri_ref (uri);
789 load_directory_op->options = options;
790 load_directory_op->items_per_notification = items_per_notification;
792 result = job->job_handle;
793 _gnome_vfs_job_go (job);
801 * gnome_vfs_async_load_directory:
802 * @handle_return: when the function returns will point to a handle for
803 * the async operation.
804 * @text_uri: string representing the URI of the directory to be loaded
805 * @options: packed boolean type providing control over various details
806 * of the get_file_info operation.
807 * @items_per_notification: number of files to process in a row before calling @callback
808 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
809 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign this job
810 * in allocating threads from the thread pool.
811 * @callback: function to be called when the operation is complete
812 * @callback_data: data to pass @callback
814 * Read the contents of the directory at @text_uri, passing back GnomeVFSFileInfo
815 * structs about each file in the directory to @callback. @items_per_notification
816 * files will be processed between each call to @callback.
819 gnome_vfs_async_load_directory (GnomeVFSAsyncHandle **handle_return,
820 const gchar *text_uri,
821 GnomeVFSFileInfoOptions options,
822 guint items_per_notification,
824 GnomeVFSAsyncDirectoryLoadCallback callback,
825 gpointer callback_data)
829 g_return_if_fail (handle_return != NULL);
830 g_return_if_fail (text_uri != NULL);
831 g_return_if_fail (callback != NULL);
832 g_return_if_fail (priority >= GNOME_VFS_PRIORITY_MIN);
833 g_return_if_fail (priority <= GNOME_VFS_PRIORITY_MAX);
835 uri = gnome_vfs_uri_new (text_uri);
836 *handle_return = async_load_directory (uri, options,
837 items_per_notification,
839 callback, callback_data);
841 gnome_vfs_uri_unref (uri);
846 * gnome_vfs_async_load_directory_uri:
847 * @handle_return: when the function returns will point to a handle for
848 * the async operation.
849 * @uri: string representing the URI of the directory to be loaded
850 * @options: packed boolean type providing control over various details
851 * of the get_file_info operation.
852 * @items_per_notification: number of files to process in a row before calling @callback
853 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
854 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign this job
855 * in allocating threads from the thread pool.
856 * @callback: function to be called when the operation is complete
857 * @callback_data: data to pass @callback
859 * Read the contents of the directory at @uri, passing back GnomeVFSFileInfo structs
860 * about each file in the directory to @callback. @items_per_notification
861 * files will be processed between each call to @callback.
864 gnome_vfs_async_load_directory_uri (GnomeVFSAsyncHandle **handle_return,
866 GnomeVFSFileInfoOptions options,
867 guint items_per_notification,
869 GnomeVFSAsyncDirectoryLoadCallback callback,
870 gpointer callback_data)
872 g_return_if_fail (handle_return != NULL);
873 g_return_if_fail (uri != NULL);
874 g_return_if_fail (callback != NULL);
875 g_return_if_fail (priority >= GNOME_VFS_PRIORITY_MIN);
876 g_return_if_fail (priority <= GNOME_VFS_PRIORITY_MAX);
878 *handle_return = async_load_directory (uri, options,
879 items_per_notification,
881 callback, callback_data);
885 * gnome_vfs_async_xfer:
886 * @handle_return: when the function returns will point to a handle for
887 * @source_uri_list: #GList of #GnomeVFSURI representing the files to be transferred
888 * @target_uri_list: #GList of #GnomeVFSURI, the target locations for the elements
889 * in @source_uri_list
890 * @xfer_options: various options controlling the details of the transfer.
891 * Use %GNOME_VFS_XFER_REMOUVESOURCE to make the operation a move rather than a copy.
892 * @error_mode: report errors to the @progress_sync_callback, or simply abort
893 * @overwrite_mode: controls whether the xfer engine will overwrite automatically,
894 * skip the file, abort the operation, or query @progress_sync_callback
895 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
896 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign this job
897 * in allocating threads from the thread pool.
898 * @progress_update_callback: called periodically to keep the client appraised of progress
899 * in completing the XFer operation, and the current phase of operation.
900 * @update_callback_data: user data passed to @progress_update_callback
901 * @progress_sync_callback: called when the program requires responses to interactive queries
902 * (e.g. overwriting files, handling errors, etc)
903 * @sync_callback_data: user data passed to @progress_sync_callback
905 * Perform a copy operation in a seperate thread. @progress_update_callback will be periodically
906 * polled with status of the operation (percent done, the current phase of operation, the
907 * current file being operated upon). If the xfer engine needs to query the caller to make
908 * a decision or report on important error it will do so on @progress_sync_callback.
910 * Return value: %GNOME_VFS_OK if the paramaters were in order,
911 * or %GNOME_VFS_ERROR_BAD_PARAMETERS if something was wrong in the passed in arguments.
914 gnome_vfs_async_xfer (GnomeVFSAsyncHandle **handle_return,
915 GList *source_uri_list,
916 GList *target_uri_list,
917 GnomeVFSXferOptions xfer_options,
918 GnomeVFSXferErrorMode error_mode,
919 GnomeVFSXferOverwriteMode overwrite_mode,
921 GnomeVFSAsyncXferProgressCallback progress_update_callback,
922 gpointer update_callback_data,
923 GnomeVFSXferProgressCallback progress_sync_callback,
924 gpointer sync_callback_data)
927 GnomeVFSXferOp *xfer_op;
929 g_return_val_if_fail (handle_return != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
930 g_return_val_if_fail (progress_update_callback != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
931 g_return_val_if_fail (priority >= GNOME_VFS_PRIORITY_MIN, GNOME_VFS_ERROR_BAD_PARAMETERS);
932 g_return_val_if_fail (priority <= GNOME_VFS_PRIORITY_MAX, GNOME_VFS_ERROR_BAD_PARAMETERS);
934 job = _gnome_vfs_job_new (GNOME_VFS_OP_XFER,
936 (GFunc) progress_update_callback,
937 update_callback_data);
940 xfer_op = &job->op->specifics.xfer;
941 xfer_op->source_uri_list = gnome_vfs_uri_list_copy (source_uri_list);
942 xfer_op->target_uri_list = gnome_vfs_uri_list_copy (target_uri_list);
943 xfer_op->xfer_options = xfer_options;
944 xfer_op->error_mode = error_mode;
945 xfer_op->overwrite_mode = overwrite_mode;
946 xfer_op->progress_sync_callback = progress_sync_callback;
947 xfer_op->sync_callback_data = sync_callback_data;
949 *handle_return = job->job_handle;
950 _gnome_vfs_job_go (job);
956 * gnome_vfs_async_file_control:
957 * @handle: handle of the file to affect
958 * @operation: The operation to execute
959 * @operation_data: The data needed to execute the operation
960 * @operation_data_destroy_func: Called to destroy operation_data when its no longer needed
961 * @callback: function to be called when the operation is complete
962 * @callback_data: data to pass @callback
964 * Execute a backend dependent operation specified by the string @operation.
965 * This is typically used for specialized vfs backends that need additional
966 * operations that gnome-vfs doesn't have. Compare it to the unix call ioctl().
967 * The format of @operation_data depends on the operation. Operation that are
968 * backend specific are normally namespaced by their module name.
970 * When the operation is complete, @callback will be called with the
971 * result of the operation, @operation_data and @callback_data.
976 gnome_vfs_async_file_control (GnomeVFSAsyncHandle *handle,
977 const char *operation,
978 gpointer operation_data,
979 GDestroyNotify operation_data_destroy_func,
980 GnomeVFSAsyncFileControlCallback callback,
981 gpointer callback_data)
984 GnomeVFSFileControlOp *file_control_op;
986 g_return_if_fail (handle != NULL);
987 g_return_if_fail (operation != NULL);
988 g_return_if_fail (callback != NULL);
990 _gnome_vfs_async_job_map_lock ();
991 job = _gnome_vfs_async_job_map_get_job (handle);
993 g_warning ("trying to call file_control on a non-existing handle");
994 _gnome_vfs_async_job_map_unlock ();
998 _gnome_vfs_job_set (job, GNOME_VFS_OP_FILE_CONTROL,
999 (GFunc) callback, callback_data);
1001 file_control_op = &job->op->specifics.file_control;
1002 file_control_op->operation = g_strdup (operation);
1003 file_control_op->operation_data = operation_data;
1004 file_control_op->operation_data_destroy_func = operation_data_destroy_func;
1006 _gnome_vfs_job_go (job);
1007 _gnome_vfs_async_job_map_unlock ();
1010 #ifdef OLD_CONTEXT_DEPRECATED
1013 gnome_vfs_async_add_status_callback (GnomeVFSAsyncHandle *handle,
1014 GnomeVFSStatusCallback callback,
1020 g_return_val_if_fail (handle != NULL, 0);
1021 g_return_val_if_fail (callback != NULL, 0);
1023 _gnome_vfs_async_job_map_lock ();
1024 job = _gnome_vfs_async_job_map_get_job (handle);
1026 if (job->op != NULL || job->op->context != NULL) {
1027 g_warning ("job or context not found");
1028 _gnome_vfs_async_job_map_unlock ();
1032 result = gnome_vfs_message_callbacks_add
1033 (gnome_vfs_context_get_message_callbacks (job->op->context),
1034 callback, user_data);
1035 _gnome_vfs_async_job_map_unlock ();
1041 gnome_vfs_async_remove_status_callback (GnomeVFSAsyncHandle *handle,
1046 g_return_if_fail (handle != NULL);
1047 g_return_if_fail (callback_id > 0);
1049 _gnome_vfs_async_job_map_lock ();
1050 job = _gnome_vfs_async_job_map_get_job (handle);
1052 if (job->op != NULL || job->op->context != NULL) {
1053 g_warning ("job or context not found");
1054 _gnome_vfs_async_job_map_unlock ();
1058 gnome_vfs_message_callbacks_remove
1059 (gnome_vfs_context_get_message_callbacks (job->op->context),
1062 _gnome_vfs_async_job_map_unlock ();
1065 #endif /* OLD_CONTEXT_DEPRECATED */