[telepathy-gabble/telepathy-gabble-0.8] Close all media channels on disconnect.
Will Thompson
will.thompson at collabora.co.uk
Wed Aug 19 06:13:20 PDT 2009
Relying on unreffing the channel to make it close is silly, and
complicates the code.
---
src/media-channel.c | 3 +--
src/media-channel.h | 2 ++
src/media-factory.c | 36 ++++++++++++------------------------
3 files changed, 15 insertions(+), 26 deletions(-)
diff --git a/src/media-channel.c b/src/media-channel.c
index 7c4cc0d..b1106c5 100644
--- a/src/media-channel.c
+++ b/src/media-channel.c
@@ -620,7 +620,6 @@ static gboolean gabble_media_channel_add_member (GObject *obj,
GError **error);
static gboolean gabble_media_channel_remove_member (GObject *obj,
TpHandle handle, const gchar *message, guint reason, GError **error);
-static void gabble_media_channel_close (GabbleMediaChannel *self);
static void
gabble_media_channel_class_init (GabbleMediaChannelClass *gabble_media_channel_class)
@@ -895,7 +894,7 @@ gabble_media_channel_close_async (TpSvcChannel *iface,
tp_svc_channel_return_from_close (context);
}
-static void
+void
gabble_media_channel_close (GabbleMediaChannel *self)
{
GabbleMediaChannelPrivate *priv = self->priv;
diff --git a/src/media-channel.h b/src/media-channel.h
index f00e85f..a91404b 100644
--- a/src/media-channel.h
+++ b/src/media-channel.h
@@ -82,6 +82,8 @@ void gabble_media_channel_request_initial_streams (GabbleMediaChannel *chan,
GFunc failed_cb,
gpointer user_data);
+void gabble_media_channel_close (GabbleMediaChannel *self);
+
G_END_DECLS
#endif /* #ifndef __GABBLE_MEDIA_CHANNEL_H__*/
diff --git a/src/media-factory.c b/src/media-factory.c
index 4d28d03..5171184 100644
--- a/src/media-factory.c
+++ b/src/media-factory.c
@@ -105,7 +105,8 @@ gabble_media_factory_dispose (GObject *object)
priv->dispose_has_run = TRUE;
gabble_media_factory_close_all (fac);
- g_assert (priv->channels == NULL);
+ g_assert (priv->channels->len == 0);
+ g_ptr_array_free (priv->channels, TRUE);
if (G_OBJECT_CLASS (gabble_media_factory_parent_class)->dispose)
G_OBJECT_CLASS (gabble_media_factory_parent_class)->dispose (object);
@@ -191,14 +192,11 @@ media_channel_closed_cb (GabbleMediaChannel *chan, gpointer user_data)
tp_channel_manager_emit_channel_closed_for_object (fac,
TP_EXPORTABLE_CHANNEL (chan));
- if (priv->channels != NULL)
- {
- DEBUG ("removing media channel %p with ref count %d",
- chan, G_OBJECT (chan)->ref_count);
+ DEBUG ("removing media channel %p with ref count %d",
+ chan, G_OBJECT (chan)->ref_count);
- g_ptr_array_remove (priv->channels, chan);
- g_object_unref (chan);
- }
+ g_ptr_array_remove (priv->channels, chan);
+ g_object_unref (chan);
}
/**
@@ -253,27 +251,17 @@ static void
gabble_media_factory_close_all (GabbleMediaFactory *fac)
{
GabbleMediaFactoryPrivate *priv = fac->priv;
+ GPtrArray *tmp = gabble_g_ptr_array_copy (priv->channels);
+ guint i;
DEBUG ("closing channels");
- if (priv->channels != NULL)
+ for (i = 0; i < tmp->len; i++)
{
- GPtrArray *tmp = priv->channels;
- guint i;
-
- priv->channels = NULL;
-
- for (i = 0; i < tmp->len; i++)
- {
- GabbleMediaChannel *chan = g_ptr_array_index (tmp, i);
-
- DEBUG ("about to unref channel with ref_count %d",
- G_OBJECT (chan)->ref_count);
-
- g_object_unref (chan);
- }
+ GabbleMediaChannel *chan = g_ptr_array_index (tmp, i);
- g_ptr_array_free (tmp, TRUE);
+ DEBUG ("closing %p", chan);
+ gabble_media_channel_close (chan);
}
if (priv->status_changed_id != 0)
--
1.5.6.5
More information about the telepathy-commits
mailing list