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-priv.h"
33 * @short_description: Virtual File System
36 * Entry point for using GIO functionality.
40 G_DEFINE_TYPE (GVfs, g_vfs, G_TYPE_OBJECT);
43 g_vfs_class_init (GVfsClass *klass)
48 g_vfs_init (GVfs *vfs)
56 * Checks if the VFS is active.
58 * Returns: %TRUE if construction of the @vfs was successful and it is now active.
61 g_vfs_is_active (GVfs *vfs)
65 g_return_val_if_fail (G_IS_VFS (vfs), FALSE);
67 class = G_VFS_GET_CLASS (vfs);
69 return (* class->is_active) (vfs);
74 * g_vfs_get_file_for_path:
76 * @path: a string containing a VFS path.
78 * Gets a #GFile for @path.
81 * Free the returned object with g_object_unref().
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
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 scheme is not supported.
109 * Free the returned object with g_object_unref().
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 %NULL-terminated array of strings.
132 * The returned array belongs to GIO and must
133 * not be freed or modified.
135 const gchar * const *
136 g_vfs_get_supported_uri_schemes (GVfs *vfs)
140 g_return_val_if_fail (G_IS_VFS (vfs), NULL);
142 class = G_VFS_GET_CLASS (vfs);
144 return (* class->get_supported_uri_schemes) (vfs);
150 * @parse_name: a string to be parsed by the VFS module.
152 * This operation never fails, but the returned object might
153 * not support any I/O operations if the @parse_name cannot
154 * be parsed by the #GVfs module.
156 * Returns: a #GFile for the given @parse_name.
157 * Free the returned object with g_object_unref().
160 g_vfs_parse_name (GVfs *vfs,
161 const char *parse_name)
165 g_return_val_if_fail (G_IS_VFS (vfs), NULL);
166 g_return_val_if_fail (parse_name != NULL, NULL);
168 class = G_VFS_GET_CLASS (vfs);
170 return (* class->parse_name) (vfs, parse_name);
174 get_default_vfs (gpointer arg)
176 const char *use_this;
179 GIOExtensionPoint *ep;
180 GIOExtension *extension;
183 use_this = g_getenv ("GIO_USE_VFS");
185 /* Ensure vfs in modules loaded */
186 _g_io_modules_ensure_loaded ();
188 ep = g_io_extension_point_lookup (G_VFS_EXTENSION_POINT_NAME);
192 extension = g_io_extension_point_get_extension_by_name (ep, use_this);
195 vfs = g_object_new (g_io_extension_get_type (extension), NULL);
197 if (g_vfs_is_active (vfs))
200 g_object_unref (vfs);
204 for (l = g_io_extension_point_get_extensions (ep); l != NULL; l = l->next)
208 vfs = g_object_new (g_io_extension_get_type (extension), NULL);
210 if (g_vfs_is_active (vfs))
213 g_object_unref (vfs);
223 * Gets the default #GVfs for the system.
228 g_vfs_get_default (void)
230 static GOnce once_init = G_ONCE_INIT;
232 return g_once (&once_init, get_default_vfs, NULL);
238 * Gets the local #GVfs for the system.
243 g_vfs_get_local (void)
245 static gsize vfs = 0;
247 if (g_once_init_enter (&vfs))
248 g_once_init_leave (&vfs, (gsize)_g_local_vfs_new ());