~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to src/server.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
 
/* server.c
3
 
 *
4
 
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or
7
 
 * modify it under the terms of version 2 of the GNU Lesser General Public
8
 
 * License as published by the Free Software Foundation.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
 * General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU Lesser General Public
16
 
 * License along with this program; if not, write to the
17
 
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 
 * Boston, MA 02110-1301, USA.
19
 
 *
20
 
 * Author: Nat Friedman (nat@ximian.com)
21
 
 */
22
 
 
23
 
#ifdef HAVE_CONFIG_H
24
 
#include <config.h>
25
 
#endif
26
 
 
27
 
/* define this if you need/want to be able to send USR2 to server and
28
 
   get a list of the active backends */
29
 
/*#define DEBUG_BACKENDS*/
30
 
 
31
 
#include <stdlib.h>
32
 
#include <signal.h>
33
 
#include <unistd.h>
34
 
#include <pthread.h>
35
 
 
36
 
#include <glib.h>
37
 
#include <glib/gi18n.h>
38
 
#include <bonobo-activation/bonobo-activation.h>
39
 
#include <bonobo/bonobo-main.h>
40
 
#include <bonobo/bonobo-exception.h>
41
 
#include <bonobo/bonobo-generic-factory.h>
42
 
#include <gconf/gconf-client.h>
43
 
 
44
 
#include <libebackend/e-data-server-module.h>
45
 
#include <libedata-book/e-data-book-factory.h>
46
 
#if ENABLE_CALENDAR
47
 
#include <libedata-cal/e-data-cal-factory.h>
48
 
#endif
49
 
 
50
 
#ifdef G_OS_WIN32
51
 
#include <libedataserver/e-data-server-util.h>
52
 
#endif
53
 
 
54
 
#include "server-interface-check.h"
55
 
#include "server-logging.h"
56
 
#include "offline-listener.h"
57
 
 
58
 
#define E_DATA_SERVER_INTERFACE_CHECK_OAF_ID "OAFIID:GNOME_Evolution_DataServer_InterfaceCheck"
59
 
#define E_DATA_SERVER_LOGGING_OAF_ID "OAFIID:GNOME_Evolution_DataServer_Logging"
60
 
 
61
 
#define E_DATA_CAL_FACTORY_OAF_ID "OAFIID:GNOME_Evolution_DataServer_CalFactory:" API_VERSION
62
 
#define E_DATA_BOOK_FACTORY_OAF_ID "OAFIID:GNOME_Evolution_DataServer_BookFactory:" API_VERSION
63
 
 
64
 
/* The and addressbook calendar factories */
65
 
 
66
 
#if ENABLE_CALENDAR
67
 
static EDataCalFactory *e_data_cal_factory;
68
 
#endif
69
 
 
70
 
static EDataBookFactory *e_data_book_factory;
71
 
 
72
 
/* The other interfaces we implement */
73
 
 
74
 
static ServerLogging *logging_iface;
75
 
static ServerInterfaceCheck *interface_check_iface;
76
 
 
77
 
/* Timeout interval in milliseconds for termination */
78
 
#define EXIT_TIMEOUT 5000
79
 
 
80
 
/* Timeout ID for termination handler */
81
 
static guint termination_handler_id;
82
 
 
83
 
static GStaticMutex termination_lock = G_STATIC_MUTEX_INIT;
84
 
 
85
 
/* Termination */
86
 
 
87
 
/* Termination handler.  Checks if both factories have zero running backends,
88
 
 * and if so terminates the program.
89
 
 */
90
 
static gboolean
91
 
termination_handler (gpointer data)
92
 
{
93
 
        gint count = 0;
94
 
 
95
 
#if ENABLE_CALENDAR
96
 
        count += e_data_cal_factory_get_n_backends (e_data_cal_factory);
97
 
#endif
98
 
        count += e_data_book_factory_get_n_backends (e_data_book_factory);
99
 
 
100
 
        if (count == 0) {
101
 
                g_message ("termination_handler(): Terminating the Server.  Have a nice day.");
102
 
                bonobo_main_quit ();
103
 
        }
104
 
 
105
 
        termination_handler_id = 0;
106
 
        return FALSE;
107
 
}
108
 
 
109
 
/* Queues a timeout for handling termination of Server */
110
 
static void
111
 
queue_termination (void)
112
 
{
113
 
        g_static_mutex_lock (&termination_lock);
114
 
        if (termination_handler_id)
115
 
                g_source_remove (termination_handler_id);
116
 
 
117
 
        termination_handler_id = g_timeout_add (EXIT_TIMEOUT, termination_handler, NULL);
118
 
        g_static_mutex_unlock (&termination_lock);
119
 
}
120
 
 
121
 
 
122
 
 
123
 
static void
124
 
last_book_gone_cb (EDataBookFactory *factory, gpointer data)
125
 
{
126
 
        queue_termination ();
127
 
}
128
 
 
129
 
static gboolean
130
 
setup_books (void)
131
 
{
132
 
        e_data_book_factory = e_data_book_factory_new ();
133
 
 
134
 
        if (!e_data_book_factory)
135
 
                return FALSE;
136
 
 
137
 
        e_data_book_factory_register_backends (e_data_book_factory);
138
 
 
139
 
        g_signal_connect (e_data_book_factory,
140
 
                          "last_book_gone",
141
 
                          G_CALLBACK (last_book_gone_cb),
142
 
                          NULL);
143
 
 
144
 
        if (!e_data_book_factory_activate (e_data_book_factory, E_DATA_BOOK_FACTORY_OAF_ID)) {
145
 
                bonobo_object_unref (BONOBO_OBJECT (e_data_book_factory));
146
 
                e_data_book_factory = NULL;
147
 
                return FALSE;
148
 
        }
149
 
 
150
 
        return TRUE;
151
 
}
152
 
 
153
 
 
154
 
/* Personal calendar server */
155
 
 
156
 
#if ENABLE_CALENDAR
157
 
/* Callback used when the calendar factory has no more running backends */
158
 
static void
159
 
last_calendar_gone_cb (EDataCalFactory *factory, gpointer data)
160
 
{
161
 
        queue_termination ();
162
 
}
163
 
 
164
 
/* Creates the calendar factory object and registers it */
165
 
static gboolean
166
 
setup_cals (void)
167
 
{
168
 
        e_data_cal_factory = e_data_cal_factory_new ();
169
 
 
170
 
        if (!e_data_cal_factory) {
171
 
                g_warning (G_STRLOC ": Could not create the calendar factory");
172
 
                return FALSE;
173
 
        }
174
 
 
175
 
        e_data_cal_factory_register_backends (e_data_cal_factory);
176
 
 
177
 
        if (!e_data_cal_factory_register_storage (e_data_cal_factory, E_DATA_CAL_FACTORY_OAF_ID)) {
178
 
                bonobo_object_unref (BONOBO_OBJECT (e_data_cal_factory));
179
 
                e_data_cal_factory = NULL;
180
 
                return FALSE;
181
 
        }
182
 
 
183
 
        g_signal_connect (G_OBJECT (e_data_cal_factory),
184
 
                          "last_calendar_gone",
185
 
                          G_CALLBACK (last_calendar_gone_cb),
186
 
                          NULL);
187
 
 
188
 
        return TRUE;
189
 
 
190
 
}
191
 
#else
192
 
static gboolean
193
 
setup_cals (void)
194
 
{
195
 
        return TRUE;
196
 
}
197
 
#endif
198
 
 
199
 
 
200
 
/* Logging iface.  */
201
 
static gboolean
202
 
setup_logging (void)
203
 
{
204
 
        gint result;
205
 
 
206
 
        logging_iface = server_logging_new ();
207
 
 
208
 
        server_logging_register_domain (logging_iface, NULL);
209
 
        server_logging_register_domain (logging_iface, "Gdk");
210
 
        server_logging_register_domain (logging_iface, "Gtk");
211
 
        server_logging_register_domain (logging_iface, "GdkPixbuf");
212
 
        server_logging_register_domain (logging_iface, "GLib");
213
 
        server_logging_register_domain (logging_iface, "GModule");
214
 
        server_logging_register_domain (logging_iface, "GLib-GObject");
215
 
        server_logging_register_domain (logging_iface, "GThread");
216
 
 
217
 
        server_logging_register_domain (logging_iface, "evolution-data-server");
218
 
        server_logging_register_domain (logging_iface, "libebookbackend");
219
 
        server_logging_register_domain (logging_iface, "libecalbackendfile");
220
 
 
221
 
        result = bonobo_activation_active_server_register (E_DATA_SERVER_LOGGING_OAF_ID,
222
 
                                                           BONOBO_OBJREF (logging_iface));
223
 
 
224
 
        return result == Bonobo_ACTIVATION_REG_SUCCESS;
225
 
}
226
 
 
227
 
 
228
 
/* Interface check iface.  */
229
 
 
230
 
static gboolean
231
 
setup_interface_check (void)
232
 
{
233
 
        gint result;
234
 
 
235
 
        interface_check_iface = server_interface_check_new ();
236
 
        result = bonobo_activation_active_server_register (E_DATA_SERVER_INTERFACE_CHECK_OAF_ID,
237
 
                                                           BONOBO_OBJREF (interface_check_iface));
238
 
 
239
 
        return result == Bonobo_ACTIVATION_REG_SUCCESS;
240
 
}
241
 
 
242
 
#ifdef DEBUG_BACKENDS
243
 
static void
244
 
dump_backends (gint signal)
245
 
{
246
 
        e_data_book_factory_dump_active_backends (e_data_book_factory);
247
 
#if ENABLE_CALENDAR
248
 
        e_data_cal_factory_dump_active_backends (e_data_cal_factory);
249
 
#endif
250
 
}
251
 
#endif
252
 
 
253
 
#ifdef G_OS_WIN32
254
 
#undef EVOLUTION_LOCALEDIR
255
 
#define EVOLUTION_LOCALEDIR e_util_get_localedir ()
256
 
 
257
 
/* Used in GNOME_PROGRAM_STANDARD_PROPERTIES: */
258
 
#undef PREFIX
259
 
#define PREFIX e_util_get_prefix ()
260
 
 
261
 
static const gchar *
262
 
sysconfdir (void)
263
 
{
264
 
        return e_util_replace_prefix (PREFIX,
265
 
                                      e_util_get_prefix (),
266
 
                                      SYSCONFDIR);
267
 
}
268
 
#undef SYSCONFDIR
269
 
#define SYSCONFDIR sysconfdir ()
270
 
 
271
 
static const gchar *
272
 
datadir (void)
273
 
{
274
 
        return e_util_replace_prefix (PREFIX,
275
 
                                      e_util_get_prefix (),
276
 
                                      DATADIR);
277
 
}
278
 
#undef DATADIR
279
 
#define DATADIR datadir ()
280
 
 
281
 
static const gchar *
282
 
libdir (void)
283
 
{
284
 
        return e_util_replace_prefix (PREFIX,
285
 
                                      e_util_get_prefix (),
286
 
                                      LIBDIR);
287
 
}
288
 
#undef LIBDIR
289
 
#define LIBDIR libdir ()
290
 
 
291
 
#endif
292
 
 
293
 
gint
294
 
main (gint argc, gchar **argv)
295
 
{
296
 
        gboolean did_books=FALSE, did_cals=FALSE;
297
 
        OfflineListener *offline_listener = NULL;
298
 
 
299
 
        bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR);
300
 
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
301
 
        textdomain (GETTEXT_PACKAGE);
302
 
 
303
 
        printf ("evolution-data-server-Message: Starting server\n");
304
 
 
305
 
#ifdef DEBUG_BACKENDS
306
 
        signal (SIGUSR2, dump_backends);
307
 
#endif
308
 
 
309
 
        bonobo_init_full (&argc, argv,
310
 
                          bonobo_activation_orb_get(),
311
 
                          CORBA_OBJECT_NIL,
312
 
                          CORBA_OBJECT_NIL);
313
 
 
314
 
        e_data_server_module_init ();
315
 
 
316
 
        if (!( (did_books = setup_books ())
317
 
               && (did_cals = setup_cals ())
318
 
                    )) {
319
 
 
320
 
                const gchar *failed = NULL;
321
 
 
322
 
                if (!did_books)
323
 
                        failed = "BOOKS";
324
 
                else if (!did_cals)
325
 
                        failed = "CALS";
326
 
 
327
 
                g_warning (G_STRLOC ": could not initialize Server service \"%s\"; terminating", failed);
328
 
 
329
 
                if (e_data_book_factory) {
330
 
                        bonobo_object_unref (BONOBO_OBJECT (e_data_book_factory));
331
 
                        e_data_book_factory = NULL;
332
 
                }
333
 
 
334
 
#if ENABLE_CALENDAR
335
 
                if (e_data_cal_factory) {
336
 
                        bonobo_object_unref (BONOBO_OBJECT (e_data_cal_factory));
337
 
                        e_data_cal_factory = NULL;
338
 
                }
339
 
#endif
340
 
                exit (EXIT_FAILURE);
341
 
        }
342
 
 
343
 
#if ENABLE_CALENDAR
344
 
        offline_listener = offline_listener_new (e_data_book_factory, e_data_cal_factory);
345
 
#else
346
 
        offline_listener = offline_listener_new (e_data_book_factory);
347
 
#endif
348
 
 
349
 
        if ( setup_logging ()) {
350
 
                        if ( setup_interface_check ()) {
351
 
                                g_message ("Server up and running");
352
 
 
353
 
                                bonobo_main ();
354
 
                        } else
355
 
                                g_error (G_STRLOC "Cannot register DataServer::InterfaceCheck object");
356
 
        } else
357
 
                g_error (G_STRLOC "Cannot register DataServer::Logging object");
358
 
 
359
 
        g_object_unref (offline_listener);
360
 
 
361
 
#if ENABLE_CALENDAR
362
 
        bonobo_object_unref (BONOBO_OBJECT (e_data_cal_factory));
363
 
        e_data_cal_factory = NULL;
364
 
#endif
365
 
 
366
 
        bonobo_object_unref (BONOBO_OBJECT (e_data_book_factory));
367
 
        e_data_book_factory = NULL;
368
 
 
369
 
        bonobo_object_unref (BONOBO_OBJECT (logging_iface));
370
 
        logging_iface = NULL;
371
 
 
372
 
        bonobo_object_unref (BONOBO_OBJECT (interface_check_iface));
373
 
        interface_check_iface = NULL;
374
 
 
375
 
        return 0;
376
 
}