1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ |
---|
2 | /* gnome-vfs-method.h - Virtual class for access methods in the GNOME |
---|
3 | Virtual File System. |
---|
4 | |
---|
5 | Copyright (C) 1999, 2001 Free Software Foundation |
---|
6 | |
---|
7 | The Gnome Library is free software; you can redistribute it and/or |
---|
8 | modify it under the terms of the GNU Library General Public License as |
---|
9 | published by the Free Software Foundation; either version 2 of the |
---|
10 | License, or (at your option) any later version. |
---|
11 | |
---|
12 | The Gnome Library is distributed in the hope that it will be useful, |
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
15 | Library General Public License for more details. |
---|
16 | |
---|
17 | You should have received a copy of the GNU Library General Public |
---|
18 | License along with the Gnome Library; see the file COPYING.LIB. If not, |
---|
19 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
20 | Boston, MA 02111-1307, USA. |
---|
21 | |
---|
22 | Author: Ettore Perazzoli <ettore@comm2000.it> |
---|
23 | Seth Nickell <snickell@stanford.edu> |
---|
24 | */ |
---|
25 | |
---|
26 | #ifndef GNOME_VFS_METHOD_H |
---|
27 | #define GNOME_VFS_METHOD_H |
---|
28 | |
---|
29 | #include <libgnomevfs/gnome-vfs-context.h> |
---|
30 | #include <libgnomevfs/gnome-vfs-directory-filter.h> |
---|
31 | #include <libgnomevfs/gnome-vfs-file-info.h> |
---|
32 | #include <libgnomevfs/gnome-vfs-find-directory.h> |
---|
33 | #include <libgnomevfs/gnome-vfs-transform.h> |
---|
34 | |
---|
35 | /* Open mode. If you don't set `GNOME_VFS_OPEN_RANDOM', you have to access the |
---|
36 | file sequentially. */ |
---|
37 | typedef enum { |
---|
38 | GNOME_VFS_OPEN_NONE = 0, |
---|
39 | GNOME_VFS_OPEN_READ = 1 << 0, |
---|
40 | GNOME_VFS_OPEN_WRITE = 1 << 1, |
---|
41 | GNOME_VFS_OPEN_RANDOM = 1 << 2 |
---|
42 | } GnomeVFSOpenMode; |
---|
43 | |
---|
44 | /* This is used to specify the start position for seek operations. */ |
---|
45 | typedef enum { |
---|
46 | GNOME_VFS_SEEK_START, |
---|
47 | GNOME_VFS_SEEK_CURRENT, |
---|
48 | GNOME_VFS_SEEK_END |
---|
49 | } GnomeVFSSeekPosition; |
---|
50 | |
---|
51 | typedef gpointer GnomeVFSMethodHandle; |
---|
52 | |
---|
53 | #define _GNOME_VFS_METHOD_PARAM_CHECK(expression) \ |
---|
54 | g_return_val_if_fail ((expression), GNOME_VFS_ERROR_BAD_PARAMETERS); |
---|
55 | |
---|
56 | typedef struct GnomeVFSMethod GnomeVFSMethod; |
---|
57 | |
---|
58 | typedef GnomeVFSMethod * (* GnomeVFSMethodInitFunc)(const char *method_name, const char *config_args); |
---|
59 | typedef void (*GnomeVFSMethodShutdownFunc)(GnomeVFSMethod *method); |
---|
60 | |
---|
61 | typedef GnomeVFSResult (* GnomeVFSMethodOpenFunc) |
---|
62 | (GnomeVFSMethod *method, |
---|
63 | GnomeVFSMethodHandle |
---|
64 | **method_handle_return, |
---|
65 | GnomeVFSURI *uri, |
---|
66 | GnomeVFSOpenMode mode, |
---|
67 | GnomeVFSContext *context); |
---|
68 | |
---|
69 | typedef GnomeVFSResult (* GnomeVFSMethodCreateFunc) |
---|
70 | (GnomeVFSMethod *method, |
---|
71 | GnomeVFSMethodHandle |
---|
72 | **method_handle_return, |
---|
73 | GnomeVFSURI *uri, |
---|
74 | GnomeVFSOpenMode mode, |
---|
75 | gboolean exclusive, |
---|
76 | guint perm, |
---|
77 | GnomeVFSContext *context); |
---|
78 | |
---|
79 | typedef GnomeVFSResult (* GnomeVFSMethodCloseFunc) |
---|
80 | (GnomeVFSMethod *method, |
---|
81 | GnomeVFSMethodHandle *method_handle, |
---|
82 | GnomeVFSContext *context); |
---|
83 | |
---|
84 | typedef GnomeVFSResult (* GnomeVFSMethodReadFunc) |
---|
85 | (GnomeVFSMethod *method, |
---|
86 | GnomeVFSMethodHandle *method_handle, |
---|
87 | gpointer buffer, |
---|
88 | GnomeVFSFileSize num_bytes, |
---|
89 | GnomeVFSFileSize *bytes_read_return, |
---|
90 | GnomeVFSContext *context); |
---|
91 | |
---|
92 | typedef GnomeVFSResult (* GnomeVFSMethodWriteFunc) |
---|
93 | (GnomeVFSMethod *method, |
---|
94 | GnomeVFSMethodHandle *method_handle, |
---|
95 | gconstpointer buffer, |
---|
96 | GnomeVFSFileSize num_bytes, |
---|
97 | GnomeVFSFileSize *bytes_written_return, |
---|
98 | GnomeVFSContext *context); |
---|
99 | |
---|
100 | typedef GnomeVFSResult (* GnomeVFSMethodSeekFunc) |
---|
101 | (GnomeVFSMethod *method, |
---|
102 | GnomeVFSMethodHandle *method_handle, |
---|
103 | GnomeVFSSeekPosition whence, |
---|
104 | GnomeVFSFileOffset offset, |
---|
105 | GnomeVFSContext *context); |
---|
106 | |
---|
107 | typedef GnomeVFSResult (* GnomeVFSMethodTellFunc) |
---|
108 | (GnomeVFSMethod *method, |
---|
109 | GnomeVFSMethodHandle *method_handle, |
---|
110 | GnomeVFSFileOffset *offset_return); |
---|
111 | |
---|
112 | typedef GnomeVFSResult (* GnomeVFSMethodOpenDirectoryFunc) |
---|
113 | (GnomeVFSMethod *method, |
---|
114 | GnomeVFSMethodHandle **method_handle, |
---|
115 | GnomeVFSURI *uri, |
---|
116 | GnomeVFSFileInfoOptions options, |
---|
117 | const GnomeVFSDirectoryFilter *filter, |
---|
118 | GnomeVFSContext *context); |
---|
119 | |
---|
120 | typedef GnomeVFSResult (* GnomeVFSMethodCloseDirectoryFunc) |
---|
121 | (GnomeVFSMethod *method, |
---|
122 | GnomeVFSMethodHandle *method_handle, |
---|
123 | GnomeVFSContext *context); |
---|
124 | |
---|
125 | typedef GnomeVFSResult (* GnomeVFSMethodReadDirectoryFunc) |
---|
126 | (GnomeVFSMethod *method, |
---|
127 | GnomeVFSMethodHandle *method_handle, |
---|
128 | GnomeVFSFileInfo *file_info, |
---|
129 | GnomeVFSContext *context); |
---|
130 | |
---|
131 | typedef GnomeVFSResult (* GnomeVFSMethodGetFileInfoFunc) |
---|
132 | (GnomeVFSMethod *method, |
---|
133 | GnomeVFSURI *uri, |
---|
134 | GnomeVFSFileInfo *file_info, |
---|
135 | GnomeVFSFileInfoOptions options, |
---|
136 | GnomeVFSContext *context); |
---|
137 | |
---|
138 | typedef GnomeVFSResult (* GnomeVFSMethodGetFileInfoFromHandleFunc) |
---|
139 | (GnomeVFSMethod *method, |
---|
140 | GnomeVFSMethodHandle *method_handle, |
---|
141 | GnomeVFSFileInfo *file_info, |
---|
142 | GnomeVFSFileInfoOptions options, |
---|
143 | GnomeVFSContext *context); |
---|
144 | |
---|
145 | typedef GnomeVFSResult (* GnomeVFSMethodTruncateFunc) (GnomeVFSMethod *method, |
---|
146 | GnomeVFSURI *uri, |
---|
147 | GnomeVFSFileSize length, |
---|
148 | GnomeVFSContext *context); |
---|
149 | typedef GnomeVFSResult (* GnomeVFSMethodTruncateHandleFunc) (GnomeVFSMethod *method, |
---|
150 | GnomeVFSMethodHandle *handle, |
---|
151 | GnomeVFSFileSize length, |
---|
152 | GnomeVFSContext *context); |
---|
153 | |
---|
154 | typedef gboolean (* GnomeVFSMethodIsLocalFunc) |
---|
155 | (GnomeVFSMethod *method, |
---|
156 | const GnomeVFSURI *uri); |
---|
157 | |
---|
158 | typedef GnomeVFSResult (* GnomeVFSMethodMakeDirectoryFunc) |
---|
159 | (GnomeVFSMethod *method, |
---|
160 | GnomeVFSURI *uri, |
---|
161 | guint perm, |
---|
162 | GnomeVFSContext *context); |
---|
163 | |
---|
164 | typedef GnomeVFSResult (* GnomeVFSMethodFindDirectoryFunc) |
---|
165 | (GnomeVFSMethod *method, |
---|
166 | GnomeVFSURI *find_near_uri, |
---|
167 | GnomeVFSFindDirectoryKind kind, |
---|
168 | GnomeVFSURI **result_uri, |
---|
169 | gboolean create_if_needed, |
---|
170 | gboolean find_if_needed, |
---|
171 | guint perm, |
---|
172 | GnomeVFSContext *context); |
---|
173 | |
---|
174 | typedef GnomeVFSResult (* GnomeVFSMethodRemoveDirectoryFunc) |
---|
175 | (GnomeVFSMethod *method, |
---|
176 | GnomeVFSURI *uri, |
---|
177 | GnomeVFSContext *context); |
---|
178 | |
---|
179 | typedef GnomeVFSResult (* GnomeVFSMethodMoveFunc) |
---|
180 | (GnomeVFSMethod *method, |
---|
181 | GnomeVFSURI *old_uri, |
---|
182 | GnomeVFSURI *new_uri, |
---|
183 | gboolean force_replace, |
---|
184 | GnomeVFSContext *context); |
---|
185 | |
---|
186 | typedef GnomeVFSResult (* GnomeVFSMethodUnlinkFunc) |
---|
187 | (GnomeVFSMethod *method, |
---|
188 | GnomeVFSURI *uri, |
---|
189 | GnomeVFSContext *context); |
---|
190 | |
---|
191 | typedef GnomeVFSResult (* GnomeVFSMethodCheckSameFSFunc) |
---|
192 | (GnomeVFSMethod *method, |
---|
193 | GnomeVFSURI *a, |
---|
194 | GnomeVFSURI *b, |
---|
195 | gboolean *same_fs_return, |
---|
196 | GnomeVFSContext *context); |
---|
197 | |
---|
198 | typedef GnomeVFSResult (* GnomeVFSMethodSetFileInfo) |
---|
199 | (GnomeVFSMethod *method, |
---|
200 | GnomeVFSURI *a, |
---|
201 | const GnomeVFSFileInfo *info, |
---|
202 | GnomeVFSSetFileInfoMask mask, |
---|
203 | GnomeVFSContext *context); |
---|
204 | |
---|
205 | typedef GnomeVFSResult (* GnomeVFSMethodCreateSymbolicLinkFunc) |
---|
206 | (GnomeVFSMethod *method, |
---|
207 | GnomeVFSURI *uri, |
---|
208 | const gchar *target_reference, |
---|
209 | GnomeVFSContext *context); |
---|
210 | |
---|
211 | |
---|
212 | |
---|
213 | /* Use this macro to test whether a given function is implemented in |
---|
214 | * a given GnomeVFSMethod. Note that it checks the expected size of the structure |
---|
215 | * prior to testing NULL. |
---|
216 | */ |
---|
217 | |
---|
218 | #define VFS_METHOD_HAS_FUNC(method,func) ((((char *)&((method)->func)) - ((char *)(method)) < (method)->method_table_size) && method->func != NULL) |
---|
219 | |
---|
220 | /* Structure defining an access method. This is also defined as an |
---|
221 | opaque type in `gnome-vfs-types.h'. */ |
---|
222 | struct GnomeVFSMethod { |
---|
223 | gsize method_table_size; /* Used for versioning */ |
---|
224 | GnomeVFSMethodOpenFunc open; |
---|
225 | GnomeVFSMethodCreateFunc create; |
---|
226 | GnomeVFSMethodCloseFunc close; |
---|
227 | GnomeVFSMethodReadFunc read; |
---|
228 | GnomeVFSMethodWriteFunc write; |
---|
229 | GnomeVFSMethodSeekFunc seek; |
---|
230 | GnomeVFSMethodTellFunc tell; |
---|
231 | GnomeVFSMethodTruncateHandleFunc truncate_handle; |
---|
232 | GnomeVFSMethodOpenDirectoryFunc open_directory; |
---|
233 | GnomeVFSMethodCloseDirectoryFunc close_directory; |
---|
234 | GnomeVFSMethodReadDirectoryFunc read_directory; |
---|
235 | GnomeVFSMethodGetFileInfoFunc get_file_info; |
---|
236 | GnomeVFSMethodGetFileInfoFromHandleFunc get_file_info_from_handle; |
---|
237 | GnomeVFSMethodIsLocalFunc is_local; |
---|
238 | GnomeVFSMethodMakeDirectoryFunc make_directory; |
---|
239 | GnomeVFSMethodRemoveDirectoryFunc remove_directory; |
---|
240 | GnomeVFSMethodMoveFunc move; |
---|
241 | GnomeVFSMethodUnlinkFunc unlink; |
---|
242 | GnomeVFSMethodCheckSameFSFunc check_same_fs; |
---|
243 | GnomeVFSMethodSetFileInfo set_file_info; |
---|
244 | GnomeVFSMethodTruncateFunc truncate; |
---|
245 | GnomeVFSMethodFindDirectoryFunc find_directory; |
---|
246 | GnomeVFSMethodCreateSymbolicLinkFunc create_symbolic_link; |
---|
247 | }; |
---|
248 | |
---|
249 | gboolean gnome_vfs_method_init (void); |
---|
250 | GnomeVFSMethod *gnome_vfs_method_get (const gchar *name); |
---|
251 | GnomeVFSTransform *gnome_vfs_transform_get (const gchar *name); |
---|
252 | |
---|
253 | #endif /* GNOME_VFS_METHOD_H */ |
---|