aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--wombat/ChangeLog16
-rw-r--r--wombat/wombat.c103
2 files changed, 98 insertions, 21 deletions
diff --git a/wombat/ChangeLog b/wombat/ChangeLog
index 3a0d938fb6..704b27d1b6 100644
--- a/wombat/ChangeLog
+++ b/wombat/ChangeLog
@@ -1,3 +1,19 @@
+2000-04-25 Federico Mena Quintero <federico@helixcode.com>
+
+ * wombat.c (cal_factory pas_book_factory): New module-wide
+ variables for the PAS and PCS factories.
+ (setup_pcs): Connect to the "last_calendar_gone" signal of the
+ calendar factory.
+ (last_calendar_gone_cb): Queue a termination job.
+ (queue_termination): Function to queue a termination job. We have
+ to use a timeout to reduce the probability of running into GOAD's
+ race condition with factories.
+ (termination_handler): Check that the PCS and the PAS have zero
+ backends. If so, exit the main loop.
+ (setup_vfs): Use EXIT_FAILURE instead of 1.
+ (init_bonobo): Likewise.
+ (main): Destroy the factories and exit Wombat. Wheee!
+
2000-04-16 Federico Mena Quintero <federico@helixcode.com>
* Makefile.am (INCLUDES): Removed spurious calendar directories
diff --git a/wombat/wombat.c b/wombat/wombat.c
index a505eb0a33..013b3615f1 100644
--- a/wombat/wombat.c
+++ b/wombat/wombat.c
@@ -16,43 +16,95 @@
#include <libgnorba/gnorba.h>
#include "calendar/pcs/cal-factory.h"
-CORBA_ORB orb;
+
+static CORBA_ORB orb;
+
+/* The and addressbook calendar factories */
+
+static CalFactory *cal_factory;
+static PASBookFactory *pas_book_factory;
+
+/* Timeout interval in milliseconds for termination */
+#define EXIT_TIMEOUT 5000
+
+/* Timeout ID for termination handler */
+static guint termination_handler_id;
+
+
+
+/* Termination */
+
+/* Termination handler. Checks if both factories have zero running backends,
+ * and if so terminates the program.
+ */
+static gboolean
+termination_handler (gpointer data)
+{
+ /* FIXME: add the test for the PAS as well */
+
+ if (cal_factory_get_n_backends (cal_factory) == 0)
+ gtk_main_quit ();
+
+ termination_handler_id = 0;
+ return FALSE;
+}
+
+/* Queues a timeout for handling termination of Wombat */
static void
-setup_pas (int argc, char **argv)
+queue_termination (void)
{
- static PASBookFactory *factory;
+ if (termination_handler_id)
+ return;
- factory = pas_book_factory_new ();
+ termination_handler_id = g_timeout_add (EXIT_TIMEOUT, termination_handler, NULL);
+}
+
+
+
+static void
+setup_pas (int argc, char **argv)
+{
+ pas_book_factory = pas_book_factory_new ();
pas_book_factory_register_backend (
- factory, "file", pas_backend_file_new);
+ pas_book_factory, "file", pas_backend_file_new);
#ifdef HAVE_LDAP
pas_book_factory_register_backend (
- factory, "ldap", pas_backend_ldap_new);
+ pas_book_factory, "ldap", pas_backend_ldap_new);
#endif
- pas_book_factory_activate (factory);
+ pas_book_factory_activate (pas_book_factory);
+}
+
+
+
+/* Personal calendar server */
+
+/* Callback used when the calendar factory has no more running backends */
+static void
+last_calendar_gone_cb (CalFactory *factory, gpointer data)
+{
+ queue_termination ();
}
/* Creates the calendar factory object and registers it with GOAD */
static void
setup_pcs (int argc, char **argv)
{
- CalFactory *factory;
CORBA_Object object;
CORBA_Environment ev;
int result;
- factory = cal_factory_new ();
+ cal_factory = cal_factory_new ();
- if (!factory) {
+ if (!cal_factory) {
g_message ("setup_pcs(): Could not create the calendar factory");
return;
}
- object = bonobo_object_corba_objref (BONOBO_OBJECT (factory));
+ object = bonobo_object_corba_objref (BONOBO_OBJECT (cal_factory));
CORBA_exception_init (&ev);
result = goad_server_register (CORBA_OBJECT_NIL,
@@ -65,25 +117,27 @@ setup_pcs (int argc, char **argv)
if (ev._major != CORBA_NO_EXCEPTION || result == -1) {
g_message ("setup_pcs(): could not register the calendar factory");
- bonobo_object_unref (BONOBO_OBJECT (factory));
+ bonobo_object_unref (BONOBO_OBJECT (cal_factory));
+ cal_factory = NULL;
CORBA_exception_free (&ev);
return;
} else if (result == -2) {
g_message ("setup_pcs(): a calendar factory is already registered");
- bonobo_object_unref (BONOBO_OBJECT (factory));
+ bonobo_object_unref (BONOBO_OBJECT (cal_factory));
+ cal_factory = NULL;
CORBA_exception_free (&ev);
return;
}
- /* FIXME: we never connect to the destroy signal of the factory. We
- * need to add a signal to it to indicate that the last client died.
- * The PAS factory needs to have the same thing. When Wombat sees that
- * both factories have lost all their clients, it should destroy the
- * factories and terminate. */
+ gtk_signal_connect (GTK_OBJECT (cal_factory), "last_calendar_gone",
+ GTK_SIGNAL_FUNC (last_calendar_gone_cb),
+ NULL);
CORBA_exception_free (&ev);
}
+
+
static void
setup_config (int argc, char **argv)
{
@@ -94,10 +148,11 @@ setup_vfs (int argc, char **argv)
{
if (!gnome_vfs_init ()) {
g_message ("setup_vfs(): could not initialize GNOME-VFS");
- exit (1);
+ exit (EXIT_FAILURE);
}
}
+
static void
init_bonobo (int argc, char **argv)
@@ -113,7 +168,7 @@ init_bonobo (int argc, char **argv)
if (ev._major != CORBA_NO_EXCEPTION) {
g_message ("init_bonobo(): could not initialize GOAD");
CORBA_exception_free (&ev);
- exit (1);
+ exit (EXIT_FAILURE);
}
CORBA_exception_free (&ev);
@@ -122,7 +177,7 @@ init_bonobo (int argc, char **argv)
if (!bonobo_init (orb, NULL, NULL)) {
g_message ("init_bonobo(): could not initialize Bonobo");
- exit (1);
+ exit (EXIT_FAILURE);
}
}
@@ -140,5 +195,11 @@ main (int argc, char **argv)
bonobo_main ();
+ bonobo_object_unref (BONOBO_OBJECT (cal_factory));
+ cal_factory = NULL;
+
+ while (1)
+ ;
+
return 0;
}