From 9e60266b1609886458fbb3a7ce12ba0b5f92092e Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 20 Jul 2012 12:13:30 +0100 Subject: [PATCH 11/16] _mcd_dispatch_operation_dup_channels: turn into dup_channel, singular --- src/mcd-dispatch-operation-priv.h | 2 +- src/mcd-dispatch-operation.c | 17 ++++++++++------- src/mcd-dispatcher.c | 13 +++---------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/mcd-dispatch-operation-priv.h b/src/mcd-dispatch-operation-priv.h index 23ddb5d..a861171 100644 --- a/src/mcd-dispatch-operation-priv.h +++ b/src/mcd-dispatch-operation-priv.h @@ -77,7 +77,7 @@ G_GNUC_INTERNAL gboolean _mcd_dispatch_operation_has_channel ( McdDispatchOperation *self, McdChannel *channel); G_GNUC_INTERNAL McdChannel *_mcd_dispatch_operation_peek_channel ( McdDispatchOperation *self); -G_GNUC_INTERNAL GList *_mcd_dispatch_operation_dup_channels ( +G_GNUC_INTERNAL McdChannel *_mcd_dispatch_operation_dup_channel ( McdDispatchOperation *self); G_GNUC_INTERNAL gboolean _mcd_dispatch_operation_is_finished ( diff --git a/src/mcd-dispatch-operation.c b/src/mcd-dispatch-operation.c index 4559c87..d18f3cc 100644 --- a/src/mcd-dispatch-operation.c +++ b/src/mcd-dispatch-operation.c @@ -1897,15 +1897,18 @@ _mcd_dispatch_operation_peek_channel (McdDispatchOperation *self) return self->priv->channels->data; } -GList * -_mcd_dispatch_operation_dup_channels (McdDispatchOperation *self) +McdChannel * +_mcd_dispatch_operation_dup_channel (McdDispatchOperation *self) { - GList *copy; - g_return_val_if_fail (MCD_IS_DISPATCH_OPERATION (self), NULL); - copy = g_list_copy (self->priv->channels); - g_list_foreach (copy, (GFunc) g_object_ref, NULL); - return copy; + + g_assert (self->priv->channels == NULL || + self->priv->channels->next == NULL); + + if (self->priv->channels != NULL) + return g_object_ref (self->priv->channels->data); + + return NULL; } static void diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c index 07d6f9a..ce3292d 100644 --- a/src/mcd-dispatcher.c +++ b/src/mcd-dispatcher.c @@ -293,25 +293,18 @@ _mcd_dispatcher_enter_state_machine (McdDispatcher *dispatcher, { GError error = { TP_ERROR, TP_ERROR_CANCELLED, "Channel request cancelled" }; - GList *list; + McdChannel *cancelled; - /* make a temporary copy, which is destroyed during the loop - - * otherwise we'll be trying to iterate over the list at the same time - * that mcd_mission_abort results in modifying it, which would be - * bad */ - list = _mcd_dispatch_operation_dup_channels (operation); + cancelled = _mcd_dispatch_operation_dup_channel (operation); - while (list != NULL) + if (cancelled != NULL) { - McdChannel *cancelled = MCD_CHANNEL (list->data); - if (mcd_channel_get_error (cancelled) == NULL) mcd_channel_take_error (cancelled, g_error_copy (&error)); _mcd_channel_undispatchable (cancelled); g_object_unref (cancelled); - list = g_list_delete_link (list, list); } } else if (_mcd_dispatch_operation_peek_channel (operation) == NULL) -- 1.7.10.4