[evolution-data-server] ECalClientView: Keep a weak reference on its ECalClient.



commit 3b946e86f1716d469c36918fd04cba73a6b98bf4
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Mar 13 09:21:38 2013 -0400

    ECalClientView: Keep a weak reference on its ECalClient.
    
    The view should cease functioning if its ECalClient is destroyed.

 calendar/libecal/e-cal-client-view.c |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)
---
diff --git a/calendar/libecal/e-cal-client-view.c b/calendar/libecal/e-cal-client-view.c
index a02780f..53527c2 100644
--- a/calendar/libecal/e-cal-client-view.c
+++ b/calendar/libecal/e-cal-client-view.c
@@ -40,7 +40,7 @@
 typedef struct _SignalClosure SignalClosure;
 
 struct _ECalClientViewPrivate {
-       ECalClient *client;
+       GWeakRef client;
        GDBusProxy *dbus_proxy;
        GDBusConnection *connection;
        gchar *object_path;
@@ -480,9 +480,8 @@ cal_client_view_set_client (ECalClientView *view,
                             ECalClient *client)
 {
        g_return_if_fail (E_IS_CAL_CLIENT (client));
-       g_return_if_fail (view->priv->client == NULL);
 
-       view->priv->client = g_object_ref (client);
+       g_weak_ref_set (&view->priv->client, client);
 }
 
 static void
@@ -573,10 +572,7 @@ cal_client_view_dispose (GObject *object)
 
        priv = E_CAL_CLIENT_VIEW_GET_PRIVATE (object);
 
-       if (priv->client != NULL) {
-               g_object_unref (priv->client);
-               priv->client = NULL;
-       }
+       g_weak_ref_set (&priv->client, NULL);
 
        if (priv->connection != NULL) {
                g_object_unref (priv->connection);
@@ -820,7 +816,7 @@ e_cal_client_view_ref_client (ECalClientView *view)
 {
        g_return_val_if_fail (E_IS_CAL_CLIENT_VIEW (view), NULL);
 
-       return g_object_ref (view->priv->client);
+       return g_weak_ref_get (&view->priv->client);
 }
 
 /**
@@ -838,9 +834,19 @@ e_cal_client_view_ref_client (ECalClientView *view)
 ECalClient *
 e_cal_client_view_get_client (ECalClientView *view)
 {
+       ECalClient *client;
+
        g_return_val_if_fail (E_IS_CAL_CLIENT_VIEW (view), NULL);
 
-       return view->priv->client;
+       client = e_cal_client_view_ref_client (view);
+
+       /* XXX Drop the ECalClient reference for backward-compatibility.
+        *     This is risky.  Without a reference, the ECalClient could
+        *     be finalized while the caller is still using it. */
+       if (client != NULL)
+               g_object_unref (client);
+
+       return client;
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]