Include "config.h" instead of <config.h> Command used: find -name
[platform/upstream/glib.git] / gio / gvfs.c
index 4dc1f25..3158d3d 100644 (file)
  * Author: Alexander Larsson <alexl@redhat.com>
  */
 
-#include <config.h>
+#include "config.h"
 #include <string.h>
 #include "gvfs.h"
 #include "glocalvfs.h"
-#include "giomodule.h"
+#include "giomodule-priv.h"
 #include "glibintl.h"
 
+#include "gioalias.h"
+
+/**
+ * SECTION:gvfs
+ * @short_description: Virtual File System 
+ * @include: gio/gio.h
+ * 
+ * Entry point for using GIO functionality.
+ *
+ **/
+
 G_DEFINE_TYPE (GVfs, g_vfs, G_TYPE_OBJECT);
 
 static void
@@ -41,9 +52,11 @@ g_vfs_init (GVfs *vfs)
 
 /**
  * g_vfs_is_active:
- * @vfs: an  #GVfs.
+ * @vfs: a #GVfs.
+ * 
+ * Checks if the VFS is active.
  * 
- * Returns TRUE if construction of the @vfs was successful and its now active.
+ * Returns: %TRUE if construction of the @vfs was successful and it is now active.
  **/
 gboolean
 g_vfs_is_active (GVfs *vfs)
@@ -60,14 +73,15 @@ g_vfs_is_active (GVfs *vfs)
 
 /**
  * g_vfs_get_file_for_path:
- * @vfs: an input #GVfs.
+ * @vfs: a #GVfs.
  * @path: a string containing a VFS path.
  * 
- * Returns a #GFile for the given @path.
+ * Gets a #GFile for @path.
  * 
+ * Returns: a #GFile.
  **/
 GFile *
-g_vfs_get_file_for_path (GVfs *vfs,
+g_vfs_get_file_for_path (GVfs       *vfs,
                         const char *path)
 {
   GVfsClass *class;
@@ -82,18 +96,20 @@ g_vfs_get_file_for_path (GVfs *vfs,
 
 /**
  * g_vfs_get_file_for_uri:
- * @vfs: an input #GVfs.
- * @uri: an input string containing a URI path.
- *
+ * @vfs: a#GVfs.
+ * @uri: a string containing a URI path.
+ * 
+ * Gets a #GFile for @uri.
+ * 
  * This operation never fails, but the returned object
  * might not support any I/O operation if the uri
  * is malformed or if the uri type is not supported.
  * 
- * Returns a #GFile for the given @uri
+ * Returns: a #GFile
  * 
  **/
 GFile *
-g_vfs_get_file_for_uri (GVfs *vfs,
+g_vfs_get_file_for_uri (GVfs       *vfs,
                        const char *uri)
 {
   GVfsClass *class;
@@ -108,10 +124,11 @@ g_vfs_get_file_for_uri (GVfs *vfs,
 
 /**
  * g_vfs_get_supported_uri_schemes:
- * @vfs: an input #GVfs.
+ * @vfs: a #GVfs.
  * 
- * Returns: 
+ * Gets a list of URI schemes supported by @vfs.
  * 
+ * Returns: a list of strings.
  **/
 const gchar * const *
 g_vfs_get_supported_uri_schemes (GVfs *vfs)
@@ -127,18 +144,17 @@ g_vfs_get_supported_uri_schemes (GVfs *vfs)
 
 /**
  * g_vfs_parse_name:
- * @vfs: an input #GVfs.
+ * @vfs: a #GVfs.
  * @parse_name: a string to be parsed by the VFS module.
  * 
  * This operation never fails, but the returned object might 
  * not support any I/O operations if the @parse_name cannot 
  * be parsed by the #GVfs module.
  * 
- * Returns a #GFile for the given @parse_name.
- * 
+ * Returns: a #GFile for the given @parse_name.
  **/
 GFile *
-g_vfs_parse_name (GVfs *vfs,
+g_vfs_parse_name (GVfs       *vfs,
                  const char *parse_name)
 {
   GVfsClass *class;
@@ -151,86 +167,59 @@ g_vfs_parse_name (GVfs *vfs,
   return (* class->parse_name) (vfs, parse_name);
 }
 
-/* Note: This compares in reverse order.
-   Higher prio -> sort first
- */
-static gint
-compare_vfs_type (gconstpointer  a,
-                 gconstpointer  b,
-                 gpointer       user_data)
-{
-  GVfsClass *class_a, *class_b;
-  gint res;
-  const char *use_this_vfs;
-  
-  class_a = g_type_class_ref (*(GType *)a);
-  class_b = g_type_class_ref (*(GType *)b);
-  use_this_vfs = user_data;
-
-  if (class_a == class_b)
-    res = 0;
-  else if (use_this_vfs != NULL &&
-          strcmp (class_a->name, use_this_vfs) == 0)
-    res = -1;
-  else if (use_this_vfs != NULL &&
-          strcmp (class_b->name, use_this_vfs) == 0)
-    res = 1;
-  else 
-    res = class_b->priority - class_a->priority;
-  
-  g_type_class_unref (class_a);
-  g_type_class_unref (class_b);
-  
-  return res;
-}
-
-
 static gpointer
 get_default_vfs (gpointer arg)
 {
-  volatile GType local_type;
-  GType *vfs_impls;
-  int i;
-  guint n_vfs_impls;
   const char *use_this;
   GVfs *vfs;
-  GType (*casted_get_type)(void);
+  GList *l;
+  GIOExtensionPoint *ep;
+  GIOExtension *extension;
+  
 
   use_this = g_getenv ("GIO_USE_VFS");
   
-  /* Ensure GLocalVfs type is available
-     the cast is required to avoid any G_GNUC_CONST optimizations */
-  casted_get_type = g_local_vfs_get_type;
-  local_type = casted_get_type ();
-  
   /* Ensure vfs in modules loaded */
-  g_io_modules_ensure_loaded (GIO_MODULE_DIR);
+  _g_io_modules_ensure_loaded ();
 
-  vfs_impls = g_type_children (G_TYPE_VFS, &n_vfs_impls);
+  ep = g_io_extension_point_lookup (G_VFS_EXTENSION_POINT_NAME);
 
-  g_qsort_with_data (vfs_impls, n_vfs_impls, sizeof (GType),
-                    compare_vfs_type, (gpointer)use_this);
-  
-  for (i = 0; i < n_vfs_impls; i++)
+  if (use_this)
+    {
+      extension = g_io_extension_point_get_extension_by_name (ep, use_this);
+      if (extension)
+       {
+         vfs = g_object_new (g_io_extension_get_type (extension), NULL);
+         
+         if (g_vfs_is_active (vfs))
+           return vfs;
+         
+         g_object_unref (vfs);
+       }
+    }
+
+  for (l = g_io_extension_point_get_extensions (ep); l != NULL; l = l->next)
     {
-      vfs = g_object_new (vfs_impls[i], NULL);
+      extension = l->data;
+
+      vfs = g_object_new (g_io_extension_get_type (extension), NULL);
 
       if (g_vfs_is_active (vfs))
-       break;
+       return vfs;
 
       g_object_unref (vfs);
-      vfs = NULL;
     }
   
-  g_free (vfs_impls);
 
-  return vfs;
+  return NULL;
 }
 
 /**
  * g_vfs_get_default:
  * 
- * Returns the default #GVfs for the system.
+ * Gets the default #GVfs for the system.
+ * 
+ * Returns: a #GVfs. 
  **/
 GVfs *
 g_vfs_get_default (void)
@@ -243,7 +232,9 @@ g_vfs_get_default (void)
 /**
  * g_vfs_get_local:
  * 
- * Returns the local #GVfs for the system.
+ * Gets the local #GVfs for the system.
+ * 
+ * Returns: a #GVfs.
  **/
 GVfs *
 g_vfs_get_local (void)
@@ -251,8 +242,10 @@ g_vfs_get_local (void)
   static gsize vfs = 0;
 
   if (g_once_init_enter (&vfs))
-    g_once_init_leave (&vfs, (gsize)g_local_vfs_new ());
+    g_once_init_leave (&vfs, (gsize)_g_local_vfs_new ());
 
   return G_VFS (vfs);
 }
 
+#define __G_VFS_C__
+#include "gioaliasdef.c"