[telepathy-mission-control/master] McdAccount: account_request_cancel: move logic of how to cancel into McdChannel
Simon McVittie
simon.mcvittie at collabora.co.uk
Mon Apr 6 09:59:41 PDT 2009
---
src/mcd-account-requests.c | 28 ++--------------------------
src/mcd-channel.c | 37 +++++++++++++++++++++++++++++++++++++
src/mcd-channel.h | 3 +++
3 files changed, 42 insertions(+), 26 deletions(-)
diff --git a/src/mcd-account-requests.c b/src/mcd-account-requests.c
index c21bde4..aa48b67 100644
--- a/src/mcd-account-requests.c
+++ b/src/mcd-account-requests.c
@@ -277,9 +277,8 @@ account_request_cancel (McSvcAccountInterfaceChannelRequests *self,
const gchar *request_id,
DBusGMethodInvocation *context)
{
- GError *error;
+ GError *error = NULL;
McdChannel *channel;
- McdChannelStatus status;
DEBUG ("called for %s", request_id);
g_return_if_fail (request_id != NULL);
@@ -293,31 +292,8 @@ account_request_cancel (McSvcAccountInterfaceChannelRequests *self,
return;
}
- status = mcd_channel_get_status (channel);
- DEBUG ("channel %p is in status %u", channel, status);
- if (status == MCD_CHANNEL_STATUS_REQUEST ||
- status == MCD_CHANNEL_STATUS_REQUESTED ||
- status == MCD_CHANNEL_STATUS_DISPATCHING)
- {
- g_object_ref (channel);
- error = g_error_new (TP_ERRORS, TP_ERROR_CANCELLED, "Cancelled");
- mcd_channel_take_error (channel, error);
-
- /* REQUESTED is a special case: the channel must not be aborted now,
- * because we need to explicitly close the channel object when it will
- * be created by the CM. In that case, mcd_mission_abort() will be
- * called once the Create/EnsureChannel method returns, if the channel
- * is ours */
- if (status != MCD_CHANNEL_STATUS_REQUESTED)
- mcd_mission_abort (MCD_MISSION (channel));
-
- g_object_unref (channel);
- }
- else
+ if (!_mcd_channel_request_cancel (channel, &error))
{
- error = g_error_new (TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
- "Request %s is not cancellable (%u)",
- request_id, status);
dbus_g_method_return_error (context, error);
g_error_free (error);
return;
diff --git a/src/mcd-channel.c b/src/mcd-channel.c
index 38bfc2c..9ab6b4d 100644
--- a/src/mcd-channel.c
+++ b/src/mcd-channel.c
@@ -1475,6 +1475,43 @@ channel_request_proceed (McSvcChannelRequest *iface,
mc_svc_channel_request_return_from_proceed (context);
}
+gboolean
+_mcd_channel_request_cancel (McdChannel *self,
+ GError **error)
+{
+ McdChannelStatus status = mcd_channel_get_status (self);
+
+ DEBUG ("%p in status %u", self, status);
+
+ if (status == MCD_CHANNEL_STATUS_REQUEST ||
+ status == MCD_CHANNEL_STATUS_REQUESTED ||
+ status == MCD_CHANNEL_STATUS_DISPATCHING)
+ {
+ g_object_ref (self);
+ mcd_channel_take_error (self, g_error_new (TP_ERRORS,
+ TP_ERROR_CANCELLED,
+ "Cancelled"));
+
+ /* REQUESTED is a special case: the channel must not be aborted now,
+ * because we need to explicitly close the channel object when it will
+ * be created by the CM. In that case, mcd_mission_abort() will be
+ * called once the Create/EnsureChannel method returns, if the channel
+ * is ours */
+ if (status != MCD_CHANNEL_STATUS_REQUESTED)
+ mcd_mission_abort (MCD_MISSION (self));
+
+ g_object_unref (self);
+ return TRUE;
+ }
+ else
+ {
+ g_set_error (error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
+ "ChannelRequest is not cancellable (status=%u)",
+ status);
+ return FALSE;
+ }
+}
+
static void
channel_request_cancel (McSvcChannelRequest *iface,
DBusGMethodInvocation *context)
diff --git a/src/mcd-channel.h b/src/mcd-channel.h
index 268c836..123ba55 100644
--- a/src/mcd-channel.h
+++ b/src/mcd-channel.h
@@ -166,6 +166,9 @@ const gchar *_mcd_channel_get_request_preferred_handler (McdChannel *channel);
G_GNUC_INTERNAL
gboolean _mcd_channel_get_request_use_existing (McdChannel *channel);
+G_GNUC_INTERNAL gboolean _mcd_channel_request_cancel (McdChannel *self,
+ GError **error);
+
G_GNUC_INTERNAL
void _mcd_channel_copy_details (McdChannel *channel, McdChannel *source);
G_GNUC_INTERNAL
--
1.5.6.5
More information about the telepathy-commits
mailing list