linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH obexd v2 1/3] gobex: Add callback and userdata parameter to g_obex_cancel_transfer()
@ 2012-05-04  9:57 Jaganath Kanakkassery
  2012-05-04  9:57 ` [PATCH obexd v2 2/3] client: Wait for abort completion before Transfer.Cancel returns Jaganath Kanakkassery
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jaganath Kanakkassery @ 2012-05-04  9:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jaganath Kanakkassery

If callback is provided in g_obex_cancel_transfer() current complete
callback will be replaced by the new one and user will be informed
when abort completes.
---
 gobex/gobex-transfer.c |   17 +++++++++++++++--
 gobex/gobex.c          |    4 ++--
 gobex/gobex.h          |    5 ++++-
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/gobex/gobex-transfer.c b/gobex/gobex-transfer.c
index c62a91e..724c788 100644
--- a/gobex/gobex-transfer.c
+++ b/gobex/gobex-transfer.c
@@ -624,9 +624,11 @@ guint g_obex_get_rsp(GObex *obex, GObexDataProducer data_func,
 							user_data, err);
 }
 
-gboolean g_obex_cancel_transfer(guint id)
+gboolean g_obex_cancel_transfer(guint id, GObexFunc complete_func,
+			gpointer user_data)
 {
 	struct transfer *transfer = NULL;
+	gboolean ret = TRUE;
 
 	g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", id);
 
@@ -635,6 +637,17 @@ gboolean g_obex_cancel_transfer(guint id)
 	if (transfer == NULL)
 		return FALSE;
 
+	if (complete_func == NULL)
+		goto done;
+
+	transfer->complete_func = complete_func;
+	transfer->user_data = user_data;
+
+	ret = g_obex_pending_req_abort(transfer->obex, NULL);
+	if (ret)
+		return TRUE;
+
+done:
 	transfer_free(transfer);
-	return TRUE;
+	return ret;
 }
diff --git a/gobex/gobex.c b/gobex/gobex.c
index f31b733..b20542d 100644
--- a/gobex/gobex.c
+++ b/gobex/gobex.c
@@ -684,7 +684,7 @@ static gint pending_pkt_cmp(gconstpointer a, gconstpointer b)
 	return (p->id - id);
 }
 
-static gboolean pending_req_abort(GObex *obex, GError **err)
+gboolean g_obex_pending_req_abort(GObex *obex, GError **err)
 {
 	struct pending_pkt *p = obex->pending_req;
 	GObexPacket *req;
@@ -728,7 +728,7 @@ gboolean g_obex_cancel_req(GObex *obex, guint req_id, gboolean remove_callback)
 	struct pending_pkt *p;
 
 	if (obex->pending_req && obex->pending_req->id == req_id) {
-		if (!pending_req_abort(obex, NULL)) {
+		if (!g_obex_pending_req_abort(obex, NULL)) {
 			p = obex->pending_req;
 			obex->pending_req = NULL;
 			goto immediate_completion;
diff --git a/gobex/gobex.h b/gobex/gobex.h
index aacdb53..3120da2 100644
--- a/gobex/gobex.h
+++ b/gobex/gobex.h
@@ -49,6 +49,8 @@ guint g_obex_send_req(GObex *obex, GObexPacket *req, gint timeout,
 gboolean g_obex_cancel_req(GObex *obex, guint req_id,
 						gboolean remove_callback);
 
+gboolean g_obex_pending_req_abort(GObex *obex, GError **err);
+
 gboolean g_obex_send_rsp(GObex *obex, guint8 rspcode, GError **err,
 						guint8 first_hdr_type, ...);
 
@@ -122,7 +124,8 @@ guint g_obex_get_rsp_pkt(GObex *obex, GObexPacket *rsp,
 			GObexDataProducer data_func, GObexFunc complete_func,
 			gpointer user_data, GError **err);
 
-gboolean g_obex_cancel_transfer(guint id);
+gboolean g_obex_cancel_transfer(guint id, GObexFunc complete_func,
+							gpointer user_data);
 
 const char *g_obex_strerror(guint8 err_code);
 guint8 g_obex_errno_to_rsp(int err);
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH obexd v2 2/3] client: Wait for abort completion before Transfer.Cancel returns
  2012-05-04  9:57 [PATCH obexd v2 1/3] gobex: Add callback and userdata parameter to g_obex_cancel_transfer() Jaganath Kanakkassery
@ 2012-05-04  9:57 ` Jaganath Kanakkassery
  2012-05-04  9:57 ` [PATCH obexd v2 3/3] gobex: Remove g_idle_add to exit main loop in test_stream_put_req_abort() Jaganath Kanakkassery
  2012-05-04 14:05 ` [PATCH obexd v2 1/3] gobex: Add callback and userdata parameter to g_obex_cancel_transfer() Luiz Augusto von Dentz
  2 siblings, 0 replies; 4+ messages in thread
From: Jaganath Kanakkassery @ 2012-05-04  9:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jaganath Kanakkassery

A new callback is given to g_obex_cancel_transfer() which will be
called when abort completes and then only "Cancel" method reply will
be sent to user
---
 client/transfer.c |   65 ++++++++++++++++++++++++++++++++++------------------
 1 files changed, 42 insertions(+), 23 deletions(-)

diff --git a/client/transfer.c b/client/transfer.c
index 411a7c0..d796239 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -59,6 +59,7 @@ struct obc_transfer {
 	struct obc_transfer_params *params;
 	struct transfer_callback *callback;
 	DBusConnection *conn;
+	DBusMessage *msg;
 	char *agent;		/* Transfer agent */
 	char *path;		/* Transfer path */
 	gchar *filename;	/* Transfer file location */
@@ -136,37 +137,51 @@ static DBusMessage *obc_transfer_get_properties(DBusConnection *connection,
 	return reply;
 }
 
-static void obc_transfer_abort(struct obc_transfer *transfer)
+static void abort_complete(GObex *obex, GError *err, gpointer user_data)
 {
+	struct obc_transfer *transfer = user_data;
 	struct transfer_callback *callback = transfer->callback;
+	DBusMessage *reply;
 
-	if (transfer->xfer > 0) {
-		g_obex_cancel_transfer(transfer->xfer);
-		transfer->xfer = 0;
-	}
+	transfer->xfer = 0;
 
-	if (transfer->obex != NULL) {
-		g_obex_unref(transfer->obex);
-		transfer->obex = NULL;
-	}
+	reply = dbus_message_new_method_return(transfer->msg);
+	if (reply)
+		g_dbus_send_message(transfer->conn, reply);
 
-	if (callback) {
-		GError *err;
+	dbus_message_unref(transfer->msg);
+	transfer->msg = NULL;
 
-		err = g_error_new(OBC_TRANSFER_ERROR, -ECANCELED, "%s",
-							strerror(ECANCELED));
-		callback->func(transfer, transfer->transferred, err,
+	if (callback) {
+		if (err) {
+			callback->func(transfer, transfer->transferred, err,
 							callback->data);
-		g_error_free(err);
+		} else {
+			GError *abort_err;
+
+			abort_err = g_error_new(OBC_TRANSFER_ERROR, -ECANCELED, "%s",
+						"Transfer cancelled by user");
+			callback->func(transfer, transfer->transferred, abort_err,
+								callback->data);
+			g_error_free(abort_err);
+		}
 	}
 }
 
+static gboolean obc_transfer_abort(struct obc_transfer *transfer)
+{
+	if (transfer->xfer == 0)
+		return FALSE;
+
+	return g_obex_cancel_transfer(transfer->xfer, abort_complete,
+								transfer);
+}
+
 static DBusMessage *obc_transfer_cancel(DBusConnection *connection,
 					DBusMessage *message, void *user_data)
 {
 	struct obc_transfer *transfer = user_data;
 	const gchar *sender;
-	DBusMessage *reply;
 
 	sender = dbus_message_get_sender(message);
 	if (g_strcmp0(transfer->agent, sender) != 0)
@@ -174,18 +189,19 @@ static DBusMessage *obc_transfer_cancel(DBusConnection *connection,
 				"org.openobex.Error.NotAuthorized",
 				"Not Authorized");
 
-	reply = dbus_message_new_method_return(message);
-	if (!reply)
-		return NULL;
+	if (!obc_transfer_abort(transfer))
+		return g_dbus_create_error(message,
+				"org.openobex.Error.Failed",
+				"Failed");
 
-	obc_transfer_abort(transfer);
+	transfer->msg = dbus_message_ref(message);
 
-	return reply;
+	return NULL;
 }
 
 static GDBusMethodTable obc_transfer_methods[] = {
 	{ "GetProperties", "", "a{sv}", obc_transfer_get_properties },
-	{ "Cancel", "", "", obc_transfer_cancel },
+	{ "Cancel", "", "", obc_transfer_cancel, G_DBUS_METHOD_FLAG_ASYNC },
 	{ }
 };
 
@@ -194,7 +210,7 @@ static void obc_transfer_free(struct obc_transfer *transfer)
 	DBG("%p", transfer);
 
 	if (transfer->xfer)
-		g_obex_cancel_transfer(transfer->xfer);
+		g_obex_cancel_transfer(transfer->xfer, NULL, NULL);
 
 	if (transfer->op == G_OBEX_OP_GET &&
 					transfer->transferred != transfer->size)
@@ -211,6 +227,9 @@ static void obc_transfer_free(struct obc_transfer *transfer)
 	if (transfer->conn)
 		dbus_connection_unref(transfer->conn);
 
+	if (transfer->msg)
+		dbus_message_unref(transfer->msg);
+
 	if (transfer->obex)
 		g_obex_unref(transfer->obex);
 
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH obexd v2 3/3] gobex: Remove g_idle_add to exit main loop in test_stream_put_req_abort()
  2012-05-04  9:57 [PATCH obexd v2 1/3] gobex: Add callback and userdata parameter to g_obex_cancel_transfer() Jaganath Kanakkassery
  2012-05-04  9:57 ` [PATCH obexd v2 2/3] client: Wait for abort completion before Transfer.Cancel returns Jaganath Kanakkassery
@ 2012-05-04  9:57 ` Jaganath Kanakkassery
  2012-05-04 14:05 ` [PATCH obexd v2 1/3] gobex: Add callback and userdata parameter to g_obex_cancel_transfer() Luiz Augusto von Dentz
  2 siblings, 0 replies; 4+ messages in thread
From: Jaganath Kanakkassery @ 2012-05-04  9:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jaganath Kanakkassery

A callback is provided in g_obex_cancel_transfer() which will be called
when abort completes which exists the mail loop as well
---
 unit/test-gobex-transfer.c |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c
index 85ba6fa..2f05784 100644
--- a/unit/test-gobex-transfer.c
+++ b/unit/test-gobex-transfer.c
@@ -456,12 +456,8 @@ static gboolean cancel_transfer(gpointer user_data)
 {
 	struct test_data *d = user_data;
 
-	if (d->id > 0) {
-		g_obex_cancel_transfer(d->id);
-		d->id = 0;
-		g_idle_add(cancel_transfer, user_data);
-	} else
-		g_main_loop_quit(d->mainloop);
+	if (d->id > 0)
+		g_obex_cancel_transfer(d->id, transfer_complete, user_data);
 
 	return FALSE;
 }
@@ -509,7 +505,7 @@ static void test_stream_put_req_abort(void)
 	g_source_remove(io_id);
 	g_obex_unref(obex);
 
-	g_assert_no_error(d.err);
+	g_assert_error(d.err, G_OBEX_ERROR, G_OBEX_ERROR_CANCELLED);
 }
 
 static void test_stream_put_rsp_abort(void)
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH obexd v2 1/3] gobex: Add callback and userdata parameter to g_obex_cancel_transfer()
  2012-05-04  9:57 [PATCH obexd v2 1/3] gobex: Add callback and userdata parameter to g_obex_cancel_transfer() Jaganath Kanakkassery
  2012-05-04  9:57 ` [PATCH obexd v2 2/3] client: Wait for abort completion before Transfer.Cancel returns Jaganath Kanakkassery
  2012-05-04  9:57 ` [PATCH obexd v2 3/3] gobex: Remove g_idle_add to exit main loop in test_stream_put_req_abort() Jaganath Kanakkassery
@ 2012-05-04 14:05 ` Luiz Augusto von Dentz
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2012-05-04 14:05 UTC (permalink / raw)
  To: Jaganath Kanakkassery; +Cc: linux-bluetooth

Hi Jaganath,

On Fri, May 4, 2012 at 12:57 PM, Jaganath Kanakkassery
<jaganath.k@samsung.com> wrote:
> If callback is provided in g_obex_cancel_transfer() current complete
> callback will be replaced by the new one and user will be informed
> when abort completes.
> ---
>  gobex/gobex-transfer.c |   17 +++++++++++++++--
>  gobex/gobex.c          |    4 ++--
>  gobex/gobex.h          |    5 ++++-
>  3 files changed, 21 insertions(+), 5 deletions(-)
>
> diff --git a/gobex/gobex-transfer.c b/gobex/gobex-transfer.c
> index c62a91e..724c788 100644
> --- a/gobex/gobex-transfer.c
> +++ b/gobex/gobex-transfer.c
> @@ -624,9 +624,11 @@ guint g_obex_get_rsp(GObex *obex, GObexDataProducer data_func,
>                                                        user_data, err);
>  }
>
> -gboolean g_obex_cancel_transfer(guint id)
> +gboolean g_obex_cancel_transfer(guint id, GObexFunc complete_func,
> +                       gpointer user_data)
>  {
>        struct transfer *transfer = NULL;
> +       gboolean ret = TRUE;
>
>        g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", id);
>
> @@ -635,6 +637,17 @@ gboolean g_obex_cancel_transfer(guint id)
>        if (transfer == NULL)
>                return FALSE;
>
> +       if (complete_func == NULL)
> +               goto done;
> +
> +       transfer->complete_func = complete_func;
> +       transfer->user_data = user_data;
> +
> +       ret = g_obex_pending_req_abort(transfer->obex, NULL);
> +       if (ret)
> +               return TRUE;
> +
> +done:
>        transfer_free(transfer);
> -       return TRUE;
> +       return ret;
>  }
> diff --git a/gobex/gobex.c b/gobex/gobex.c
> index f31b733..b20542d 100644
> --- a/gobex/gobex.c
> +++ b/gobex/gobex.c
> @@ -684,7 +684,7 @@ static gint pending_pkt_cmp(gconstpointer a, gconstpointer b)
>        return (p->id - id);
>  }
>
> -static gboolean pending_req_abort(GObex *obex, GError **err)
> +gboolean g_obex_pending_req_abort(GObex *obex, GError **err)
>  {
>        struct pending_pkt *p = obex->pending_req;
>        GObexPacket *req;
> @@ -728,7 +728,7 @@ gboolean g_obex_cancel_req(GObex *obex, guint req_id, gboolean remove_callback)
>        struct pending_pkt *p;
>
>        if (obex->pending_req && obex->pending_req->id == req_id) {
> -               if (!pending_req_abort(obex, NULL)) {
> +               if (!g_obex_pending_req_abort(obex, NULL)) {
>                        p = obex->pending_req;
>                        obex->pending_req = NULL;
>                        goto immediate_completion;
> diff --git a/gobex/gobex.h b/gobex/gobex.h
> index aacdb53..3120da2 100644
> --- a/gobex/gobex.h
> +++ b/gobex/gobex.h
> @@ -49,6 +49,8 @@ guint g_obex_send_req(GObex *obex, GObexPacket *req, gint timeout,
>  gboolean g_obex_cancel_req(GObex *obex, guint req_id,
>                                                gboolean remove_callback);
>
> +gboolean g_obex_pending_req_abort(GObex *obex, GError **err);
> +
>  gboolean g_obex_send_rsp(GObex *obex, guint8 rspcode, GError **err,
>                                                guint8 first_hdr_type, ...);
>
> @@ -122,7 +124,8 @@ guint g_obex_get_rsp_pkt(GObex *obex, GObexPacket *rsp,
>                        GObexDataProducer data_func, GObexFunc complete_func,
>                        gpointer user_data, GError **err);
>
> -gboolean g_obex_cancel_transfer(guint id);
> +gboolean g_obex_cancel_transfer(guint id, GObexFunc complete_func,
> +                                                       gpointer user_data);
>
>  const char *g_obex_strerror(guint8 err_code);
>  guint8 g_obex_errno_to_rsp(int err);
> --
> 1.7.1

All 3 patches are now upstream, thanks.


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-05-04 14:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-04  9:57 [PATCH obexd v2 1/3] gobex: Add callback and userdata parameter to g_obex_cancel_transfer() Jaganath Kanakkassery
2012-05-04  9:57 ` [PATCH obexd v2 2/3] client: Wait for abort completion before Transfer.Cancel returns Jaganath Kanakkassery
2012-05-04  9:57 ` [PATCH obexd v2 3/3] gobex: Remove g_idle_add to exit main loop in test_stream_put_req_abort() Jaganath Kanakkassery
2012-05-04 14:05 ` [PATCH obexd v2 1/3] gobex: Add callback and userdata parameter to g_obex_cancel_transfer() Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).