From 26cbf6cd5fb66c8c490bbb4d148b811139ec9210 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Wed, 8 Aug 2001 00:22:07 +0000 Subject: New function to stop further notification from happening. 2001-08-07 Federico Mena Quintero * cal-client/cal-listener.c (cal_listener_stop_notification): New function to stop further notification from happening. (impl_notifyCalOpened): Do not notify if requested. (impl_notifyObjUpdated): Likewise. (impl_notifyObjRemoved): Likewise. (impl_notifyCategoriesChanged): Likewise. (CalListenerPrivate): Do not keep a reference to the server-side Cal. This would create a circular reference since the server keeps a reference to the listener. (cal_listener_destroy): Likewise. (impl_notifyCalOpened): Likewise. * pcs/cal.c (cal_destroy): bonobo_object_release_unref() the listener. * cal-client/cal-client.c (cal_client_destroy): Ask the listener to stop notifications. Also, do not unref it as the server does that itself when we unref the Cal. svn path=/trunk/; revision=11758 --- calendar/ChangeLog | 20 ++++++++++++ calendar/cal-client/cal-client.c | 22 ++++--------- calendar/cal-client/cal-listener.c | 66 ++++++++++++++++++++++---------------- calendar/cal-client/cal-listener.h | 2 ++ calendar/pcs/cal.c | 3 +- 5 files changed, 68 insertions(+), 45 deletions(-) diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 5fa5d4f17c..304831fd7d 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,23 @@ +2001-08-07 Federico Mena Quintero + + * cal-client/cal-listener.c (cal_listener_stop_notification): New + function to stop further notification from happening. + (impl_notifyCalOpened): Do not notify if requested. + (impl_notifyObjUpdated): Likewise. + (impl_notifyObjRemoved): Likewise. + (impl_notifyCategoriesChanged): Likewise. + (CalListenerPrivate): Do not keep a reference to the server-side + Cal. This would create a circular reference since the server + keeps a reference to the listener. + (cal_listener_destroy): Likewise. + (impl_notifyCalOpened): Likewise. + + * pcs/cal.c (cal_destroy): bonobo_object_release_unref() the listener. + + * cal-client/cal-client.c (cal_client_destroy): Ask the listener + to stop notifications. Also, do not unref it as the server does + that itself when we unref the Cal. + 2001-08-07 Federico Mena Quintero * gui/calendar-model.c (calendar_model_free_value): Only unref the diff --git a/calendar/cal-client/cal-client.c b/calendar/cal-client/cal-client.c index 41e42613bb..f0519057d6 100644 --- a/calendar/cal-client/cal-client.c +++ b/calendar/cal-client/cal-client.c @@ -260,21 +260,6 @@ destroy_factory (CalClient *client) priv->factory = CORBA_OBJECT_NIL; } -/* Gets rid of the listener that a client knows about */ -static void -destroy_listener (CalClient *client) -{ - CalClientPrivate *priv; - - priv = client->priv; - - if (!priv->listener) - return; - - bonobo_object_unref (BONOBO_OBJECT (priv->listener)); - priv->listener = NULL; -} - /* Gets rid of the calendar client interface object that a client knows about */ static void destroy_cal (CalClient *client) @@ -337,9 +322,14 @@ cal_client_destroy (GtkObject *object) client = CAL_CLIENT (object); priv = client->priv; + /* The server unrefs the query listener, so we just NULL it out here */ + if (priv->listener) { + cal_listener_stop_notification (priv->listener); + priv->listener = NULL; + } + destroy_wombat_client (client); destroy_factory (client); - destroy_listener (client); destroy_cal (client); priv->load_state = CAL_CLIENT_LOAD_NOT_LOADED; diff --git a/calendar/cal-client/cal-listener.c b/calendar/cal-client/cal-listener.c index 0062718155..8d4d49c286 100644 --- a/calendar/cal-client/cal-listener.c +++ b/calendar/cal-client/cal-listener.c @@ -26,15 +26,15 @@ /* Private part of the CalListener structure */ struct CalListenerPrivate { - /* The calendar this listener refers to */ - GNOME_Evolution_Calendar_Cal cal; - /* Notification functions and their closure data */ CalListenerCalOpenedFn cal_opened_fn; CalListenerObjUpdatedFn obj_updated_fn; CalListenerObjRemovedFn obj_removed_fn; CalListenerCategoriesChangedFn categories_changed_fn; gpointer fn_data; + + /* Whether notification is desired */ + gboolean notify : 1; }; @@ -93,11 +93,12 @@ cal_listener_init (CalListener *listener) priv = g_new0 (CalListenerPrivate, 1); listener->priv = priv; - priv->cal = CORBA_OBJECT_NIL; priv->cal_opened_fn = NULL; priv->obj_updated_fn = NULL; priv->obj_removed_fn = NULL; priv->categories_changed_fn = NULL; + + priv->notify = TRUE; } /* Destroy handler for the calendar listener */ @@ -106,8 +107,6 @@ cal_listener_destroy (GtkObject *object) { CalListener *listener; CalListenerPrivate *priv; - CORBA_Environment ev; - gboolean result; g_return_if_fail (object != NULL); g_return_if_fail (IS_CAL_LISTENER (object)); @@ -121,23 +120,7 @@ cal_listener_destroy (GtkObject *object) priv->categories_changed_fn = NULL; priv->fn_data = NULL; - CORBA_exception_init (&ev); - result = CORBA_Object_is_nil (priv->cal, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) - g_message ("cal_listener_destroy(): could not see if the calendar was NIL"); - else if (!result) { - CORBA_exception_free (&ev); - - CORBA_exception_init (&ev); - CORBA_Object_release (priv->cal, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) - g_message ("cal_listener_destroy(): could not release the calendar"); - - priv->cal = CORBA_OBJECT_NIL; - } - CORBA_exception_free (&ev); + priv->notify = FALSE; g_free (priv); listener->priv = NULL; @@ -165,10 +148,8 @@ impl_notifyCalOpened (PortableServer_Servant servant, listener = CAL_LISTENER (bonobo_object_from_servant (servant)); priv = listener->priv; - if (priv->cal != CORBA_OBJECT_NIL) { - g_message ("Listener_notifyCalOpened(): calendar was already open!"); + if (!priv->notify) return; - } CORBA_exception_init (&aev); cal_copy = CORBA_Object_duplicate (cal, &aev); @@ -180,8 +161,6 @@ impl_notifyCalOpened (PortableServer_Servant servant, } CORBA_exception_free (&aev); - priv->cal = cal_copy; - g_assert (priv->cal_opened_fn != NULL); (* priv->cal_opened_fn) (listener, status, cal, priv->fn_data); } @@ -198,6 +177,9 @@ impl_notifyObjUpdated (PortableServer_Servant servant, listener = CAL_LISTENER (bonobo_object_from_servant (servant)); priv = listener->priv; + if (!priv->notify) + return; + g_assert (priv->obj_updated_fn != NULL); (* priv->obj_updated_fn) (listener, uid, priv->fn_data); } @@ -214,6 +196,9 @@ impl_notifyObjRemoved (PortableServer_Servant servant, listener = CAL_LISTENER (bonobo_object_from_servant (servant)); priv = listener->priv; + if (!priv->notify) + return; + g_assert (priv->obj_removed_fn != NULL); (* priv->obj_removed_fn) (listener, uid, priv->fn_data); } @@ -230,6 +215,9 @@ impl_notifyCategoriesChanged (PortableServer_Servant servant, listener = CAL_LISTENER (bonobo_object_from_servant (servant)); priv = listener->priv; + if (!priv->notify) + return; + g_assert (priv->categories_changed_fn != NULL); (* priv->categories_changed_fn) (listener, categories, priv->fn_data); } @@ -322,3 +310,25 @@ cal_listener_new (CalListenerCalOpenedFn cal_opened_fn, categories_changed_fn, fn_data); } + +/** + * cal_listener_stop_notification: + * @listener: A calendar listener. + * + * Informs a calendar listener that no further notification is desired. The + * callbacks specified when the listener was created will no longer be invoked + * after this function is called. + **/ +void +cal_listener_stop_notification (CalListener *listener) +{ + CalListenerPrivate *priv; + + g_return_if_fail (listener != NULL); + g_return_if_fail (IS_CAL_LISTENER (listener)); + + priv = listener->priv; + g_return_if_fail (priv->notify != FALSE); + + priv->notify = FALSE; +} diff --git a/calendar/cal-client/cal-listener.h b/calendar/cal-client/cal-listener.h index 4cbbd8b8c9..87a4f892fe 100644 --- a/calendar/cal-client/cal-listener.h +++ b/calendar/cal-client/cal-listener.h @@ -85,6 +85,8 @@ CalListener *cal_listener_new (CalListenerCalOpenedFn cal_opened_fn, CalListenerCategoriesChangedFn categories_changed_fn, gpointer fn_data); +void cal_listener_stop_notification (CalListener *listener); + END_GNOME_DECLS diff --git a/calendar/pcs/cal.c b/calendar/pcs/cal.c index cb92f391b5..213ad35c31 100644 --- a/calendar/pcs/cal.c +++ b/calendar/pcs/cal.c @@ -554,10 +554,11 @@ cal_destroy (GtkObject *object) priv->backend = NULL; CORBA_exception_init (&ev); - CORBA_Object_release (priv->listener, &ev); + bonobo_object_release_unref (priv->listener, &ev); if (ev._major != CORBA_NO_EXCEPTION) g_message ("cal_destroy(): could not release the listener"); + priv->listener = NULL; CORBA_exception_free (&ev); g_free (priv); -- cgit v1.2.3