From 06c876bf8ee5f22fd5e9e60fb9dbc3cc06756c1a Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Sat, 24 Feb 2001 00:32:36 +0000 Subject: Switched to using our own refcounted structure for loaded clients. 2001-02-23 Federico Mena Quintero * gui/alarm-notify/alarm-notify.c (AlarmNotify_addCalendar): Switched to using our own refcounted structure for loaded clients. (AlarmNotify_removeCalendar): Ditto. Also, do the full destruction of the client. (alarm_notify_destroy): Destroy each element in the hash table. * cal-client/cal-client.c (cal_client_construct): Test for exceptions from OAF when activating the Wombat calendar factory. * gui/alarm-notify/GNOME_Evolution_Calendar_AlarmNotify.oaf.in: New .oaf.in file. * gui/alarm-notify/Makefile.am (oaf_in_files): Updated. * gui/GNOME_Evolution_Calendar.oaf.in: Put all the servers here instead of in a million files. * gui/GNOME_Evolution_Calendar_Control.oaf.in: Removed file. * gui/GNOME_Evolution_Calendar_gnomecal.oaf.in: Removed *REALLY* obsolete file. * gui/Makefile.am (oaf_in_files): Updated. svn path=/trunk/; revision=8375 --- calendar/ChangeLog | 26 +++++ calendar/cal-client/cal-client.c | 14 +-- calendar/gui/GNOME_Evolution_Calendar.oaf.in | 25 +++++ calendar/gui/GNOME_Evolution_Calendar.oafinfo | 89 ----------------- .../gui/GNOME_Evolution_Calendar_Control.oaf.in | 28 ------ .../gui/GNOME_Evolution_Calendar_Control.oafinfo | 28 ------ .../gui/GNOME_Evolution_Calendar_gnomecal.oaf.in | 27 ------ .../gui/GNOME_Evolution_Calendar_gnomecal.oafinfo | 27 ------ calendar/gui/Makefile.am | 8 +- calendar/gui/alarm-notify/.cvsignore | 2 + .../GNOME_Evolution_Calendar_AlarmNotify.oaf.in | 24 +++++ calendar/gui/alarm-notify/Makefile.am | 10 +- calendar/gui/alarm-notify/alarm-notify.c | 107 +++++++++++++++++---- calendar/gui/alarm-notify/alarm-queue.c | 12 +-- calendar/idl/evolution-calendar.idl | 2 +- 15 files changed, 187 insertions(+), 242 deletions(-) delete mode 100644 calendar/gui/GNOME_Evolution_Calendar.oafinfo delete mode 100644 calendar/gui/GNOME_Evolution_Calendar_Control.oaf.in delete mode 100644 calendar/gui/GNOME_Evolution_Calendar_Control.oafinfo delete mode 100644 calendar/gui/GNOME_Evolution_Calendar_gnomecal.oaf.in delete mode 100644 calendar/gui/GNOME_Evolution_Calendar_gnomecal.oafinfo create mode 100644 calendar/gui/alarm-notify/GNOME_Evolution_Calendar_AlarmNotify.oaf.in diff --git a/calendar/ChangeLog b/calendar/ChangeLog index c1ca40d772..98ba329e37 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,29 @@ +2001-02-23 Federico Mena Quintero + + * gui/alarm-notify/alarm-notify.c (AlarmNotify_addCalendar): + Switched to using our own refcounted structure for loaded clients. + (AlarmNotify_removeCalendar): Ditto. Also, do the full + destruction of the client. + (alarm_notify_destroy): Destroy each element in the hash table. + + * cal-client/cal-client.c (cal_client_construct): Test for + exceptions from OAF when activating the Wombat calendar factory. + + * gui/alarm-notify/GNOME_Evolution_Calendar_AlarmNotify.oaf.in: + New .oaf.in file. + + * gui/alarm-notify/Makefile.am (oaf_in_files): Updated. + + * gui/GNOME_Evolution_Calendar.oaf.in: Put all the servers here + instead of in a million files. + + * gui/GNOME_Evolution_Calendar_Control.oaf.in: Removed file. + + * gui/GNOME_Evolution_Calendar_gnomecal.oaf.in: Removed *REALLY* + obsolete file. + + * gui/Makefile.am (oaf_in_files): Updated. + 2001-02-23 Rodrigo Moya * pcs/cal-backend-db.c (add_history): fixed generation of history records diff --git a/calendar/cal-client/cal-client.c b/calendar/cal-client/cal-client.c index 0012ec3706..43a881f50f 100644 --- a/calendar/cal-client/cal-client.c +++ b/calendar/cal-client/cal-client.c @@ -407,7 +407,6 @@ cal_client_construct (CalClient *client) CalClientPrivate *priv; GNOME_Evolution_Calendar_CalFactory factory, factory_copy; CORBA_Environment ev; - int result; CORBA_exception_init (&ev); g_return_val_if_fail (client != NULL, NULL); @@ -415,23 +414,16 @@ cal_client_construct (CalClient *client) priv = client->priv; + CORBA_exception_init (&ev); factory = (GNOME_Evolution_Calendar_CalFactory) oaf_activate_from_id ( "OAFIID:GNOME_Evolution_Wombat_CalendarFactory", - OAF_FLAG_NO_LOCAL, NULL, &ev); + 0, NULL, &ev); - result = CORBA_Object_is_nil (factory, &ev); if (ev._major != CORBA_NO_EXCEPTION) { - g_message ("cal_client_construct(): could not see if the factory is NIL"); + g_message ("cal_client_construct(): Could not activate the calendar factory"); CORBA_exception_free (&ev); return NULL; } - CORBA_exception_free (&ev); - - if (result) { - g_message ("cal_client_construct(): could not contact Wombat, " - "the personal calendar server"); - return NULL; - } CORBA_exception_init (&ev); factory_copy = CORBA_Object_duplicate (factory, &ev); diff --git a/calendar/gui/GNOME_Evolution_Calendar.oaf.in b/calendar/gui/GNOME_Evolution_Calendar.oaf.in index e96e4b7c8a..0f74743a38 100644 --- a/calendar/gui/GNOME_Evolution_Calendar.oaf.in +++ b/calendar/gui/GNOME_Evolution_Calendar.oaf.in @@ -86,4 +86,29 @@ _value="Evolution calendar executive summary component."/> + + + + + + + + + + + + + + + + + + + diff --git a/calendar/gui/GNOME_Evolution_Calendar.oafinfo b/calendar/gui/GNOME_Evolution_Calendar.oafinfo deleted file mode 100644 index 75aa4a6b0f..0000000000 --- a/calendar/gui/GNOME_Evolution_Calendar.oafinfo +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/calendar/gui/GNOME_Evolution_Calendar_Control.oaf.in b/calendar/gui/GNOME_Evolution_Calendar_Control.oaf.in deleted file mode 100644 index d241806784..0000000000 --- a/calendar/gui/GNOME_Evolution_Calendar_Control.oaf.in +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/calendar/gui/GNOME_Evolution_Calendar_Control.oafinfo b/calendar/gui/GNOME_Evolution_Calendar_Control.oafinfo deleted file mode 100644 index 48cbfa7cbb..0000000000 --- a/calendar/gui/GNOME_Evolution_Calendar_Control.oafinfo +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/calendar/gui/GNOME_Evolution_Calendar_gnomecal.oaf.in b/calendar/gui/GNOME_Evolution_Calendar_gnomecal.oaf.in deleted file mode 100644 index 3719ba618b..0000000000 --- a/calendar/gui/GNOME_Evolution_Calendar_gnomecal.oaf.in +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/calendar/gui/GNOME_Evolution_Calendar_gnomecal.oafinfo b/calendar/gui/GNOME_Evolution_Calendar_gnomecal.oafinfo deleted file mode 100644 index c4b91b9dd8..0000000000 --- a/calendar/gui/GNOME_Evolution_Calendar_gnomecal.oafinfo +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am index 432acf0676..d6b7e6edea 100644 --- a/calendar/gui/Makefile.am +++ b/calendar/gui/Makefile.am @@ -13,8 +13,8 @@ $(IDL_GENERATED): $(IDLS) $(ORBIT_IDL) -I $(srcdir) -I $(datadir)/idl `$(GNOME_CONFIG) --cflags idl` \ $(srcdir)/../../composer/Evolution-Composer.idl -#SUBDIRS = alarm-notify dialogs -SUBDIRS = dialogs +SUBDIRS = alarm-notify dialogs +#SUBDIRS = dialogs help_base = $(datadir)/gnome/help/cal @@ -134,9 +134,7 @@ evolution_calendar_LDADD = \ oafdir = $(datadir)/oaf oaf_in_files = \ - GNOME_Evolution_Calendar_Control.oaf.in \ - GNOME_Evolution_Calendar.oaf.in \ - GNOME_Evolution_Calendar_gnomecal.oaf.in + GNOME_Evolution_Calendar.oaf.in oaf_DATA = $(oaf_in_files:.oaf.in=.oaf) diff --git a/calendar/gui/alarm-notify/.cvsignore b/calendar/gui/alarm-notify/.cvsignore index fa1c1f7c87..1f2b546c7c 100644 --- a/calendar/gui/alarm-notify/.cvsignore +++ b/calendar/gui/alarm-notify/.cvsignore @@ -6,3 +6,5 @@ evolution-calendar-stubs.c evolution-calendar-skels.c evolution-calendar-common.c evolution-calendar.h +evolution-alarm-notify +GNOME_Evolution_Calendar_AlarmNotify.oaf diff --git a/calendar/gui/alarm-notify/GNOME_Evolution_Calendar_AlarmNotify.oaf.in b/calendar/gui/alarm-notify/GNOME_Evolution_Calendar_AlarmNotify.oaf.in new file mode 100644 index 0000000000..86f5c71493 --- /dev/null +++ b/calendar/gui/alarm-notify/GNOME_Evolution_Calendar_AlarmNotify.oaf.in @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/calendar/gui/alarm-notify/Makefile.am b/calendar/gui/alarm-notify/Makefile.am index 5df0b3c234..3201f062f6 100644 --- a/calendar/gui/alarm-notify/Makefile.am +++ b/calendar/gui/alarm-notify/Makefile.am @@ -47,10 +47,16 @@ evolution_alarm_notify_LDADD = \ $(INTLLIBS) oafdir = $(datadir)/oaf -oaf_DATA = GNOME_Evolution_Calendar_AlarmNotify.oafinfo +oaf_in_files = \ + GNOME_Evolution_Calendar_AlarmNotify.oaf.in + +oaf_DATA = $(oaf_in_files:.oaf.in=.oaf) + +@XML_I18N_MERGE_OAF_RULE@ EXTRA_DIST = \ - $(oaf_DATA) + $(oaf_DATA) \ + $(oaf_in_files) BUILT_SOURCES = $(CORBA_GENERATED) CLEANFILES += $(BUILT_SOURCES) diff --git a/calendar/gui/alarm-notify/alarm-notify.c b/calendar/gui/alarm-notify/alarm-notify.c index 9d64bfd4a8..fa70a1d236 100644 --- a/calendar/gui/alarm-notify/alarm-notify.c +++ b/calendar/gui/alarm-notify/alarm-notify.c @@ -27,12 +27,29 @@ #include #include #include "alarm-notify.h" +#include "alarm-queue.h" +/* A loaded client */ +typedef struct { + /* The actual client */ + CalClient *client; + + /* The URI of the client in gnome-vfs's format. This *is* the key that + * is stored in the uri_client_hash hash table below. + */ + GnomeVFSURI *uri; + + /* Number of times clients have requested this URI to be added to the + * alarm notification system. + */ + int refcount; +} LoadedClient; + /* Private part of the AlarmNotify structure */ struct _AlarmNotifyPrivate { - /* Mapping from GnomeVFSURIs to loaded clients */ + /* Mapping from GnomeVFSURIs to LoadedClient structures */ GHashTable *uri_client_hash; }; @@ -114,6 +131,19 @@ alarm_notify_init (AlarmNotify *an) priv->uri_client_hash = g_hash_table_new (gnome_vfs_uri_hash, gnome_vfs_uri_hequal); } +/* Callback used from g_hash-table_forach(), used to destroy a loade client */ +static void +destroy_loaded_client_cb (gpointer key, gpointer value, gpointer data) +{ + LoadedClient *lc; + + lc = value; + + gtk_object_unref (GTK_OBJECT (lc->client)); + gnome_vfs_uri_unref (lc->uri); + g_free (lc); +} + /* Destroy handler for the alarm notify system */ static void alarm_notify_destroy (GtkObject *object) @@ -127,7 +157,7 @@ alarm_notify_destroy (GtkObject *object) an = ALARM_NOTIFY (object); priv = an->priv; - /* FIXME */ + g_hash_table_foreach (priv->uri_client_hash, destroy_loaded_client_cb, NULL); g_hash_table_destroy (priv->uri_client_hash); priv->uri_client_hash = NULL; @@ -153,6 +183,7 @@ AlarmNotify_addCalendar (PortableServer_Servant servant, AlarmNotifyPrivate *priv; GnomeVFSURI *uri; CalClient *client; + LoadedClient *lc; an = ALARM_NOTIFY (bonobo_object_from_servant (servant)); priv = an->priv; @@ -165,26 +196,33 @@ AlarmNotify_addCalendar (PortableServer_Servant servant, return; } - client = g_hash_table_lookup (priv->uri_client_hash, uri); + lc = g_hash_table_lookup (priv->uri_client_hash, uri); - if (client) { + if (lc) { gnome_vfs_uri_unref (uri); - - gtk_object_ref (GTK_OBJECT (client)); + g_assert (lc->refcount > 0); + lc->refcount++; return; } client = cal_client_new (); if (client) { - g_hash_table_insert (priv->uri_client_hash, uri); - alarm_queue_add_client (client); - - if (!cal_client_open_calendar (client, str_uri, FALSE)) { + if (cal_client_open_calendar (client, str_uri, FALSE)) { + lc = g_new (LoadedClient, 1); + lc->client = client; + lc->uri = uri; + lc->refcount = 1; + g_hash_table_insert (priv->uri_client_hash, uri, lc); + + alarm_queue_add_client (client); + } else { gtk_object_unref (GTK_OBJECT (client)); client = NULL; } - } else { + } + + if (!client) { gnome_vfs_uri_unref (uri); CORBA_exception_set (ev, CORBA_USER_EXCEPTION, @@ -197,26 +235,59 @@ AlarmNotify_addCalendar (PortableServer_Servant servant, /* AlarmNotify::removeCalendar method */ static void AlarmNotify_removeCalendar (PortableServer_Servant servant, - const CORBA_char *uri, + const CORBA_char *str_uri, CORBA_Environment *ev) { AlarmNotify *an; AlarmNotifyPrivate *priv; - CalClient *client; - char *orig_uri; + LoadedClient *lc; + GnomeVFSURI *uri; an = ALARM_NOTIFY (bonobo_object_from_servant (servant)); priv = an->priv; - if (!g_hash_table_lookup_extended (priv->uri_client_hash, uri, &orig_uri, &client)) { + uri = gnome_vfs_uri_new (str_uri); + if (!uri) { CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_AlarmNotify_NotFound); + ex_GNOME_Evolution_Calendar_AlarmNotify_InvalidURI, + NULL); return; } - gtk_object_unref (client); + lc = g_hash_table_lookup (priv->uri_client_hash, uri); + gnome_vfs_uri_unref (uri); + + if (!lc) { + CORBA_exception_set (ev, CORBA_USER_EXCEPTION, + ex_GNOME_Evolution_Calendar_AlarmNotify_NotFound, + NULL); + return; + } - /* FIXME: do we need to do anything else? */ + g_assert (lc->refcount > 0); + + lc->refcount--; + if (lc->refcount > 0) + return; + + g_hash_table_remove (priv->uri_client_hash, lc->uri); + + gtk_object_unref (GTK_OBJECT (lc->client)); + gnome_vfs_uri_unref (lc->uri); + g_free (lc); +} + +static void +AlarmNotify_die (PortableServer_Servant servant, + CORBA_Environment *ev) +{ + AlarmNotify *an; + AlarmNotifyPrivate *priv; + + an = ALARM_NOTIFY (bonobo_object_from_servant (servant)); + priv = an->priv; + + /* FIXME */ } /** diff --git a/calendar/gui/alarm-notify/alarm-queue.c b/calendar/gui/alarm-notify/alarm-queue.c index e2f2ae88db..1e235c116d 100644 --- a/calendar/gui/alarm-notify/alarm-queue.c +++ b/calendar/gui/alarm-notify/alarm-queue.c @@ -286,13 +286,13 @@ load_alarms (ClientAlarms *ca) /* Called when a calendar client finished loading; we load its alarms */ static void -cal_loaded_cb (CalClient *client, CalClientLoadStatus status, gpointer data) +cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data) { ClientAlarms *ca; ca = data; - if (status != CAL_CLIENT_LOAD_SUCCESS) + if (status != CAL_CLIENT_OPEN_SUCCESS) return; load_alarms (ca); @@ -463,16 +463,16 @@ alarm_queue_add_client (CalClient *client) ca->uid_alarms_hash = g_hash_table_new (g_str_hash, g_str_equal); - if (!cal_client_is_loaded (client)) - gtk_signal_connect (GTK_OBJECT (client), "cal_loaded", - GTK_SIGNAL_FUNC (cal_loaded_cb), ca); + if (cal_client_get_load_state (client) != CAL_CLIENT_LOAD_LOADED) + gtk_signal_connect (GTK_OBJECT (client), "cal_opened", + GTK_SIGNAL_FUNC (cal_opened_cb), ca); gtk_signal_connect (GTK_OBJECT (client), "obj_updated", GTK_SIGNAL_FUNC (obj_updated_cb), ca); gtk_signal_connect (GTK_OBJECT (client), "obj_removed", GTK_SIGNAL_FUNC (obj_removed_cb), ca); - if (cal_client_is_loaded (client)) + if (cal_client_get_load_state (client) == CAL_CLIENT_LOAD_LOADED) load_alarms (ca); } diff --git a/calendar/idl/evolution-calendar.idl b/calendar/idl/evolution-calendar.idl index c3de81e41f..f8f727c196 100644 --- a/calendar/idl/evolution-calendar.idl +++ b/calendar/idl/evolution-calendar.idl @@ -198,7 +198,7 @@ module Calendar { /* Removes a calendar from the alarm notification system */ void removeCalendar (in string uri) - raises (NotFound); + raises (InvalidURI, NotFound); /* Makes the alarm notification daemon unconditionally exit */ void die (); -- cgit