File: gnome-vfs-init.c

package info (click to toggle)
gnome-vfs 1:2.24.4-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 17,120 kB
  • ctags: 10,397
  • sloc: ansic: 78,516; sh: 10,341; makefile: 902; perl: 99
file content (213 lines) | stat: -rw-r--r-- 4,917 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* gnome-vfs-init.c - Initialization for the GNOME Virtual File System.

   Copyright (C) 1999 Free Software Foundation

   The Gnome Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The Gnome Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Author: Ettore Perazzoli <ettore@gnu.org>
*/

#include <config.h>
#include "gnome-vfs-init.h"

#include "gnome-vfs-mime.h"

#include "gnome-vfs-configuration.h"
#include "gnome-vfs-method.h"
#include "gnome-vfs-utils.h"
#include "gnome-vfs-private-utils.h"

#include "gnome-vfs-async-job-map.h"
#include "gnome-vfs-job-queue.h"
#include "gnome-vfs-volume-monitor-private.h"
#include "gnome-vfs-module-callback-private.h"

#include <errno.h>
#include <glib/gstdio.h>
#include <glib/gi18n-lib.h>
#include <glib.h>

#ifdef USE_DAEMON
#ifndef DBUS_API_SUBJECT_TO_CHANGE
#define DBUS_API_SUBJECT_TO_CHANGE 1
#endif
#include <dbus/dbus-glib.h>
#endif

#include <sys/stat.h>
#include <sys/types.h>
#include <signal.h>

static gboolean vfs_already_initialized = FALSE;
G_LOCK_DEFINE_STATIC (vfs_already_initialized);

static GPrivate * private_is_primary_thread;

static void
gnome_vfs_thread_init (void)
{
	private_is_primary_thread = g_private_new (NULL);
	g_private_set (private_is_primary_thread, GUINT_TO_POINTER (1));
	
	_gnome_vfs_module_callback_private_init ();
	
	_gnome_vfs_async_job_map_init ();
	_gnome_vfs_job_queue_init ();
}

/**
 * gnome_vfs_init:
 *
 * If gnome-vfs is not already initialized, initialize it. This must be
 * called prior to performing any other gnome-vfs operations, and may
 * be called multiple times without error.
 * 
 * Return value: %TRUE if gnome-vfs is successfully initialized (or was
 * already initialized).
 */
gboolean 
gnome_vfs_init (void)
{
	gboolean retval;
	/*
	char *bogus_argv[2] = { "dummy", NULL };
	*/
	
	/* The first call also checks that ~/.gnome2 is writable. */
	if (!gnome_vfs_get_home_dir ()) {
		return FALSE;
	}

 	if (!g_thread_supported ())
 		g_thread_init (NULL);

	G_LOCK (vfs_already_initialized);

	if (!vfs_already_initialized) {
#ifdef ENABLE_NLS
		bindtextdomain (GETTEXT_PACKAGE, GNOME_VFS_LOCALEDIR);
		bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
#endif   
		gnome_vfs_thread_init ();
#ifdef USE_DAEMON
		dbus_g_thread_init ();
#endif
 		/* Make sure the type system is inited. */
		g_type_init ();

		retval = gnome_vfs_method_init ();

		if (retval) {
			retval = _gnome_vfs_configuration_init ();
		}
		
#ifdef SIGPIPE
		if (retval) {
			signal (SIGPIPE, SIG_IGN);
		}
#endif		
	} else {
		retval = TRUE;	/* Who cares after all.  */
	}

	vfs_already_initialized = TRUE;
	G_UNLOCK (vfs_already_initialized);

	return retval;
}

/**
 * gnome_vfs_initialized:
 *
 * Detects if gnome-vfs has already been initialized (gnome-vfs must be
 * initialized prior to using any methods or operations).
 * 
 * Return value: %TRUE if gnome-vfs has already been initialized.
 */
gboolean
gnome_vfs_initialized (void)
{
	gboolean out;

	G_LOCK (vfs_already_initialized);
	out = vfs_already_initialized;
	G_UNLOCK (vfs_already_initialized);
	return out;
}

/**
 * gnome_vfs_shutdown:
 *
 * Cease all active gnome-vfs operations and unload the MIME
 * database from memory.
 * 
 */
void
gnome_vfs_shutdown (void)
{
	gnome_vfs_mime_shutdown ();
#ifndef G_OS_WIN32
	_gnome_vfs_volume_monitor_shutdown ();
#endif
	_gnome_vfs_method_shutdown ();
}

void
gnome_vfs_loadinit (gpointer app, gpointer modinfo)
{
}

void
gnome_vfs_preinit (gpointer app, gpointer modinfo)
{
}

void
gnome_vfs_postinit (gpointer app, gpointer modinfo)
{
	G_LOCK (vfs_already_initialized);

	gnome_vfs_thread_init ();

	gnome_vfs_method_init ();
	_gnome_vfs_configuration_init ();

#ifdef SIGPIPE
	signal (SIGPIPE, SIG_IGN);
#endif

	vfs_already_initialized = TRUE;
	G_UNLOCK (vfs_already_initialized);
}

/**
 * gnome_vfs_is_primary_thread:
 *
 * Check if the current thread is the thread with the main glib event loop.
 *
 * Return value: %TRUE if the current thread is the thread with the 
 * main glib event loop.
 */
gboolean
gnome_vfs_is_primary_thread (void)
{
	if (g_thread_supported()) {
		return GPOINTER_TO_UINT(g_private_get (private_is_primary_thread)) == 1;
	} else {
		return TRUE;
	}
}