1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
4
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
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.
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.
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.
20
* Author: Nat Friedman (nat@ximian.com)
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*/
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>
44
#include <libebackend/e-data-server-module.h>
45
#include <libedata-book/e-data-book-factory.h>
47
#include <libedata-cal/e-data-cal-factory.h>
51
#include <libedataserver/e-data-server-util.h>
54
#include "server-interface-check.h"
55
#include "server-logging.h"
56
#include "offline-listener.h"
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"
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
64
/* The and addressbook calendar factories */
67
static EDataCalFactory *e_data_cal_factory;
70
static EDataBookFactory *e_data_book_factory;
72
/* The other interfaces we implement */
74
static ServerLogging *logging_iface;
75
static ServerInterfaceCheck *interface_check_iface;
77
/* Timeout interval in milliseconds for termination */
78
#define EXIT_TIMEOUT 5000
80
/* Timeout ID for termination handler */
81
static guint termination_handler_id;
83
static GStaticMutex termination_lock = G_STATIC_MUTEX_INIT;
87
/* Termination handler. Checks if both factories have zero running backends,
88
* and if so terminates the program.
91
termination_handler (gpointer data)
96
count += e_data_cal_factory_get_n_backends (e_data_cal_factory);
98
count += e_data_book_factory_get_n_backends (e_data_book_factory);
101
g_message ("termination_handler(): Terminating the Server. Have a nice day.");
105
termination_handler_id = 0;
109
/* Queues a timeout for handling termination of Server */
111
queue_termination (void)
113
g_static_mutex_lock (&termination_lock);
114
if (termination_handler_id)
115
g_source_remove (termination_handler_id);
117
termination_handler_id = g_timeout_add (EXIT_TIMEOUT, termination_handler, NULL);
118
g_static_mutex_unlock (&termination_lock);
124
last_book_gone_cb (EDataBookFactory *factory, gpointer data)
126
queue_termination ();
132
e_data_book_factory = e_data_book_factory_new ();
134
if (!e_data_book_factory)
137
e_data_book_factory_register_backends (e_data_book_factory);
139
g_signal_connect (e_data_book_factory,
141
G_CALLBACK (last_book_gone_cb),
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;
154
/* Personal calendar server */
157
/* Callback used when the calendar factory has no more running backends */
159
last_calendar_gone_cb (EDataCalFactory *factory, gpointer data)
161
queue_termination ();
164
/* Creates the calendar factory object and registers it */
168
e_data_cal_factory = e_data_cal_factory_new ();
170
if (!e_data_cal_factory) {
171
g_warning (G_STRLOC ": Could not create the calendar factory");
175
e_data_cal_factory_register_backends (e_data_cal_factory);
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;
183
g_signal_connect (G_OBJECT (e_data_cal_factory),
184
"last_calendar_gone",
185
G_CALLBACK (last_calendar_gone_cb),
206
logging_iface = server_logging_new ();
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");
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");
221
result = bonobo_activation_active_server_register (E_DATA_SERVER_LOGGING_OAF_ID,
222
BONOBO_OBJREF (logging_iface));
224
return result == Bonobo_ACTIVATION_REG_SUCCESS;
228
/* Interface check iface. */
231
setup_interface_check (void)
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));
239
return result == Bonobo_ACTIVATION_REG_SUCCESS;
242
#ifdef DEBUG_BACKENDS
244
dump_backends (gint signal)
246
e_data_book_factory_dump_active_backends (e_data_book_factory);
248
e_data_cal_factory_dump_active_backends (e_data_cal_factory);
254
#undef EVOLUTION_LOCALEDIR
255
#define EVOLUTION_LOCALEDIR e_util_get_localedir ()
257
/* Used in GNOME_PROGRAM_STANDARD_PROPERTIES: */
259
#define PREFIX e_util_get_prefix ()
264
return e_util_replace_prefix (PREFIX,
265
e_util_get_prefix (),
269
#define SYSCONFDIR sysconfdir ()
274
return e_util_replace_prefix (PREFIX,
275
e_util_get_prefix (),
279
#define DATADIR datadir ()
284
return e_util_replace_prefix (PREFIX,
285
e_util_get_prefix (),
289
#define LIBDIR libdir ()
294
main (gint argc, gchar **argv)
296
gboolean did_books=FALSE, did_cals=FALSE;
297
OfflineListener *offline_listener = NULL;
299
bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR);
300
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
301
textdomain (GETTEXT_PACKAGE);
303
printf ("evolution-data-server-Message: Starting server\n");
305
#ifdef DEBUG_BACKENDS
306
signal (SIGUSR2, dump_backends);
309
bonobo_init_full (&argc, argv,
310
bonobo_activation_orb_get(),
314
e_data_server_module_init ();
316
if (!( (did_books = setup_books ())
317
&& (did_cals = setup_cals ())
320
const gchar *failed = NULL;
327
g_warning (G_STRLOC ": could not initialize Server service \"%s\"; terminating", failed);
329
if (e_data_book_factory) {
330
bonobo_object_unref (BONOBO_OBJECT (e_data_book_factory));
331
e_data_book_factory = NULL;
335
if (e_data_cal_factory) {
336
bonobo_object_unref (BONOBO_OBJECT (e_data_cal_factory));
337
e_data_cal_factory = NULL;
344
offline_listener = offline_listener_new (e_data_book_factory, e_data_cal_factory);
346
offline_listener = offline_listener_new (e_data_book_factory);
349
if ( setup_logging ()) {
350
if ( setup_interface_check ()) {
351
g_message ("Server up and running");
355
g_error (G_STRLOC "Cannot register DataServer::InterfaceCheck object");
357
g_error (G_STRLOC "Cannot register DataServer::Logging object");
359
g_object_unref (offline_listener);
362
bonobo_object_unref (BONOBO_OBJECT (e_data_cal_factory));
363
e_data_cal_factory = NULL;
366
bonobo_object_unref (BONOBO_OBJECT (e_data_book_factory));
367
e_data_book_factory = NULL;
369
bonobo_object_unref (BONOBO_OBJECT (logging_iface));
370
logging_iface = NULL;
372
bonobo_object_unref (BONOBO_OBJECT (interface_check_iface));
373
interface_check_iface = NULL;