source: trunk/third/gnome-vfs/libgnomevfs/gnome-vfs-backend.c @ 15497

Revision 15497, 16.8 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r15496, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
3/* gnome-vfs-backend.c - Handling of asynchronocity backends in the GNOME
4                         Virtual File System.
5
6   Copyright (C) 2000 Red Hat, Inc.
7   Copyright (C) 2000 Eazel, Inc.
8   All rights reserved.
9
10   The Gnome Library is free software; you can redistribute it and/or
11   modify it under the terms of the GNU Library General Public License as
12   published by the Free Software Foundation; either version 2 of the
13   License, or (at your option) any later version.
14
15   The Gnome Library is distributed in the hope that it will be useful,
16   but WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18   Library General Public License for more details.
19
20   You should have received a copy of the GNU Library General Public
21   License along with the Gnome Library; see the file COPYING.LIB.  If not,
22   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23   Boston, MA 02111-1307, USA.
24
25   Author: Elliot Lee <sopwith@redhat.com>
26*/
27
28#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif
31#include "gnome-vfs-backend.h"
32#include "gnome-vfs-types.h"
33#include "gnome-vfs-private-types.h"
34
35#include "gnome-vfs.h"
36#include <gmodule.h>
37#include <string.h>
38#include <unistd.h>
39#include <stdlib.h>
40
41static GModule *gmod = NULL;
42static gboolean (* gnome_vfs_backend_module_init)(gboolean deps_init);
43
44static char backend_lower[128] = "";
45
46const char *
47gnome_vfs_backend_name (void)
48{
49        return (*backend_lower) ? backend_lower : NULL;
50}
51
52void
53gnome_vfs_backend_loadinit (gpointer app, gpointer modinfo)
54{
55        const char *backend;
56        char backend_filename[256];
57
58        /* Decide which backend module to load, based on
59           (a) environment variable
60           (b) default
61        */
62        if (gmod != NULL) {
63                return;
64        }
65
66        backend = getenv ("GNOME_VFS_BACKEND");
67        if (backend == NULL) {
68                backend = GNOME_VFS_DEFAULT_BACKEND;
69        }
70
71        strcpy (backend_lower, backend);
72        g_strdown (backend_lower);
73
74        g_snprintf (backend_filename, sizeof (backend_filename),
75                "libgnomevfs-%s.so.0", backend_lower);
76
77        gmod = g_module_open (backend_filename, G_MODULE_BIND_LAZY);
78        if (gmod == NULL) {
79                g_error("Could not open %s: %s", backend_filename, g_module_error());
80        }
81        g_snprintf (backend_filename, sizeof (backend_filename),
82                "gnome_vfs_%s_init", backend_lower);
83
84        if (!g_module_symbol (gmod, backend_filename,
85                (gpointer *)&gnome_vfs_backend_module_init)) {
86                g_module_close (gmod);
87                gmod = NULL;
88                g_error("Could not locate module initialization function: %s", g_module_error());
89        }
90}
91
92gboolean
93gnome_vfs_backend_init (gboolean deps_init)
94{
95        g_assert (gmod);
96        g_assert (gnome_vfs_backend_init);
97
98        gnome_vfs_backend_module_init (deps_init);
99
100        return TRUE;
101}
102
103void
104gnome_vfs_backend_shutdown (void)
105{
106        /* find and call the backend shutdown function */
107        void (* thread_backend_shutdown_call) (void);
108       
109        g_assert (gmod);
110        if (g_module_symbol (gmod, "gnome_vfs_thread_backend_shutdown",
111                              (gpointer)&thread_backend_shutdown_call)) {
112                g_assert (thread_backend_shutdown_call);
113                (* thread_backend_shutdown_call) ();
114        }
115}
116
117typedef GnomeVFSResult (*GnomeVFSAsyncFunction) ();
118
119static GnomeVFSAsyncFunction
120func_lookup(const char *func_name)
121{
122        char *name;
123        gpointer function;
124
125        name = g_strdup_printf ("%s_%s", backend_lower, func_name);
126
127        g_assert (gmod);
128        if (!g_module_symbol (gmod, name, &function)) {
129                function = NULL;
130        }
131
132        g_free (name);
133
134        return (GnomeVFSAsyncFunction) function;
135}
136
137#define CALL_BACKEND(name, parameters) \
138G_STMT_START { \
139        if (real_##name == NULL) { \
140                real_##name = (void (*)()) func_lookup (#name); \
141        } \
142        if (real_##name == NULL) { \
143                g_warning ("can't find " #name " in the back end"); \
144        } else { \
145                real_##name parameters; \
146        } \
147} G_STMT_END
148
149#define CALL_BACKEND_RETURN(name, parameters) \
150G_STMT_START { \
151        if (real_##name == NULL) { \
152                real_##name = func_lookup (#name); \
153        } \
154        if (real_##name == NULL) { \
155                g_warning ("can't find " #name " in the back end"); \
156                return GNOME_VFS_ERROR_INTERNAL; \
157        } \
158        return real_##name parameters; \
159} G_STMT_END
160
161void
162gnome_vfs_async_open (GnomeVFSAsyncHandle **handle_return,
163                      const gchar *text_uri,
164                      GnomeVFSOpenMode open_mode,
165                      GnomeVFSAsyncOpenCallback callback,
166                      gpointer callback_data)
167{
168        static void     
169                (*real_gnome_vfs_async_open) (GnomeVFSAsyncHandle **handle_return,
170                                              const gchar *text_uri,
171                                              GnomeVFSOpenMode open_mode,
172                                              GnomeVFSAsyncOpenCallback callback,
173                                              gpointer callback_data) = NULL;
174
175        CALL_BACKEND (gnome_vfs_async_open,
176                      (handle_return, text_uri, open_mode, callback, callback_data));
177}
178
179void
180gnome_vfs_async_open_uri (GnomeVFSAsyncHandle **handle_return,
181                          GnomeVFSURI *uri,
182                          GnomeVFSOpenMode open_mode,
183                          GnomeVFSAsyncOpenCallback callback,
184                          gpointer callback_data)
185{
186        static void
187                (*real_gnome_vfs_async_open_uri) (GnomeVFSAsyncHandle **handle_return,
188                                                  GnomeVFSURI *uri,
189                                                  GnomeVFSOpenMode open_mode,
190                                                  GnomeVFSAsyncOpenCallback callback,
191                                                  gpointer callback_data) = NULL;
192
193        CALL_BACKEND (gnome_vfs_async_open_uri,
194                      (handle_return, uri, open_mode, callback, callback_data));
195}
196
197void
198gnome_vfs_async_open_as_channel (GnomeVFSAsyncHandle **handle_return,
199                                 const gchar *text_uri,
200                                 GnomeVFSOpenMode open_mode,
201                                 guint advised_block_size,
202                                 GnomeVFSAsyncOpenAsChannelCallback callback,
203                                 gpointer callback_data)
204{
205        static void
206                (*real_gnome_vfs_async_open_as_channel) (GnomeVFSAsyncHandle **handle_return,
207                                                         const gchar *text_uri,
208                                                         GnomeVFSOpenMode open_mode,
209                                                         guint advised_block_size,
210                                                         GnomeVFSAsyncOpenAsChannelCallback callback,
211                                                         gpointer callback_data) = NULL;
212
213        CALL_BACKEND (gnome_vfs_async_open_as_channel,
214                      (handle_return, text_uri, open_mode, advised_block_size,
215                       callback, callback_data));
216}
217
218void     
219gnome_vfs_async_create (GnomeVFSAsyncHandle **handle_return,
220                        const gchar *text_uri,
221                        GnomeVFSOpenMode open_mode,
222                        gboolean exclusive,
223                        guint perm,
224                        GnomeVFSAsyncOpenCallback callback,
225                        gpointer callback_data)
226{
227        static void
228                (*real_gnome_vfs_async_create) (GnomeVFSAsyncHandle **handle_return,
229                                                const gchar *text_uri,
230                                                GnomeVFSOpenMode open_mode,
231                                                gboolean exclusive,
232                                                guint perm,
233                                                GnomeVFSAsyncOpenCallback callback,
234                                                gpointer callback_data) = NULL;
235
236        CALL_BACKEND (gnome_vfs_async_create,
237                      (handle_return, text_uri, open_mode, exclusive, perm,
238                       callback, callback_data));
239}
240
241void
242gnome_vfs_async_create_as_channel (GnomeVFSAsyncHandle **handle_return,
243                                   const gchar *text_uri,
244                                   GnomeVFSOpenMode open_mode,
245                                   gboolean exclusive,
246                                   guint perm,
247                                   GnomeVFSAsyncOpenAsChannelCallback callback,
248                                   gpointer callback_data)
249{
250        static void
251                (*real_gnome_vfs_async_create_as_channel) (GnomeVFSAsyncHandle **handle_return,
252                                                           const gchar *text_uri,
253                                                           GnomeVFSOpenMode open_mode,
254                                                           gboolean exclusive,
255                                                           guint perm,
256                                                           GnomeVFSAsyncOpenAsChannelCallback callback,
257                                                           gpointer callback_data) = NULL;
258       
259        CALL_BACKEND (gnome_vfs_async_create_as_channel,
260                      (handle_return, text_uri, open_mode, exclusive, perm,
261                       callback, callback_data));
262}
263
264void
265gnome_vfs_async_create_uri (GnomeVFSAsyncHandle **handle_return,
266                            GnomeVFSURI *text_uri,
267                            GnomeVFSOpenMode open_mode,
268                            gboolean exclusive,
269                            guint perm,
270                            GnomeVFSAsyncOpenCallback callback,
271                            gpointer callback_data)
272{
273        static void
274                (*real_gnome_vfs_async_create_uri) (GnomeVFSAsyncHandle **handle_return,
275                                                    GnomeVFSURI *uri,
276                                                    GnomeVFSOpenMode open_mode,
277                                                    gboolean exclusive,
278                                                    guint perm,
279                                                    GnomeVFSAsyncOpenCallback callback,
280                                                    gpointer callback_data);
281
282        CALL_BACKEND (gnome_vfs_async_create_uri,
283                      (handle_return, text_uri, open_mode, exclusive, perm,
284                       callback, callback_data));
285}
286
287
288void
289gnome_vfs_async_create_symbolic_link (GnomeVFSAsyncHandle **handle_return,
290                                      GnomeVFSURI *uri,
291                                      const gchar *uri_reference,
292                                      GnomeVFSAsyncOpenCallback callback,
293                                      gpointer callback_data)
294{
295        static void
296                (*real_gnome_vfs_async_create_symbolic_link) (GnomeVFSAsyncHandle **handle_return,
297                                                              GnomeVFSURI *uri,
298                                                              const gchar *uri_reference,
299                                                              GnomeVFSAsyncOpenCallback callback,
300                                                              gpointer callback_data);
301
302        CALL_BACKEND (gnome_vfs_async_create_symbolic_link,
303                      (handle_return, uri, uri_reference, callback, callback_data));
304}
305
306void     
307gnome_vfs_async_close (GnomeVFSAsyncHandle *handle,
308                       GnomeVFSAsyncCloseCallback callback,
309                       gpointer callback_data)
310{
311        static void
312                (*real_gnome_vfs_async_close) (GnomeVFSAsyncHandle *handle,
313                                               GnomeVFSAsyncCloseCallback callback,
314                                               gpointer callback_data);
315
316        CALL_BACKEND (gnome_vfs_async_close,
317                      (handle, callback, callback_data));
318}
319
320void     
321gnome_vfs_async_read (GnomeVFSAsyncHandle *handle,
322                      gpointer buffer,
323                      guint bytes,
324                      GnomeVFSAsyncReadCallback callback,
325                      gpointer callback_data)
326{
327        static void
328                (*real_gnome_vfs_async_read) (GnomeVFSAsyncHandle *handle,
329                                              gpointer buffer,
330                                              guint bytes,
331                                              GnomeVFSAsyncReadCallback callback,
332                                              gpointer callback_data);
333
334        CALL_BACKEND (gnome_vfs_async_read,
335                      (handle, buffer, bytes,
336                       callback, callback_data));
337}
338
339void     
340gnome_vfs_async_write (GnomeVFSAsyncHandle *handle,
341                       gconstpointer buffer,
342                       guint bytes,
343                       GnomeVFSAsyncWriteCallback callback,
344                       gpointer callback_data)
345{
346        static void
347                (*real_gnome_vfs_async_write) (GnomeVFSAsyncHandle *handle,
348                                               gconstpointer buffer,
349                                               guint bytes,
350                                               GnomeVFSAsyncWriteCallback callback,
351                                               gpointer callback_data);
352
353        CALL_BACKEND (gnome_vfs_async_write,
354                      (handle, buffer, bytes,
355                       callback, callback_data));
356}
357
358void
359gnome_vfs_async_get_file_info  (GnomeVFSAsyncHandle **handle_return,
360                                GList *uris,
361                                GnomeVFSFileInfoOptions options,
362                                GnomeVFSAsyncGetFileInfoCallback callback,
363                                gpointer callback_data)
364{
365        static void
366                (*real_gnome_vfs_async_get_file_info) (GnomeVFSAsyncHandle **handle_return,
367                                                       GList *uris,
368                                                       GnomeVFSFileInfoOptions options,
369                                                       GnomeVFSAsyncGetFileInfoCallback callback,
370                                                       gpointer callback_data);
371
372        CALL_BACKEND (gnome_vfs_async_get_file_info,
373                      (handle_return, uris, options,
374                       callback, callback_data));
375}
376
377void
378gnome_vfs_async_find_directory (GnomeVFSAsyncHandle **handle_return,
379                                GList *near_uri_list,
380                                GnomeVFSFindDirectoryKind kind,
381                                gboolean create_if_needed,
382                                gboolean find_if_needed,
383                                guint permissions,
384                                GnomeVFSAsyncFindDirectoryCallback callback,
385                                gpointer callback_data)
386{
387        static void
388                (*real_gnome_vfs_async_find_directory) (GnomeVFSAsyncHandle **handle_return,
389                                                        GList *near_uri_list,
390                                                        GnomeVFSFindDirectoryKind kind,
391                                                        gboolean create_if_needed,
392                                                        gboolean find_if_needed,
393                                                        guint permissions,
394                                                        GnomeVFSAsyncFindDirectoryCallback callback,
395                                                        gpointer callback_data);
396       
397        CALL_BACKEND (gnome_vfs_async_find_directory,
398                      (handle_return, near_uri_list, kind, create_if_needed, find_if_needed,
399                       permissions, callback, callback_data));
400}
401
402void
403gnome_vfs_async_set_file_info  (GnomeVFSAsyncHandle **handle_return,
404                                GnomeVFSURI *uri,
405                                GnomeVFSFileInfo *info,
406                                GnomeVFSSetFileInfoMask mask,
407                                GnomeVFSFileInfoOptions options,
408                                GnomeVFSAsyncSetFileInfoCallback callback,
409                                gpointer callback_data)
410{
411        static void
412                (*real_gnome_vfs_async_set_file_info) (GnomeVFSAsyncHandle **handle_return,
413                                                       GnomeVFSURI *uri,
414                                                       GnomeVFSFileInfo *info,
415                                                       GnomeVFSSetFileInfoMask mask,
416                                                       GnomeVFSFileInfoOptions options,
417                                                       GnomeVFSAsyncSetFileInfoCallback callback,
418                                                       gpointer callback_data);
419
420        CALL_BACKEND (gnome_vfs_async_set_file_info,
421                      (handle_return, uri, info, mask, options,
422                       callback, callback_data));
423}
424
425void
426gnome_vfs_async_load_directory_uri (GnomeVFSAsyncHandle **handle_return,
427                                    GnomeVFSURI *uri,
428                                    GnomeVFSFileInfoOptions options,
429                                    GnomeVFSDirectorySortRule sort_rules[],
430                                    gboolean reverse_order,
431                                    GnomeVFSDirectoryFilterType filter_type,
432                                    GnomeVFSDirectoryFilterOptions filter_options,
433                                    const gchar *filter_pattern,
434                                    guint items_per_notification,
435                                    GnomeVFSAsyncDirectoryLoadCallback callback,
436                                    gpointer callback_data)
437{
438        static void
439                (*real_gnome_vfs_async_load_directory_uri) (GnomeVFSAsyncHandle **handle_return,
440                                                            GnomeVFSURI *uri,
441                                                            GnomeVFSFileInfoOptions options,
442                                                            GnomeVFSDirectorySortRule sort_rules[],
443                                                            gboolean reverse_order,
444                                                            GnomeVFSDirectoryFilterType filter_type,
445                                                            GnomeVFSDirectoryFilterOptions filter_options,
446                                                            const gchar *filter_pattern,
447                                                            guint items_per_notification,
448                                                            GnomeVFSAsyncDirectoryLoadCallback callback,
449                                                            gpointer callback_data);
450       
451        CALL_BACKEND (gnome_vfs_async_load_directory_uri,
452                      (handle_return, uri, options, sort_rules,
453                       reverse_order, filter_type, filter_options,
454                       filter_pattern, items_per_notification,
455                       callback, callback_data));
456}
457
458void
459gnome_vfs_async_load_directory (GnomeVFSAsyncHandle **handle_return,
460                                const gchar *uri,
461                                GnomeVFSFileInfoOptions options,
462                                GnomeVFSDirectorySortRule sort_rules[],
463                                gboolean reverse_order,
464                                GnomeVFSDirectoryFilterType filter_type,
465                                GnomeVFSDirectoryFilterOptions filter_options,
466                                const gchar *filter_pattern,
467                                guint items_per_notification,
468                                GnomeVFSAsyncDirectoryLoadCallback callback,
469                                gpointer callback_data)
470{
471        static void
472                (*real_gnome_vfs_async_load_directory) (GnomeVFSAsyncHandle **handle_return,
473                                                        const gchar *uri,
474                                                        GnomeVFSFileInfoOptions options,
475                                                        GnomeVFSDirectorySortRule sort_rules[],
476                                                        gboolean reverse_order,
477                                                        GnomeVFSDirectoryFilterType filter_type,
478                                                        GnomeVFSDirectoryFilterOptions filter_options,
479                                                        const gchar *filter_pattern,
480                                                        guint items_per_notification,
481                                                        GnomeVFSAsyncDirectoryLoadCallback callback,
482                                                        gpointer callback_data);
483
484        CALL_BACKEND (gnome_vfs_async_load_directory,
485                      (handle_return, uri, options, sort_rules, reverse_order,
486                       filter_type, filter_options, filter_pattern, items_per_notification,
487                       callback, callback_data));
488}
489
490GnomeVFSResult
491gnome_vfs_async_xfer (GnomeVFSAsyncHandle **handle_return,
492                      const GList *source_uri_list,
493                      const GList *target_uri_list,
494                      GnomeVFSXferOptions xfer_options,
495                      GnomeVFSXferErrorMode error_mode,
496                      GnomeVFSXferOverwriteMode overwrite_mode,
497                      GnomeVFSAsyncXferProgressCallback progress_update_callback,
498                      gpointer update_callback_data,
499                      GnomeVFSXferProgressCallback progress_sync_callback,
500                      gpointer sync_callback_data)
501{
502        static GnomeVFSResult
503                (*real_gnome_vfs_async_xfer) (GnomeVFSAsyncHandle **handle_return,
504                                              const GList *source_uri_list,
505                                              const GList *target_uri_list,
506                                              GnomeVFSXferOptions xfer_options,
507                                              GnomeVFSXferErrorMode error_mode,
508                                              GnomeVFSXferOverwriteMode overwrite_mode,
509                                              GnomeVFSAsyncXferProgressCallback progress_update_callback,
510                                              gpointer update_callback_data,
511                                              GnomeVFSXferProgressCallback progress_sync_callback,
512                                              gpointer sync_callback_data);
513
514        CALL_BACKEND_RETURN (gnome_vfs_async_xfer,
515                             (handle_return,
516                              source_uri_list, target_uri_list,
517                              xfer_options, error_mode, overwrite_mode,
518                              progress_update_callback, update_callback_data,
519                              progress_sync_callback, sync_callback_data));
520}
521
522void
523gnome_vfs_async_cancel (GnomeVFSAsyncHandle *handle)
524{
525        static void
526                (*real_gnome_vfs_async_cancel)(GnomeVFSAsyncHandle *handle);
527
528        CALL_BACKEND (gnome_vfs_async_cancel, (handle));
529}
530
531guint
532gnome_vfs_async_add_status_callback (GnomeVFSAsyncHandle *handle,
533                                     GnomeVFSStatusCallback callback,
534                                     gpointer user_data)
535{
536        static guint
537                (*real_gnome_vfs_async_add_status_callback) (GnomeVFSAsyncHandle *handle,
538                                                             GnomeVFSStatusCallback callback,
539                                                             gpointer user_data);
540
541        CALL_BACKEND_RETURN (gnome_vfs_async_add_status_callback,
542                             (handle, callback, user_data));
543}
544
545void
546gnome_vfs_async_remove_status_callback (GnomeVFSAsyncHandle *handle,
547                                        guint callback_id)
548{
549        static void
550                (*real_gnome_vfs_async_remove_status_callback) (GnomeVFSAsyncHandle *handle,
551                                                                guint callback_id);
552
553        CALL_BACKEND (gnome_vfs_async_remove_status_callback,
554                      (handle, callback_id));
555}
556
557int
558gnome_vfs_backend_get_job_count (void)
559{
560        /* find and call the backend function */
561
562        int (* get_count) (void);
563       
564        g_assert (gmod != NULL);
565        if (g_module_symbol (gmod,
566                             "gnome_vfs_job_get_count",
567                             (gpointer) &get_count)) {
568                return (* get_count) ();
569        }
570
571        return -1;
572}
Note: See TracBrowser for help on using the repository browser.