aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2012-05-26 15:56:10 -0500
committerCharles Kerr <charles.kerr@canonical.com>2012-05-26 15:56:10 -0500
commitb3a1b201431b649b5fb37d1c10a2609e92d06239 (patch)
treef23a5daed4369dcbcc2b9fd11e35049ba1ed08fe
parent29ec6d23c13cbe7487232b79700c5d5406c26014 (diff)
downloadayatana-indicator-power-b3a1b201431b649b5fb37d1c10a2609e92d06239.tar.gz
ayatana-indicator-power-b3a1b201431b649b5fb37d1c10a2609e92d06239.tar.bz2
ayatana-indicator-power-b3a1b201431b649b5fb37d1c10a2609e92d06239.zip
avoid a cyclical refcount dependency between IndicatorPower and its DBusListener
-rw-r--r--src/dbus-listener.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/dbus-listener.c b/src/dbus-listener.c
index fe8af09..9f62f25 100644
--- a/src/dbus-listener.c
+++ b/src/dbus-listener.c
@@ -102,6 +102,20 @@ indicator_power_dbus_listener_init (IndicatorPowerDbusListener *self)
}
static void
+set_indicator (IndicatorPowerDbusListener * self, GObject * ipower)
+{
+ IndicatorPowerDbusListenerPrivate * priv = self->priv;
+
+ if (priv->ipower != NULL)
+ g_object_remove_weak_pointer (G_OBJECT(priv->ipower), (gpointer*)&priv->ipower);
+
+ priv->ipower = INDICATOR_POWER(ipower);
+
+ if (priv->ipower != NULL)
+ g_object_add_weak_pointer (G_OBJECT(priv->ipower), (gpointer*)&priv->ipower);
+};
+
+static void
indicator_power_dbus_listener_dispose (GObject *object)
{
IndicatorPowerDbusListener * self = INDICATOR_POWER_DBUS_LISTENER(object);
@@ -109,7 +123,8 @@ indicator_power_dbus_listener_dispose (GObject *object)
g_clear_object (&priv->proxy);
g_clear_object (&priv->proxy_cancel);
- g_clear_object (&priv->ipower);
+
+ set_indicator (self, NULL);
G_OBJECT_CLASS (indicator_power_dbus_listener_parent_class)->dispose (object);
}
@@ -142,12 +157,11 @@ static void
set_property (GObject * o, guint prop_id, const GValue * value, GParamSpec * pspec)
{
IndicatorPowerDbusListener * self = INDICATOR_POWER_DBUS_LISTENER(o);
- IndicatorPowerDbusListenerPrivate * priv = self->priv;
switch (prop_id)
{
case PROP_INDICATOR:
- priv->ipower = g_value_dup_object (value);
+ set_indicator (self, g_value_get_object(value));
break;
}
}