gio/tests/file: skip the file monitor tests if using GPollFileMonitor
[platform/upstream/glib.git] / gio / gvfs.c
1 /* GIO - GLib Input, Output and Streaming Library
2  *
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  *
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.
9  *
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.
14  *
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.
19  *
20  * Author: Alexander Larsson <alexl@redhat.com>
21  */
22
23 #include "config.h"
24 #include <string.h>
25 #include "gvfs.h"
26 #include "glocalvfs.h"
27 #include "gresourcefile.h"
28 #include "giomodule-priv.h"
29 #include "glibintl.h"
30
31
32 /**
33  * SECTION:gvfs
34  * @short_description: Virtual File System
35  * @include: gio/gio.h
36  *
37  * Entry point for using GIO functionality.
38  *
39  */
40
41 G_DEFINE_TYPE (GVfs, g_vfs, G_TYPE_OBJECT);
42
43 static void
44 g_vfs_class_init (GVfsClass *klass)
45 {
46 }
47
48 static void
49 g_vfs_init (GVfs *vfs)
50 {
51 }
52
53 /**
54  * g_vfs_is_active:
55  * @vfs: a #GVfs.
56  *
57  * Checks if the VFS is active.
58  *
59  * Returns: %TRUE if construction of the @vfs was successful
60  *     and it is now active.
61  */
62 gboolean
63 g_vfs_is_active (GVfs *vfs)
64 {
65   GVfsClass *class;
66
67   g_return_val_if_fail (G_IS_VFS (vfs), FALSE);
68
69   class = G_VFS_GET_CLASS (vfs);
70
71   return (* class->is_active) (vfs);
72 }
73
74
75 /**
76  * g_vfs_get_file_for_path:
77  * @vfs: a #GVfs.
78  * @path: a string containing a VFS path.
79  *
80  * Gets a #GFile for @path.
81  *
82  * Returns: (transfer full): a #GFile.
83  *     Free the returned object with g_object_unref().
84  */
85 GFile *
86 g_vfs_get_file_for_path (GVfs       *vfs,
87                          const char *path)
88 {
89   GVfsClass *class;
90  
91   g_return_val_if_fail (G_IS_VFS (vfs), NULL);
92   g_return_val_if_fail (path != NULL, NULL);
93
94   class = G_VFS_GET_CLASS (vfs);
95
96   return (* class->get_file_for_path) (vfs, path);
97 }
98
99 /**
100  * g_vfs_get_file_for_uri:
101  * @vfs: a#GVfs.
102  * @uri: a string containing a URI
103  *
104  * Gets a #GFile for @uri.
105  *
106  * This operation never fails, but the returned object
107  * might not support any I/O operation if the URI
108  * is malformed or if the URI scheme is not supported.
109  *
110  * Returns: (transfer full): a #GFile.
111  *     Free the returned object with g_object_unref().
112  */
113 GFile *
114 g_vfs_get_file_for_uri (GVfs       *vfs,
115                         const char *uri)
116 {
117   GVfsClass *class;
118  
119   g_return_val_if_fail (G_IS_VFS (vfs), NULL);
120   g_return_val_if_fail (uri != NULL, NULL);
121
122   class = G_VFS_GET_CLASS (vfs);
123
124   /* This is an unfortunate placement, but we really
125    * need to check this before chaining to the vfs,
126    * because we want to support resource uris for
127    * all vfs:es, even those that predate resources.
128    */
129   if (g_str_has_prefix (uri, "resource:"))
130     return _g_resource_file_new (uri);
131
132   return (* class->get_file_for_uri) (vfs, uri);
133 }
134
135 /**
136  * g_vfs_get_supported_uri_schemes:
137  * @vfs: a #GVfs.
138  *
139  * Gets a list of URI schemes supported by @vfs.
140  *
141  * Returns: (transfer none): a %NULL-terminated array of strings.
142  *     The returned array belongs to GIO and must
143  *     not be freed or modified.
144  */
145 const gchar * const *
146 g_vfs_get_supported_uri_schemes (GVfs *vfs)
147 {
148   GVfsClass *class;
149
150   g_return_val_if_fail (G_IS_VFS (vfs), NULL);
151
152   class = G_VFS_GET_CLASS (vfs);
153
154   return (* class->get_supported_uri_schemes) (vfs);
155 }
156
157 /**
158  * g_vfs_parse_name:
159  * @vfs: a #GVfs.
160  * @parse_name: a string to be parsed by the VFS module.
161  *
162  * This operation never fails, but the returned object might
163  * not support any I/O operations if the @parse_name cannot
164  * be parsed by the #GVfs module.
165  *
166  * Returns: (transfer full): a #GFile for the given @parse_name.
167  *     Free the returned object with g_object_unref().
168  */
169 GFile *
170 g_vfs_parse_name (GVfs       *vfs,
171                   const char *parse_name)
172 {
173   GVfsClass *class;
174
175   g_return_val_if_fail (G_IS_VFS (vfs), NULL);
176   g_return_val_if_fail (parse_name != NULL, NULL);
177
178   class = G_VFS_GET_CLASS (vfs);
179
180   if (g_str_has_prefix (parse_name, "resource:"))
181     return _g_resource_file_new (parse_name);
182
183   return (* class->parse_name) (vfs, parse_name);
184 }
185
186 /**
187  * g_vfs_get_default:
188  *
189  * Gets the default #GVfs for the system.
190  *
191  * Returns: (transfer none): a #GVfs.
192  */
193 GVfs *
194 g_vfs_get_default (void)
195 {
196   return _g_io_module_get_default (G_VFS_EXTENSION_POINT_NAME,
197                                    "GIO_USE_VFS",
198                                    (GIOModuleVerifyFunc)g_vfs_is_active);
199 }
200
201 /**
202  * g_vfs_get_local:
203  *
204  * Gets the local #GVfs for the system.
205  *
206  * Returns: (transfer none): a #GVfs.
207  */
208 GVfs *
209 g_vfs_get_local (void)
210 {
211   static gsize vfs = 0;
212
213   if (g_once_init_enter (&vfs))
214     g_once_init_leave (&vfs, (gsize)_g_local_vfs_new ());
215
216   return G_VFS (vfs);
217 }