From: Mikel Astiz <[email protected]>
If a previous cancel request is in progress, a second cancel request
should fail.
This by the way fixes unreplied D-Bus messages.
---
client/transfer.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/client/transfer.c b/client/transfer.c
index 242d989..0686afe 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -213,6 +213,11 @@ static DBusMessage *obc_transfer_cancel(DBusConnection *connection,
ERROR_INTERFACE ".NotAuthorized",
"Not Authorized");
+ if (transfer->msg != NULL)
+ return g_dbus_create_error(message,
+ ERROR_INTERFACE ".InProgress",
+ "Cancellation already in progress");
+
if (!obc_transfer_abort(transfer))
return g_dbus_create_error(message,
ERROR_INTERFACE ".Failed",
--
1.7.7.6
Hi Mikel,
On Tue, Jun 12, 2012 at 3:10 PM, Mikel Astiz <[email protected]> wrote:
> From: Mikel Astiz <[email protected]>
>
> If a previous cancel request is in progress, a second cancel request
> should fail.
>
> This by the way fixes unreplied D-Bus messages.
> ---
> ?client/transfer.c | ? ?5 +++++
> ?1 files changed, 5 insertions(+), 0 deletions(-)
>
> diff --git a/client/transfer.c b/client/transfer.c
> index 242d989..0686afe 100644
> --- a/client/transfer.c
> +++ b/client/transfer.c
> @@ -213,6 +213,11 @@ static DBusMessage *obc_transfer_cancel(DBusConnection *connection,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ERROR_INTERFACE ".NotAuthorized",
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"Not Authorized");
>
> + ? ? ? if (transfer->msg != NULL)
> + ? ? ? ? ? ? ? return g_dbus_create_error(message,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ERROR_INTERFACE ".InProgress",
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "Cancellation already in progress");
> +
> ? ? ? ?if (!obc_transfer_abort(transfer))
> ? ? ? ? ? ? ? ?return g_dbus_create_error(message,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ERROR_INTERFACE ".Failed",
> --
> 1.7.7.6
All 3 patches are now upstream, thanks.
--
Luiz Augusto von Dentz
From: Mikel Astiz <[email protected]>
Cancelling queued (not started yet) transfers should not fail. Instead,
they must be removed from the queue, so we just need to call the
transfer callback.
---
client/transfer.c | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/client/transfer.c b/client/transfer.c
index f296638..cb7c26c 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -204,10 +204,20 @@ static DBusMessage *obc_transfer_cancel(DBusConnection *connection,
ERROR_INTERFACE ".InProgress",
"Cancellation already in progress");
- if (transfer->xfer == 0)
- return g_dbus_create_error(message,
- ERROR_INTERFACE ".Failed",
- "Failed");
+ if (transfer->xfer == 0) {
+ struct transfer_callback *callback = transfer->callback;
+
+ if (callback != NULL) {
+ GError *err;
+
+ err = g_error_new(OBC_TRANSFER_ERROR, -ECANCELED, "%s",
+ "Transfer cancelled by user");
+ callback->func(transfer, err, callback->data);
+ g_error_free(err);
+ }
+
+ return dbus_message_new_method_return(message);
+ }
if (transfer->progress_id != 0) {
g_source_remove(transfer->progress_id);
--
1.7.7.6
From: Mikel Astiz <[email protected]>
Refactor the code to remove function obc_transfer_abort, which is used
only once and is anyway coupled to the D-Bus API.
---
client/transfer.c | 26 +++++++++++---------------
1 files changed, 11 insertions(+), 15 deletions(-)
diff --git a/client/transfer.c b/client/transfer.c
index 0686afe..f296638 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -187,20 +187,6 @@ static void abort_complete(GObex *obex, GError *err, gpointer user_data)
}
}
-static gboolean obc_transfer_abort(struct obc_transfer *transfer)
-{
- if (transfer->xfer == 0)
- return FALSE;
-
- if (transfer->progress_id != 0) {
- g_source_remove(transfer->progress_id);
- transfer->progress_id = 0;
- }
-
- return g_obex_cancel_transfer(transfer->xfer, abort_complete,
- transfer);
-}
-
static DBusMessage *obc_transfer_cancel(DBusConnection *connection,
DBusMessage *message, void *user_data)
{
@@ -218,7 +204,17 @@ static DBusMessage *obc_transfer_cancel(DBusConnection *connection,
ERROR_INTERFACE ".InProgress",
"Cancellation already in progress");
- if (!obc_transfer_abort(transfer))
+ if (transfer->xfer == 0)
+ return g_dbus_create_error(message,
+ ERROR_INTERFACE ".Failed",
+ "Failed");
+
+ if (transfer->progress_id != 0) {
+ g_source_remove(transfer->progress_id);
+ transfer->progress_id = 0;
+ }
+
+ if (!g_obex_cancel_transfer(transfer->xfer, abort_complete, transfer))
return g_dbus_create_error(message,
ERROR_INTERFACE ".Failed",
"Failed");
--
1.7.7.6