1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* gnome-vfs-context.c - context VFS modules can use to communicate with gnome-vfs proper
4 Copyright (C) 1999 Free Software Foundation
6 The Gnome Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The Gnome Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the Gnome Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
21 Author: Havoc Pennington <hp@redhat.com> */
24 #include "gnome-vfs-context.h"
26 #include "gnome-vfs-backend.h"
27 #include "gnome-vfs-cancellation.h"
28 #include "gnome-vfs-private-utils.h"
29 #include "gnome-vfs-utils.h"
33 #define DEBUG_MSG (x) printf x
39 struct GnomeVFSContext {
40 GnomeVFSCancellation *cancellation;
43 /* This is a token Context to return in situations
44 * where we don't normally have a context: eg, during sync calls
46 const GnomeVFSContext sync_context = {NULL};
49 * gnome_vfs_context_new:
51 * Creates a new context and cancellation object. Must be called
52 * from the main glib event loop.
54 * Return value: a newly allocated #GnomeVFSContext
57 gnome_vfs_context_new (void)
61 GNOME_VFS_ASSERT_PRIMARY_THREAD;
63 ctx = g_new0(GnomeVFSContext, 1);
65 ctx->cancellation = gnome_vfs_cancellation_new();
71 * gnome_vfs_context_free:
72 * @ctx: context to be freed
74 * Free @ctx and destroy the associated #GnomeVFSCancellation.
77 gnome_vfs_context_free (GnomeVFSContext *ctx)
79 g_return_if_fail(ctx != NULL);
81 gnome_vfs_cancellation_destroy(ctx->cancellation);
87 * gnome_vfs_context_get_cancellation:
88 * @ctx: context to get the #GnomeVFSCancellation from
90 * Retrieve the #GnomeVFSCancellation associated with @ctx.
92 * Return value: @ctx 's #GnomeVFSCancellation
95 gnome_vfs_context_get_cancellation (const GnomeVFSContext *ctx)
97 g_return_val_if_fail(ctx != NULL, NULL);
98 return ctx->cancellation;
102 * gnome_vfs_context_peek_current:
104 * Get the currently active context. It shouldn't be
105 * manipulated but can be compared to context's the module
106 * holds to determine whether they are active.
108 * Return value: the currently active #GnomeVFSContext
110 const GnomeVFSContext *
111 gnome_vfs_context_peek_current (void)
113 const GnomeVFSContext *ret;
115 _gnome_vfs_get_current_context ((GnomeVFSContext **)&ret);
117 /* If the context is NULL, then this must be a synchronous call */
126 * gnome_vfs_context_check_cancellation_current:
128 * Check to see if the currently active context has been cancelled.
130 * Return value: %TRUE if the currently active context has been cancelled, otherwise %FALSE
133 gnome_vfs_context_check_cancellation_current (void)
135 const GnomeVFSContext *current_ctx;
137 current_ctx = gnome_vfs_context_peek_current ();
139 if (current_ctx == &sync_context) {
141 } else if (current_ctx != NULL) {
142 return gnome_vfs_cancellation_check (gnome_vfs_context_get_cancellation (current_ctx));