File: gnome-vfs-context.c

package info (click to toggle)
gnome-vfs 1%3A2.24.4-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 17,120 kB
  • ctags: 10,397
  • sloc: ansic: 78,516; sh: 10,341; makefile: 902; perl: 99
file content (144 lines) | stat: -rw-r--r-- 3,790 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* gnome-vfs-context.c - context VFS modules can use to communicate with gnome-vfs proper

   Copyright (C) 1999 Free Software Foundation

   The Gnome Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The Gnome Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Author: Havoc Pennington <hp@redhat.com> */

#include <config.h>
#include "gnome-vfs-context.h"

#include "gnome-vfs-backend.h"
#include "gnome-vfs-cancellation.h"
#include "gnome-vfs-private-utils.h"
#include "gnome-vfs-utils.h"
#include <stdio.h>

#if 1
#define DEBUG_MSG (x) printf x
#else
#define DEBUG_MSG (x)
#endif


struct GnomeVFSContext {
        GnomeVFSCancellation *cancellation;
};

/* This is a token Context to return in situations
 * where we don't normally have a context: eg, during sync calls
 */
static const GnomeVFSContext sync_context = {NULL};

/**
 * gnome_vfs_context_new:
 * 
 * Creates a new context and cancellation object. Must be called
 * from the main glib event loop.
 *
 * Return value: a newly allocated #GnomeVFSContext.
 */
GnomeVFSContext*
gnome_vfs_context_new (void)
{
        GnomeVFSContext *ctx;

        ctx = g_new0(GnomeVFSContext, 1);

        ctx->cancellation = gnome_vfs_cancellation_new();
 
        return ctx;
}

/**
 * gnome_vfs_context_free:
 * @ctx: context to be freed.
 *
 * Free @ctx and destroy the associated #GnomeVFSCancellation.
 */
void
gnome_vfs_context_free (GnomeVFSContext *ctx)
{
        g_return_if_fail(ctx != NULL);
  
	gnome_vfs_cancellation_destroy(ctx->cancellation);
	
	g_free(ctx);
}

/**
 * gnome_vfs_context_get_cancellation:
 * @ctx: context to get the #GnomeVFSCancellation from.
 *
 * Retrieve the #GnomeVFSCancellation associated with @ctx.
 *
 * Return value: @ctx 's #GnomeVFSCancellation.
 */
GnomeVFSCancellation*
gnome_vfs_context_get_cancellation (const GnomeVFSContext *ctx)
{
        g_return_val_if_fail(ctx != NULL, NULL);
        return ctx->cancellation;
}

/**
 * gnome_vfs_context_peek_current:
 *
 * Get the currently active context. It shouldn't be
 * manipulated but can be compared to contexts module
 * holds to determine whether they are active.
 *
 * Return value: the currently active #GnomeVFSContext.
 */
const GnomeVFSContext *
gnome_vfs_context_peek_current		  (void)
{
	const GnomeVFSContext *ret;
	
	_gnome_vfs_get_current_context ((GnomeVFSContext **)&ret);

	/* If the context is NULL, then this must be a synchronous call */
	if (ret == NULL) {
		ret = &sync_context;
	}

	return ret;
}

/**
 * gnome_vfs_context_check_cancellation_current:
 * 
 * Check to see if the currently active context has been cancelled.
 *
 * Return value: %TRUE if the currently active context has been cancelled, otherwise %FALSE.
 */
gboolean
gnome_vfs_context_check_cancellation_current (void)
{
	const GnomeVFSContext *current_ctx;

	current_ctx = gnome_vfs_context_peek_current ();

	if (current_ctx == &sync_context) {
		return FALSE;
	} else if (current_ctx != NULL) {
		return gnome_vfs_cancellation_check (gnome_vfs_context_get_cancellation (current_ctx));
	} else {
		return FALSE;
	}	
}