1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
26 #include "glocalvfs.h"
27 #include "giomodule.h"
34 * @short_description: Virtual File System
35 * @include: gio/gvfs.h
37 * Entry point for using GIO functionality.
41 G_DEFINE_TYPE (GVfs, g_vfs, G_TYPE_OBJECT);
44 g_vfs_class_init (GVfsClass *klass)
49 g_vfs_init (GVfs *vfs)
57 * Checks if the VFS is active.
59 * Returns: %TRUE if construction of the @vfs was successful and it is now active.
62 g_vfs_is_active (GVfs *vfs)
66 g_return_val_if_fail (G_IS_VFS (vfs), FALSE);
68 class = G_VFS_GET_CLASS (vfs);
70 return (* class->is_active) (vfs);
75 * g_vfs_get_file_for_path:
77 * @path: a string containing a VFS path.
79 * Gets a #GFile for @path.
84 g_vfs_get_file_for_path (GVfs *vfs,
89 g_return_val_if_fail (G_IS_VFS (vfs), NULL);
90 g_return_val_if_fail (path != NULL, NULL);
92 class = G_VFS_GET_CLASS (vfs);
94 return (* class->get_file_for_path) (vfs, path);
98 * g_vfs_get_file_for_uri:
100 * @uri: a string containing a URI path.
102 * Gets a #GFile for @uri.
104 * This operation never fails, but the returned object
105 * might not support any I/O operation if the uri
106 * is malformed or if the uri type is not supported.
112 g_vfs_get_file_for_uri (GVfs *vfs,
117 g_return_val_if_fail (G_IS_VFS (vfs), NULL);
118 g_return_val_if_fail (uri != NULL, NULL);
120 class = G_VFS_GET_CLASS (vfs);
122 return (* class->get_file_for_uri) (vfs, uri);
126 * g_vfs_get_supported_uri_schemes:
129 * Gets a list of URI schemes supported by @vfs.
131 * Returns: a list of strings.
133 const gchar * const *
134 g_vfs_get_supported_uri_schemes (GVfs *vfs)
138 g_return_val_if_fail (G_IS_VFS (vfs), NULL);
140 class = G_VFS_GET_CLASS (vfs);
142 return (* class->get_supported_uri_schemes) (vfs);
148 * @parse_name: a string to be parsed by the VFS module.
150 * This operation never fails, but the returned object might
151 * not support any I/O operations if the @parse_name cannot
152 * be parsed by the #GVfs module.
154 * Returns: a #GFile for the given @parse_name.
157 g_vfs_parse_name (GVfs *vfs,
158 const char *parse_name)
162 g_return_val_if_fail (G_IS_VFS (vfs), NULL);
163 g_return_val_if_fail (parse_name != NULL, NULL);
165 class = G_VFS_GET_CLASS (vfs);
167 return (* class->parse_name) (vfs, parse_name);
170 /* Note: This compares in reverse order.
171 Higher prio -> sort first
174 compare_vfs_type (gconstpointer a,
178 GVfsClass *class_a, *class_b;
180 const char *use_this_vfs;
182 class_a = g_type_class_ref (*(GType *)a);
183 class_b = g_type_class_ref (*(GType *)b);
184 use_this_vfs = user_data;
186 if (class_a == class_b)
188 else if (use_this_vfs != NULL &&
189 strcmp (class_a->name, use_this_vfs) == 0)
191 else if (use_this_vfs != NULL &&
192 strcmp (class_b->name, use_this_vfs) == 0)
195 res = class_b->priority - class_a->priority;
197 g_type_class_unref (class_a);
198 g_type_class_unref (class_b);
205 get_default_vfs (gpointer arg)
207 volatile GType local_type;
211 const char *use_this;
213 GType (*casted_get_type)(void);
215 use_this = g_getenv ("GIO_USE_VFS");
217 /* Ensure GLocalVfs type is available
218 the cast is required to avoid any G_GNUC_CONST optimizations */
219 casted_get_type = _g_local_vfs_get_type;
220 local_type = casted_get_type ();
222 /* Ensure vfs in modules loaded */
223 _g_io_modules_ensure_loaded ();
225 vfs_impls = g_type_children (G_TYPE_VFS, &n_vfs_impls);
227 g_qsort_with_data (vfs_impls, n_vfs_impls, sizeof (GType),
228 compare_vfs_type, (gpointer)use_this);
230 for (i = 0; i < n_vfs_impls; i++)
232 vfs = g_object_new (vfs_impls[i], NULL);
234 if (g_vfs_is_active (vfs))
237 g_object_unref (vfs);
249 * Gets the default #GVfs for the system.
254 g_vfs_get_default (void)
256 static GOnce once_init = G_ONCE_INIT;
258 return g_once (&once_init, get_default_vfs, NULL);
264 * Gets the local #GVfs for the system.
269 g_vfs_get_local (void)
271 static gsize vfs = 0;
273 if (g_once_init_enter (&vfs))
274 g_once_init_leave (&vfs, (gsize)_g_local_vfs_new ());
280 #include "gioaliasdef.c"