1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* gnome-vfs-init.c - Initialization for the GNOME Virtual File System.
4 Copyright (C) 1999 Free Software Foundation
6 The Gnome Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The Gnome Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the Gnome Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
21 Author: Ettore Perazzoli <ettore@gnu.org>
25 #include "gnome-vfs-init.h"
27 #include "gnome-vfs-ssl-private.h"
28 #include "gnome-vfs-mime.h"
30 #include "gnome-vfs-configuration.h"
31 #include "gnome-vfs-i18n.h"
32 #include "gnome-vfs-method.h"
33 #include "gnome-vfs-process.h"
34 #include "gnome-vfs-utils.h"
36 #include "gnome-vfs-async-job-map.h"
37 #include "gnome-vfs-thread-pool.h"
38 #include "gnome-vfs-job-queue.h"
41 #include <bonobo-activation/bonobo-activation.h>
42 #include <glib/gmessages.h>
43 #include <glib/gfileutils.h>
44 #include <libgnomevfs/gnome-vfs-job-slave.h>
46 #include <sys/types.h>
48 static gboolean vfs_already_initialized = FALSE;
49 G_LOCK_DEFINE_STATIC (vfs_already_initialized);
51 static GPrivate * private_is_primary_thread;
54 ensure_dot_gnome_exists (void)
56 gboolean retval = TRUE;
59 dirname = g_build_filename (g_get_home_dir (), ".gnome", NULL);
61 if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) {
62 if (mkdir (dirname, S_IRWXU) != 0) {
63 g_warning ("Unable to create ~/.gnome directory: %s",
67 } else if (!g_file_test (dirname, G_FILE_TEST_IS_DIR)) {
68 g_warning ("Error: ~/.gnome must be a directory.");
77 gnome_vfs_pthread_init (void)
79 private_is_primary_thread = g_private_new (NULL);
80 g_private_set (private_is_primary_thread, GUINT_TO_POINTER (1));
82 _gnome_vfs_module_callback_private_init ();
84 _gnome_vfs_async_job_map_init ();
85 _gnome_vfs_thread_pool_init ();
86 _gnome_vfs_job_queue_init ();
92 * If GnomeVFS is not already initialized, initialize it. This must be
93 * called prior to performing any other GnomeVFS operations, and may
94 * be called multiple times without error.
96 * Return value: %TRUE if GnomeVFS is successfully initialized (or was
97 * already initialized)
100 gnome_vfs_init (void)
103 char *bogus_argv[2] = { "dummy", NULL };
105 if (!ensure_dot_gnome_exists ()) {
109 if (!g_thread_supported ())
110 g_thread_init (NULL);
112 G_LOCK (vfs_already_initialized);
114 if (!vfs_already_initialized) {
116 bindtextdomain (GETTEXT_PACKAGE, GNOMEVFS_LOCALEDIR);
117 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
119 gnome_vfs_pthread_init ();
121 if (bonobo_activation_orb_get() == NULL) {
122 bonobo_activation_init (0, bogus_argv);
125 _gnome_vfs_ssl_init ();
127 retval = gnome_vfs_method_init ();
130 retval = _gnome_vfs_process_init ();
133 retval = _gnome_vfs_configuration_init ();
136 signal (SIGPIPE, SIG_IGN);
139 retval = TRUE; /* Who cares after all. */
142 vfs_already_initialized = TRUE;
143 G_UNLOCK (vfs_already_initialized);
149 * gnome_vfs_initialized:
151 * Detects if GnomeVFS has already been initialized (GnomeVFS must be
152 * initialized prior to using any methods or operations).
154 * Return value: %TRUE if GnomeVFS has already been initialized
157 gnome_vfs_initialized (void)
161 G_LOCK (vfs_already_initialized);
162 out = vfs_already_initialized;
163 G_UNLOCK (vfs_already_initialized);
168 * gnome_vfs_shutdown:
170 * Cease all active GnomeVFS operations and unload the MIME
171 * database from memory.
175 gnome_vfs_shutdown (void)
177 _gnome_vfs_thread_backend_shutdown ();
178 gnome_vfs_mime_shutdown ();
182 gnome_vfs_loadinit (gpointer app, gpointer modinfo)
187 gnome_vfs_preinit (gpointer app, gpointer modinfo)
192 gnome_vfs_postinit (gpointer app, gpointer modinfo)
194 G_LOCK (vfs_already_initialized);
196 gnome_vfs_pthread_init ();
198 gnome_vfs_method_init ();
199 _gnome_vfs_process_init ();
200 _gnome_vfs_configuration_init ();
202 signal (SIGPIPE, SIG_IGN);
204 vfs_already_initialized = TRUE;
205 G_UNLOCK (vfs_already_initialized);
209 * gnome_vfs_is_primary_thread:
211 * Check if the current thread is the thread with the main glib event loop.
213 * Return value: %TRUE if the current thread is the thread with the
214 * main glib event loop
217 gnome_vfs_is_primary_thread (void)
219 if (g_thread_supported()) {
220 return GPOINTER_TO_UINT(g_private_get (private_is_primary_thread)) == 1;